Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

302 Redirect all pages to homepage - ASP.NET

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)?

like image 352
Metzed Avatar asked Oct 18 '25 15:10

Metzed


1 Answers

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.

like image 186
Alex Filipovici Avatar answered Oct 20 '25 05:10

Alex Filipovici



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!