Redirect URL Using HttpModule Asp.net

前端 未结 1 1654
醉酒成梦
醉酒成梦 2021-01-13 11:18

I have created an HttpModule so that Whenever I type \"localhost/blabla.html\" in the browser, it will redirect me to www.google.com (this is just an example, it\'s really

相关标签:
1条回答
  • You can use request object in BeginRequest event

    public class MyHttpModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
              context.BeginRequest += new EventHandler(this.context_BeginRequest);
        }
    
        private void context_BeginRequest(object sender, EventArgs e)
        {
              HttpApplication application = (HttpApplication)sender;
              HttpContext context = application.Context;
    
              //check here context.Request for using request object 
              if(context.Request.FilePath.Contains("blahblah.html"))
              {
                   context.Response.Redirect("http://www.google.com");
              }
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题