title: Custom HTTP handler for URL rewriting + session and application variable
body: <p>Currently my product page URL is like </p>
  
  <p><a href="http://www.localhost:80/products/default.aspx?code=productCode" rel="nofollow">http://www.localhost:80/products/default.aspx?code=productCode</a></p>
  
  <p>I want to access product page with</p>
  
  <p><a href="http://www.localhost:80/productCode" rel="nofollow">http://www.localhost:80/productCode</a> </p>
  
  <p>I have used HTTP module for this.</p>
  
  <pre><code>public class UrlRewritingModule : IHttpModule
  
  {
  
          public void Dispose()
          {
  
          }
          public void Init(HttpApplication context)
          {
              context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
  
             context.AuthorizeRequest += new EventHandler(context_AuthorizeRequest);
  
  
          }  
          void context_AuthorizeRequest(object sender, EventArgs e)
          {
               HttpContext context = ((HttpApplication)sender).Context;
              if (some condition)
              {
                 context.RewritePath(url);
               }
          }
          void context_PreRequestHandlerExecute(object sender, EventArgs e)
          {
              //We set back the original url on browser
              HttpContext context = ((HttpApplication)sender).Context;
  
              if (context.Items["originalUrl"] != null)
              {
                  context.RewritePath((string)context.Items["originalUrl"]);
              }
          }
  }
  </code></pre>
  
  <p>I have register it in web.config and it is working fine. But when I deploy it in IIS that session and application variables are not throwing null referent Exceptions.</p>
  
  <p>Can anyone help me? </p>
  
  <p>Edit: Do it require extra code to access session/ Application variable for rewritten URLs
  ? </p>