What should I do to redirect to a web form from an MVC controller?

I have this line in the controller:

Response.Redirect("~/WebForms/ReportViewer.aspx"); 

Then this simple test code in Page_Load in ReportViewer.aspx:

 protected void Page_Load(object sender, EventArgs e) { Response.Write("Hello"); return; } 

This code is not even executed, i.e. Page_Load not running. I suppose there is something that I have to do before redirecting to a web form, but I have no idea what it is. I saw a complete sample of code that just calls Redirect .

My web form has a Crystal Reports report viewer that may have something to do with the situation:

 <body> <form id="form" runat="server"> <CR:CrystalReportViewer ID="CrystalViewer" runat="server" AutoDataBind="true" /> </form> </body> 
+4
source share
2 answers
 return Redirect("~/Webform.aspx"); 

is perfect, and its return type is RedirectResult, and it works amazingly, I tested it.

My actions look like

  public ActionResult Print() { return Redirect("~/Webform2.aspx"); } 

Thanks @Andrey Gubal

+7
source

Perhaps this link will be useful: Response.Redirect to another URL. This is a question about redirecting from the controller to .aspx

The basic idea is to use return Redirect("url"); instead of Response.Redirect("url");

+1
source

Source: https://habr.com/ru/post/1495799/


All Articles