Aspx page to redirect to new page

What is the code needed to redirect the browser to a new page using an ASPX page?

I tried this on my default.aspx page:

<% Response.Redirect("new.aspx", true); %> 

or

 <%@ Response.Redirect("new.aspx", true); %> 

And this led to a server error that is not defined. I do not see the error code; because the server is not at my disposal and the errors are not publicly available.

Please provide all the necessary code from line 1 of the page to the end, and I would greatly appreciate it.

+70
redirect c #
Jul 07 '09 at 15:40
source share
8 answers
 <%@ Page Language="C#" %> <script runat="server"> protected override void OnLoad(EventArgs e) { Response.Redirect("new.aspx"); } </script> 
+140
Jul 07 '09 at 15:41
source share

You can also do this simply in html with a meta tag :

 <html> <head> <meta http-equiv="refresh" content="0;url=new.aspx" /> </head> <body> </body> </html> 
+21
Jul 07 '09 at 15:53
source share

Darin's answer works great. It creates a redirect 302. Here the code is changed so that it creates a permanent 301 redirect:

 <%@ Page Language="C#" %> <script runat="server"> protected override void OnLoad(EventArgs e) { Response.RedirectPermanent("new.aspx"); base.OnLoad(e); } </script> 
+15
Jul 03 '13 at 7:20
source share

If you use VB, you need to drop the semicolon:

 <% Response.Redirect("new.aspx", true) %> 
+11
Jul 07 '09 at 15:52
source share

Or you can use javascript to redirect to another page:

 <script type="text/javascript"> function toRedirect() { window.location.href="new.aspx"; } </script> 

Call this toRedirect() function from the client (for example: the onload event of the body tag) or from the server using:

 ClientScript.RegisterStartupScript(this.gettype(),"Redirect","toRedirect()",true); 
+3
Jul 03 2018-12-12T00:
source share

Even if you do not control the server, you can still see error messages by adding the following line to the Web.config file in your project (bewlow <system.web> ):

 <customErrors mode="off" /> 
+2
Jul 07 '09 at 15:55
source share

Redirect aspx:

 <iframe> <script runat="server"> private void Page_Load(object sender, System.EventArgs e) { Response.Status = "301 Moved Permanently"; Response.AddHeader("Location","http://www.avsapansiyonlar.com/altinkum-tatil-konaklari.aspx"); } </script> </iframe> 
0
Jun 08 '14 at 15:16
source share

In a special case in ASP.NET. If you want to know if the page is redirected by the specified .aspx page and not the other, just put the information in the session name and perform the necessary actions in the receiving Page_Load event.

0
Jun 26 '19 at 2:56
source share



All Articles