【问题标题】:Imageresizer Authentication with Owin使用 Owin 进行 Imageresizer 身份验证
【发布时间】:2016-08-16 08:17:25
【问题描述】:

我在 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>

【问题讨论】:

    标签: c# owin imageresizer


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-09-23
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 2017-12-17
      • 1970-01-01
      • 2017-05-06
      • 2015-10-29
      • 2018-08-30
      相关资源
      最近更新 更多