Changing the response object from OWIN Middleware

Yes, deriving from OwinMiddleware is recommended. The reason some middleware classes don’t derive from OwinMiddleware is that either they haven’t switched over yet because the class was introduced recently. Or to avoid having the assembly take a dependency on the Microsoft.Owin assembly for some reason. The probable reason setting stuff on the response after calling … Read more

How do I create a ClaimsIdentity object for Asp.NET MVC 5?

Perhaps the following link can help: var claims = new List<Claim>(); claims.Add(new Claim(ClaimTypes.Name, “Brock”)); claims.Add(new Claim(ClaimTypes.Email, “[email protected]”)); var id = new ClaimsIdentity(claims,DefaultAuthenticationTypes.ApplicationCookie); var ctx = Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignIn(id);

Pass command-line arguments to Startup class in ASP.NET Core

You should be able to use the AddCommandLine() extension. First install the Nuget package Microsoft.Extensions.Configuration.CommandLine and ensure you have the correct import: using Microsoft.Extensions.Configuration; Now update your Main method to include the new config: var config = new ConfigurationBuilder() .AddJsonFile(“hosting.json”, optional: true) //this is not needed, but could be useful .AddCommandLine(args) .Build(); var builder = … Read more

Migrating from OWIN to ASP.NET Core

Middleware is quite similar between Katana and Core but you use HttpContext instead of IOwinContext. Startup.cs is similar but there’s much more DI support. WebApi has been merged into MVC DelegatingHandler is gone, use middleware instead. HttpConfiguration has been split up into Routing and MvcOptions. Also https://devblogs.microsoft.com/aspnet/katana-asp-net-5-and-bridging-the-gap/

Web API 2 OWIN Bearer Token purpose of cookie?

In the SPA template there are actually two separate authentication mechanisms enabled- cookie authentication and token authentication. This enables authentication of both MVC and Web API controller actions, but requires some additional setup. If you look in the WebApiConfig.Register method you’ll see this line of code: config.SuppressDefaultHostAuthentication(); That tells Web API to ignore cookie authentication, … Read more

OWIN Authentication Pipeline To Use Katana Middleware Correctly?

As @Tratcher said, the AuthenticationType parameter is used by Microsoft.Owin.Security as a key to do lookups of authentication middleware instances. The code below will use the following simple helper method to require that all requests are authenticated. In practice you’re more likely to use an [Authorize] attribute on sensitive controllers, but I wanted an example … Read more

Is there Application_End from Global.asax in Owin?

AppProperties, found in Microsoft.Owin.BuilderProperties, exposes the CancellationToken for OnAppDisposing. You can get this token and register a callback to it public class Startup { public void Configuration(IAppBuilder app) { var properties = new AppProperties(app.Properties); CancellationToken token = properties.OnAppDisposing; if (token != CancellationToken.None) { token.Register(() => { // do stuff }); } } }

No owin.Environment item was found in the context

Most likely it cannot find the OWIN Startup class. The default convention for the Startup class is [AssemblyName].Startup. If you’re no longer following that convention you’ll need to specify the full name of your Startup class in the Web.Config. The next release of Microsoft.Owin.Host.SystemWeb package now throws detailed exception messages when the Startup class cannot … Read more

Global exception handling in OWIN middleware

Ok, so this was easier than anticipated, thanks for @Khalid for the heads up, I have ended up creating an owin middleware named OwinExceptionHandlerMiddleware which is dedicated for handling any exception happening in any Owin Middleware (logging it and manipulating the response before returning it to the client). You need to register this middleware as … Read more

Unhandled Exception Global Handler for OWIN / Katana?

Try writing a custom middleware and placing it as the first middleware: public class GlobalExceptionMiddleware : OwinMiddleware { public GlobalExceptionMiddleware(OwinMiddleware next) : base(next) {} public override async Task Invoke(IOwinContext context) { try { await Next.Invoke(context); } catch(Exception ex) { // your handling logic } } } Place it as the first middleware: public class Startup … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)