加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 在生产服务器上没有为JPG触发Application_BeginRequest

发布时间:2020-12-15 05:40:43 所属栏目:百科 来源:网络整理
导读:我有一个IIS 7.5网站在经典管道模式下运行.NET 4.0. 我创建了一个简单的默认图像设置,如果调用图像但物理文件不存在,则使用Application_BeginRequest事件中的以下代码将请求重定向到默认图像: protected void Application_BeginRequest(object sender,Event
我有一个IIS 7.5网站在经典管道模式下运行.NET 4.0.

我创建了一个简单的默认图像设置,如果调用图像但物理文件不存在,则使用Application_BeginRequest事件中的以下代码将请求重定向到默认图像:

protected void Application_BeginRequest(object sender,EventArgs e)
{
    if (Request.PhysicalPath.EndsWith(".jpg") && File.Exists(Request.PhysicalPath) == false)
    {
        Context.RewritePath("~/images/nophoto.jpg");
    }
}

这在我的VS2010开发服务器上工作正常,但是在生产环境中,没有为JPG请求调用Application_BeginRequest事件,我得到的是标准HTTP错误404.0 – 未找到错误.

我已经尝试将Web.Config中的runAllManagedModulesForAllRequests选项设置为true,但这似乎没有帮助:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>

根据我的理解,这应该导致所有请求通过.NET,从而触发Application_BeginRequest事件?

期望的结果:

我希望所有请求都通过.NET,以便为JPG调用Application_BeginRequest事件,如果没有找到图像则返回默认图像.

解决方法

经典模式不会发生这种情况,您需要切换到集成模式.

This文章可能会提供一个洞察力.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读