【发布时间】: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