Question

Is there a way using ASP.NET that I can 302 (temporary) redirect all pages on the website to the homepage (obviously not redirecting the homepage)?

Was it helpful?

Solution

Add this in your Global.asax file:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (Request.Url.LocalPath != "/Home.aspx")
        HttpContext.Current.Response.Redirect("Home.aspx");
}

From the HttpResponse.Redirect Method (String) article:

ASP.NET performs the redirection by returning a 302 HTTP status code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top