locked
Httpmodules is not executing after first time RRS feed

  • Question

  • User-1840580866 posted

    Hi All,

     I have created one httpmodule for url rewriting. It is running fine when I
    run application first time but when second time if I do refresh the page
    httpmodule is not executing.

    When first time httpmodule execute sequence of events are as follow.

    1) Application start of global.asax

    2) Init event of httpmodule

    3) application begin request of global.asax

     

    But when second time I do refresh the page sequence of events are as  follow.

    1) directly application begin request of global.asax

     So I am unable to rewrite url second time.

    Please reply me as soon as possible.

    Regards,
    Kaivan Shah

     

     

    Sunday, April 5, 2009 12:45 PM

All replies

  • User1439985827 posted

     The Init on an HttpModule is fired only once. Rather doing your rewriting there, you should use the Init method to wire into an event to handle it, like so: 

    public sealed class UrlRewrite : IHttpModule
    {
    	public void Init(HttpApplication context)
    	{
    		context.PreRequestHandlerExecute += context_BeginRequest;
    	}
    
    	private void context_BeginRequest(object sender, EventArgs e)
    	{
    		//Handle your re-writing here.
    	}
    
    	public void Dispose()
    	{
    	}
    }
     
    Sunday, April 5, 2009 2:38 PM
  • User-1840580866 posted

     Hi Kevin,

     My code is as follow.

    namespace URLRewriting
    {
        public class Rewriteurl : System.Web.IHttpModule
        {
            public void Init(HttpApplication oHttpApplication)
            {
                oHttpApplication.BeginRequest+=new EventHandler(oHttpApplication_BeginRequest);

            }

            public void Dispose()
            {

            }

            public void oHttpApplication_BeginRequest(object sender, EventArgs e)
            {
                //url rewrite code
            }

           
        }
    }

    So when I start application at that time httpmodule is executing but when I do refresh httpmodule is not executing.

    I tried .PreRequestHandlerExecute event but when first time httpmodule execute so it comes to init event at that time i added  PreRequestHandlerExecute event but this event is not executing even first time.When I add beginrequest event it is executing first time. so my problem is why httpmodule is not executing everyrtime when I request for any page.

     Please reply me.

    Regards,
    Kaivan Shah

     

    Monday, April 6, 2009 1:00 PM