owin-middleware

OwinMiddleware doesn't preserve culture change in .net 4.6.*

左心房为你撑大大i 提交于 2019-11-30 17:48:12
问题 I have an owin culture middle ware running very nice. It just changes the culture according to the url. This works in 4.5.* perfectly. Now when the runtiome is changed to 4.6.1, the culture isn't preserved anymore and as a result it just doesn't work. I can reproduce it in a very simple solution which only has this middleware simulating the culture change public class CultureMiddleware : OwinMiddleware { public CultureMiddleware(OwinMiddleware next) : base(next) { } public override async Task

ASP.NET with OpenIdAuthentication: redirect to url if not authorized

主宰稳场 提交于 2019-11-30 17:43:36
问题 I am attempting to write an ASP.NET application that uses a hybrid authentication scheme. A user can either have his username and password hash stored in the UserStore, or he can authenticate via Azure Active Directory. I have created the login form pictured. It has the standard UserName and Password inputs, but also has a "Login via Active Directory" button. This works well. Now for the problem: The application's home page has the [Authorize] attribute. public class DefaultController :

Should I use OwinContext's Environment to hold application specific data per request

蓝咒 提交于 2019-11-30 17:20:11
I need a way to store a logging object per request. With HttpContext I would add this to the items Dictionary. I don't want to bring HttpContext into this if I can help it. The below code is what I propose for a Unity LifeTimeManager that will store objects in OwinContext's Environment property, which I have access to with my Owin middleware. public class OwinContextLifetimeManager : LifetimeManager { private string key = (new Guid()).ToString(); private IDictionary<string, object> environment; public OwinContextLifetimeManager(IDictionary<string, object> environment) { this.environment =

Rewind request body stream

杀马特。学长 韩版系。学妹 提交于 2019-11-30 16:57:59
I am re-implementing a request logger as Owin Middleware which logs the request url and body of all incoming requests. I am able to read the body, but if I do the body parameter in my controller is null. I'm guessing it's null because the stream position is at the end so there is nothing left to read when it tries to deserialize the body. I had a similar issue in a previous version of Web API but was able to set the Stream position back to 0. This particular stream throws a This stream does not support seek operations exception. In the most recent version of Web API 2.0 I could call Request

Should I use OwinContext's Environment to hold application specific data per request

隐身守侯 提交于 2019-11-30 16:33:31
问题 I need a way to store a logging object per request. With HttpContext I would add this to the items Dictionary. I don't want to bring HttpContext into this if I can help it. The below code is what I propose for a Unity LifeTimeManager that will store objects in OwinContext's Environment property, which I have access to with my Owin middleware. public class OwinContextLifetimeManager : LifetimeManager { private string key = (new Guid()).ToString(); private IDictionary<string, object>

Change OWIN Auth Middleware Per Request (Multi-tenant, oauth API keys per tenant)

匆匆过客 提交于 2019-11-30 03:58:30
I have a multi-tenant application. Each tenant can authenticate its users using OAUTH-2 with Facebook, Twitter, Google, etc. Each tenant has its own API keys for the aforementioned services. The typical way to setup the OWIN pipeline is to "use" auth providers in Startup but this sets the API keys at app start. I need to be able to change which keys are used with each oauth API for each request. app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, Provider = cookieAuthProvider, CookieName = "VarsityAuth", }); app

Rewind request body stream

*爱你&永不变心* 提交于 2019-11-30 00:13:47
问题 I am re-implementing a request logger as Owin Middleware which logs the request url and body of all incoming requests. I am able to read the body, but if I do the body parameter in my controller is null. I'm guessing it's null because the stream position is at the end so there is nothing left to read when it tries to deserialize the body. I had a similar issue in a previous version of Web API but was able to set the Stream position back to 0. This particular stream throws a This stream does

How to intercept 404 using Owin middleware

狂风中的少年 提交于 2019-11-29 09:19:13
Background First let me explain the background. I am working on a project that attempts to marry a backend server that uses Web API configured via OWIN- hosted on IIS now, but potentially other OWIN-supported hosts in the future- to a frontend using AngularJS. The AngularJS frontend is entirely static content. I completely avoid server-side technologies such as MVC/Razor, WebForms, Bundles, anything that has to do with the frontend and the assets it uses, and defer instead to the latest and greatest techniques using Node.js, Grunt/Gulp, etc. to handle CSS compilation, bundling, minification,

Global exception handling in OWIN middleware

泪湿孤枕 提交于 2019-11-28 03:49:47
I'm trying to create a unified error handling/reporting in ASP.NET Web API 2.1 Project built on top of OWIN middleware (IIS HOST using Owin.Host.SystemWeb). Currently I used a custom exception logger which inherits from System.Web.Http.ExceptionHandling.ExceptionLogger and uses NLog to log all exceptions as the code below: public class NLogExceptionLogger : ExceptionLogger { private static readonly Logger Nlog = LogManager.GetCurrentClassLogger(); public override void Log(ExceptionLoggerContext context) { //Log using NLog } } The I want to change the response body for all API exceptions to a

How can I safely intercept the Response stream in a custom Owin Middleware

夙愿已清 提交于 2019-11-26 16:34:20
问题 I'm trying to write a simple OWIN Middleware, in order to intercept the response stream. What I'm trying to do is replace the original stream with custom Stream-based class, where I will be able to intercept writes to the response stream. However, I'm facing some issues because I cannot know when the response has been completely written to by inner middleware components in the chain. The Dispose override of the Stream is never called. So I don't know when it's time to perform my processing,