Looking at a standard new MVC 5 project in Visual Studio 2013 you can see that it now includes OWIN.
There's a new OWIN Startup class that configures auth however I can't see how/where MVC5 is registered with OWIN. Where does this happen?
I'm assuming here that all requests pass through OWIN before entering the MVC pipeline. Why else would they include OWIN?
Please note: I'm not asking how OWIN is setup, that's easily explained in the docs. I'm interested in how MVC5 uses OWIN.
Update: I figured out why MVC5 uses OWIN even though requests are handled by the IIS pipeline instead of OWIN.
MVC5 does not pass through OWIN, however it looks like this could change in the future. Instead MVC currently still needs to pass through the IIS Integrated Pipeline. The reason that OWIN is included in the default MVC project is so that MVC5 can use the Owin middleware components.
From the OWIN middleware in the iis integrated pipeline:
In order for an OMC to participate in this same, event-based execution
ordering, the Katana runtime code scans through the startup
configuration and subscribes each of the middleware components to an
integrated pipeline event.
This does change in ASP.NET vNext as Web.Api and MVC have been combined and abandon System.Web in favour of OWIN and project Helios.
MVC 5 is not registered with OWIN.
OWIN is registered to start before application (PreApplicationStartMethod).
And at Pre-application-startup, OwinStartup registered class is used to configure current application.
[assembly: OwinStartup(typeof(WebApplication1.Startup))]
The above line in startup.cs will load the class to configure OWIN.
Look further OWIN Startup class detection
Related
I am developing a .NET Core 3.1 MVC App and then publishing it to Azure Web App. In the Azure portal, for this hosted app -> I enabled App Service Authentication with AzureAD Login. But then the authentication doesn't work as "User.Identity.IsAuthenticated" is always coming as false in the Controller and I can't fetch other user details I want to, like email etc. Upon searching I found there is a workaround using a Nuget Package for >Net Core 2.2 (https://github.com/MaximRouiller/MaximeRouiller.Azure.AppService.EasyAuth), but I don't see any solution for 3.1.
However, when I setup custom auth by disabling the App Service Authentication in Azure, and set the auth in Startup.cs like this:
services.AddAuthentication(AzureADDefaults.AuthenticationScheme).AddAzureAD(options => Configuration.Bind("AzureAd", options));
and this:
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints => ...
with config in appsettings.json, the auth works fine and I can fetch user details as well.
But our preferred solution is not to have any auth settings/custom auth in code and rather handle it fully on the portal using Azure AD Easy Auth with .NET Core 3.1 MVC app. Would really appreciate any help.
This is a known limitation for EasyAuth and .NET Core as documented. The User Principal is implemented differently in .NET Core and EasyAuth can't grab those details automagically like it can in .NETFX. That is why you need to use Maxime's workaround.
I've an ASP.NET Core Application (.net Framework) and that references my other .net Framework dlls.
I've configured logging in my ASP.NET Application using "Microsoft.Extensions.Logging.AzureAppServices" and injecting ILogger to controllers. All that works fine. all my logs are written to azure application logs in Azure.
In my .net framework dll, i've Trace.TraceError, TraceWarning statements. And I would like to include them in azure application log. but I cannot find any way to do it.
Looking forward for some help.
You will have to use the logging framework of ASP.NET Core (ILogger and friends) in your .NET Framework class library/DLL if you want them appear in the same application log.
Another option might be to convert the library to use the TraceSource system, there is a logging provider for ASP.NET Core available. If you're unable to make changes to the existing library, I'm afraid you're out of options.
I created a new web application with VS2017, by choosing asp.net web application and from templates. when the application is created I don't see startup class. no reference to Owin. VS2017 templates don't use Owin?
First, the version of Visual Studio has nothing to do with anything. However, in VS2017, you'll have three choices for a "web application" out of the box: MVC (where you later choose to include MVC, Web Api, or both), Core, and Core on the Full Framework.
The Core projects will have a Startup.cs class, but the MVC project will not, unless you indicate you want Individual Authentication. In that case, a Startup.cs file will be added for the purposes of Identity, but the MVC website, itself, will not be affected or controlled by that.
You can create Owin Project with Visual Studio 2017 by going to
1 . Create new project with ASP.NET (.Net Framework)
2. Select Single Page Application Template
here you go - > new owin project created
How do I add .NET Core class library reference in Service Fabric App.
While I'm adding Class Library reference (.NET Core) in WebAPI app, showing Compatibility issues. Please find below What I did, using Visual Studio 2017.
File >> New Project >> Cloud >> Service Fabric Application
Name - FirstServiceFabricApp
Select a Template >> Stateless ASP.NET Core
Name - FirstStatelessAPI
Build and Run the Project. It works.
Although API Project Framework version is .NET Framework 4.5.2.
Added Class Library Project [builds on .NET Core 1.1] as reference into Stateless WebAPI Project. Showing compatibility issues-
Building the solution x64 platform.
My concerns are:
How do I take .NET Core Library reference in Stateless WebAPI Project [Service Fabric]
Should I go/develop with .NET Framework for Class Library which is compatible with Stateless WebAPI project.
I did Azure AD Authentication/Microsoft Graph in Azure APP Service, but never did for Service Fabric App. Whether Azure AD and Microsoft Graph implementation is same in this Stateless WebAPI App. Kindly provide some references on this.
You need to make your class library target a compatible framework e.g. net452 (or netstandard2.0 when it's supported like 2017 Q3)
The below link talks about converting a .net core to azure service fabric application.
It talks about statefulservice. Statelessservice is more or less similar to it.
http://dotnetextensions.blogspot.in/2018/04/convert-dot-net-core-application-to.html?m=1
When it comes to azure ad, i won't have much impact. You can continue to use the same thing
One key ability with the old ASP.NET pipeline is the ability to add an HTTP Module to the pipeline via configuration. The advantage was the ability to add, say, redirects or filtering to a web application's pipeline where access to the application's source was not available.
My understanding of OWIN middleware - whether katana, kestrel or later - is that adding middleware and ordering is a compile/build time action.
Or is there some mechanism to insert a component at the beginning of the OWIN pipe for a web application via web.config type configuration?