简体   繁体   中英

Imageresizer Authentication with Owin

Im using Imageresizer 4 in a MVC 5 application. We have the need to authenticate the image requests so we are using the following event:

protected void Application_Start() { ImageResizer.Configuration.Config.Current.Pipeline.AuthorizeAllImages = true; ImageResizer.Configuration.Config.Current.Pipeline.AuthorizeImage += AuthorizeImage; }

The AuthorizeImage method looks like this:

private static void AuthorizeImage(IHttpModule sender, HttpContext context, IUrlAuthorizationEventArgs e) { //This line throws an exception if runAllManagedModulesForAllRequests is set to false var owinContext = context.GetOwinContext(); Authorize(context, owinContext); }

The problem is that we are using Owin so we need the OwinContext from the HttpContext. When calling the GetOwinContext method we get the following error:

No owin.Environment item was found in the context

If I set the runAllManagedModulesForAllRequests to true in web.config, everything works like it should.

But I don't want to use runAllManagedModulesForAllRequests since it has a performance impact.

My question is: Can I somehow force the Owin middleware to execute before a specific HttpModule?

Something like this(psuedo code):

<modules runAllManagedModulesForAllRequests="false"> <add name="ImageResizingModule" type="ImageResizer.InterceptModule" modulesToRunBefore="Owin........" /> </modules>

不,你需要runAllManagedModulesForAllRequests=true ,除非你可以改变runAllManagedModulesForAllRequests=true模块的注册方式,并告诉为所有请求运行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM