Pan*_*kaj 9 c# asp.net iis-7 c#-4.0
我的示例项目中有一个图像文件.我正在尝试如下URL.
Application_BeginRequest event
我的Global.asax
文件中有一个.
protected void Application_BeginRequest(Object sender, EventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)
查询 - 当我通过直接键入上面的URL请求上面的图像时,不会触发此事件.
FROM MSDN - HttpApplication.BeginRequest事件 - 当ASP.NET响应请求时,作为HTTP管道执行链中的第一个事件发生.
I want to make my all request to fire `Application_BeginRequest` Event
Run Code Online (Sandbox Code Playgroud)
问题可能是因为.jpg扩展名没有默认映射到asp.net并且由IIS处理.
如果您使用IIS7,则可以通过将runAllManagedModulesForAllRequests设置为true来更改此设置.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
...
</modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
如果仍未触发此事件,您可以尝试像这样更改global.asax
<%@ Application Language="C#" %>
<script runat="server">
public override void Init()
{
this.BeginRequest += new EventHandler(global_asax_BeginRequest);
base.Init();
}
void global_asax_BeginRequest(object sender, EventArgs e)
{
}
</script>
Run Code Online (Sandbox Code Playgroud)
如果您只想处理.jpg文件,更好的方法是在web.config中创建HTTP处理程序并配置system.webServer> handlers和system.web> httpHandlers部分,以便为.jpg请求运行此处理程序.
归档时间: |
|
查看次数: |
16203 次 |
最近记录: |