簡體   English   中英

使用Owin進行Imageresizer身份驗證

[英]Imageresizer Authentication with Owin

我在MVC 5應用程序中使用Imageresizer 4 我們需要對圖像請求進行身份驗證,因此我們使用以下事件:

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

AuthorizeImage方法如下所示:

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); }

問題是我們正在使用Owin所以我們需要來自HttpContext的OwinContext。 調用GetOwinContext方法時,我們收到以下錯誤:

在上下文中找不到owin.Environment項

如果我在web.config中將runAllManagedModulesForAllRequests設置為true,那么一切都會像它應該的那樣工作。

但我不想使用runAllManagedModulesForAllRequests,因為它會對性能產生影響。

我的問題是:我可以以某種方式強制Owin中間件在特定的HttpModule之前執行嗎?

像這樣的東西(偽代碼):

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

不,你需要runAllManagedModulesForAllRequests=true ,除非你可以改變runAllManagedModulesForAllRequests=true模塊的注冊方式,並告訴為所有請求運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM