Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Http Modules

Http Modules

Scheduled Pinned Locked Moved ASP.NET
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nishant Singh
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • N Nishant Singh

      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

        &lt;httpModules&gt;
      
      <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

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Use server.Transfer instead of Response.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>

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups