Http Modules
-
Hi , I am looking at the working of HttpModule lately ..... I am stuck up at a place I have a class implementing IHttpModule which is supposed to catch any unhadled exception and redirect to a default page.
public class HttpModule2 : IHttpModule
{
public void Dispose()
{} public void Init(HttpApplication App) { App.Error += new EventHandler(App\_EndRequest); } void App\_EndRequest(object sender, EventArgs e) { HttpApplication App = (HttpApplication)(sender); App.Response.Redirect("Default.aspx",true); }
}
Now after that I put it in the web config
<httpModules> <add name="ErrorModule" type="HttpModule2"/> </httpModules>
but now if I introduce a divide by zero error in my code
protected void LinkButton1_Click(object sender, EventArgs e)
{
try
{
int k = 0;
int m = 100 / k;
Response.Redirect("MyTxt.txt");
}
catch (Exception ex)
{
throw ex;
}}
it's still showing me the error page is there something i am missing , actually I am touching this area after 6 months or so ..i must be forgetting something. ;P
-
Hi , I am looking at the working of HttpModule lately ..... I am stuck up at a place I have a class implementing IHttpModule which is supposed to catch any unhadled exception and redirect to a default page.
public class HttpModule2 : IHttpModule
{
public void Dispose()
{} public void Init(HttpApplication App) { App.Error += new EventHandler(App\_EndRequest); } void App\_EndRequest(object sender, EventArgs e) { HttpApplication App = (HttpApplication)(sender); App.Response.Redirect("Default.aspx",true); }
}
Now after that I put it in the web config
<httpModules> <add name="ErrorModule" type="HttpModule2"/> </httpModules>
but now if I introduce a divide by zero error in my code
protected void LinkButton1_Click(object sender, EventArgs e)
{
try
{
int k = 0;
int m = 100 / k;
Response.Redirect("MyTxt.txt");
}
catch (Exception ex)
{
throw ex;
}}
it's still showing me the error page is there something i am missing , actually I am touching this area after 6 months or so ..i must be forgetting something. ;P
Use
server.Transfer
instead ofResponse.Redirect
.Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>