I'm moving stuff from my ASP.Net MVC application (.Net Framework 4.7) to a new .Net Core 2.2 API.
In my old MVC application I added some specific POST properties to the IIS logs via HttpResponseBase.AppendToLog(). I can't find a similar method in .Net Core.
My question: how can I add properties that are in the HttpPost to the IIS logs in a .Net Core Api? This is how the logs look like:
2019-06-26 19:34:07 website-ip-address POST /some-endpoint [data-to-log-ended-here] 443 username ip-address etc.
I don't have a direct answer to your question, but I found two posts that may relate to what you are asking
How to log http POST data to IIS log in asp.net core
Where do logs go when running ASP.NET Core on IIS 7.5?
Generally, in an Asp.net Core app it's more common to use its logging API to work with a powerful 3rd party logging libraries like Serilog to easily log to a number of different sources you can choose from. Though IIS is not one of them, I'd recommend take a look at Application Insights which is very popular for doing logging in Asp.net Core applications. Hope this helps somewhat!
Related
I am new to ASP.NET Core Razor(or MVC) page web development. I have an ASP.NET core web site deployed in a docker container and I have few other docker containers which are just .NET Core modules. Between the modules and the ASP.NET Core web page they would be talking over an RabbitMQ message bus or an Azure IOT Edge hub. Now if I get a message from one of the .NET Core module,I want to update the ASP.NET Core Index page view. I googled and I couldnt find a clear answer. Is polling using Jquery or Javascript and updating the view using Ajax the only option?
What you need is full duplex communication between your client (webpage) and server (asp.net core MVC).
With a classic MVC Razor webapp, communication is half-duplex; it is one way from your client to your server, and unfortunately, never the other way around.
Popular solutions that would enable what you want to achieve are:
https://github.com/websockets/ws
https://www.asp.net/signalr
I'd like to use ASP.NET Identity 2.x (.NET 4.6.1 / MVC5), without talking to a database directly through Entity Framework, but instead using an external (REST) web service as the source of users and roles. I've read up a little bit on this already, but I was just curious if anyone knows what would be the minimum interfaces to implement. I would assume IUserStore and IRoleStore would be absolute minimum, correct?
I'm aware of these resources:
Simple Asp.net Identity Core Without Entity Framework
Exorcising Entity Framework from ASP.NET Identity
ASP.NET Identity w/o Entity Framework
...but nobody particularly talked about using a web service, and they're mainly focusing on just not using EF, but are still using a DB of some kind directly. I am curious if anyone has tried this with a web service and has come across any pitfalls?
I have an SQL Server database with a MVC 4 internet application. How do I use OAuth with my existing database and existing user table (unfortunately called 'Customer'). I'm trying to avoid changing as much as I can. Does anyone have any helpful information?
Take a look at DotNetOpenAuth. It's shipped with VS2012, is available via NuGet, and seems to be geared more toward the ASP.NET MVC audience than simpler WCF setups.
I have a .NET 4 application that runs as a windows service. It runs periodic tasks and provides WCF restful webservices. It already hosts a silverlight web page (via WCF) that allows a user to configure the service.
Now I have a requirement to provide information on HTML/java script pages (e.g. for browsers and platforms that don't support Silverlight). I can serve simple HTML and javascript pages through WCF but that becomes laborious very quickly. I'd like to use MVC2.
Is it possible to provide MVC2 web pages from within a windows service? Or at least use some of the functionality provided by MVC like routing and the view engine?
Or is it more trouble than it's worth and should I head down the path of a separate app hosted on IIS?
You can host the ASP.NET runtime in any type of application including a Windows Service using the CreateApplicationHost method. Although note that by doing this you lose the robustness, security, logging, etc... that a real web server such as IIS provides.
Since you're asking the question about what route to take, I'd host an MVC2 application in IIS. Why recreate a web server using WCF when IIS is already there - and since you're asking, it sounds like that's a viable option.
I agree with Darin's answer that you can host ASP.NET MVC2 in any application, but I think you're going to end up recreating a lot of plumbing that's already in place with IIS.
On the upside, if you go with serving up ASP.NET MVC2 resources in a WCF service application, it may end up rocking and you could have a nice application you can sell on the side. :)
A Guide to Designing and Building RESTful Web Services with WCF 3.5, this article explains the foundations of REST and how it relates to WCF. MVC uses REST as the architectural model. I am guessing one can use the .NET MVC to create web applications that have both a front end and an API point, but I am not sure if the safe way of building the API is to build it with WCF and then use it in the MVC as a controller.
Please comment if the question is not clear, I will add or modify the text.
Theres actually a third option, ADO.NET Data Servies. Anyway, here how I see them.
MVC REST: Gives you full control over how to expose your data, you have to write all the code to get it up an running tho, e.g. serialization, deserialization, all the CRUD methods etc etc. Worht metioning that this being an MVC site means you are limited to exposing your service via IIS over HTTP(S)
WCF REST: More automation than MVC, a much more solid frameowkr than MVC REST, i.e. caching, security, error handling etc (basically all the stff you'd have to write yourself using plain MVC). Being WCF, you can host this in a variety of ways (e.g WS-, TCP) etc.
ADO.NET DATA SERVICES: The quickest way to get up an running with everthing ready to use, all you need todo is configure the global.asax, however you have to use an Entity Data Model, which you many not want to.
Personally, I would use either ADO.NET DATA SERVICES or WCF REST to build an API, consue that API in MVC site and then expose that API either directly, or by passing it through another layer.
ASP.NET MVC can serve as a REST endpoint for light services work, so I guess the answer to your question depends on how you define "safe."
Clearly WCF is designed specifically for creating REST endpoints, with all of the security implications that are implied thereof, whereas ASP.NET MVC is designed to create REST endpoints which can be used by ASP.NET MVC itself.
The following article shows how to create a web service using an ASP.NET MVC controller:
Create REST API using ASP.NET MVC that speaks both Json and plain Xml
http://msmvps.com/blogs/omar/archive/2008/10/03/create-rest-api-using-asp-net-mvc-that-speaks-both-json-and-plain-xml.aspx
See also the following article from Phil Haack, which discusses an SDK the WCF team put together for users of ASP.NET MVC:
Rest For ASP.NET MVC SDK and Sample
http://haacked.com/archive/2009/08/17/rest-for-mvc.aspx
They are two different sets of technologies, only related by being built on .net
MVC is used to create websites and provides a model where URLs are routed to controllers and controllers deliver views to the user as the user interface.
WCF is a set of libraries in .net that are used to abstract the type of service (is it hosted in a windows service, as a webservice in IIS etc.) as well as the protocol (HTTP, TCP, MSMQ etc.) from the client and server which are communicating.
An MVC website may use WCF to connect to a web service, but that is just one of many options.