Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is RedirectToRoute supposed to be used?

I have this in my Global.asax.cs:

routes.MapRoute("BetaAccess", "beta-access", new { controller = "Beta", action = "Index" }); 

And this in my controller (index action on HomeController) and it definitely is getting hit:

RedirectToRoute("BetaAccess"); 

But still no redirection happens... it just goes to the normal home page. Am I using it wrong?

Also, I can do Response.Redirect("~/beta-access") and it goes to the beta page...

like image 699
Max Schmeling Avatar asked Aug 17 '09 20:08

Max Schmeling


People also ask

What is difference between RedirectToAction and RedirectToRoute?

RedirectToAction will return a http 302 response to the browser and then browser will make GET request to specified action. Show activity on this post. Ideally I would use RedirectToRoute for Action Links/Images and RedirectToAction in Controller's Action to redirect to another Controller's Action .

What is RedirectToRoute in MVC?

RedirectToRoute(Object) Redirects to the specified route using the specified route values. RedirectToRoute(String) Redirects to the specified route using the route name.

How do I use response redirect?

Response. Redirect sends an HTTP request to the browser, then the browser sends that request to the web server, then the web server delivers a response to the web browser. For example, suppose you are on the web page "UserRegister. aspx" page and it has a button that redirects you to the "UserDetail.

What is RedirectToAction MVC?

RedirectToAction(String, Object) Redirects to the specified action using the action name and route values. RedirectToAction(String, String) Redirects to the specified action using the action name and controller name.


2 Answers

RedirectToRoute returns a RedirectToRouteResult. Try this instead.

return RedirectToRoute("BetaAccess"); 
like image 157
Joel Avatar answered Sep 27 '22 20:09

Joel


This will redirect you.

Response.RedirectToRoute("BetaAccess"); Response.End(); 
like image 41
Michael Avatar answered Sep 27 '22 21:09

Michael