I have a image file in my sample Project. I am trying the URL as below.
http://localhost:49334/Chrysanthemum.jpg
I have a Application_BeginRequest event
in my Global.asax
file.
protected void Application_BeginRequest(Object sender, EventArgs e)
{
}
Query - This event is not getting fired when I request the above image by directly typing the URL above.
FROM MSDN - HttpApplication.BeginRequest Event - Occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request.
I want to make my all request to fire `Application_BeginRequest` Event
The problem is probably because .jpg extension is not defaultly mapped to asp.net and is handled by IIS.
If you using IIS7 you can change this by set runAllManagedModulesForAllRequests to true.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
...
</modules>
</system.webServer>
If still this event is not fired, you can try change global.asax like this
<%@ 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 handle only .jpg files, better way is to make HTTP handler and configure system.webServer > handlers and system.web > httpHandlers section in web.config to run this handler for .jpg requests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With