ASP.Net Request Life Cycle - Application_BeginRequest

I have an image file in my sample project. I am trying the URL as shown below.

http: // localhost: 49334 / Chrysanthemum.jpg

I have an Application_BeginRequest event in my Global.asax file.

 protected void Application_BeginRequest(Object sender, EventArgs e) { } 

Request . This event does not fire when I request the above image, simply by typing the above URL.


FROM MSDN - HttpApplication.BeginRequest Event - occurs as the first event in the HTTP protocol execution chain when ASP.NET responds.

 I want to make my all request to fire `Application_BeginRequest` Event 
+8
c # iis-7
source share
1 answer

The problem is probably due to the fact that the .jpg extension is not mapped to asp.net by default and is being processed by IIS.

If you are using IIS7, you can change this by setting the runAllManagedModulesForAllRequests parameter to true.

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

If this event is not already fired, you can try changing global.asax as

 <%@ 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> 

If you want to process only .jpg files, it is better to make an HTTP handler and configure system.webServer> handlers and system.web> httpHandlers on the Internet. config to run this handler for .jpg requests.

+4
source share

All Articles