Search code examples
c#asp.netglobal-asax

Redirect on Global.asax not working


I have empty website with blank index.html file (only mandatory HTML tags). And wanted to try out redirect through Global.asax file, but either the Global.asax file is not working for some reason or my redirect is badly coded. Here is the code on Global.asax:

namespace redirectURL
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            string responseURL = "http://live.com/blog";

            if (Request.Url.ToString().ToLower().Contains("://loc.test.com"))
            {
                Response.Redirect(responseURL);
            }
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}

Thanks for help in forward.


Solution

  • Instead of creating blank(empty web application) website I used "web forms application" and added same code as above to my global.asax file and removed all the content files that I did not need(leaving global.asax, web.config, references and properties). And end result was as needed - empty project with only redirect on global.asax file.