Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use LocalRedirect vs RedirectToPage

People also ask

How do I redirect to another page in razor?

You can use the IActionResult to return a redirection or your razor page.

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

RedirectResult. RedirectResult is an ActionResult that returns a Found (302), Moved Permanently (301), Temporary Redirect (307), or Permanent Redirect (308) response with a Location header to the supplied URL. It will redirect us to the provided URL, it doesn't matter if the URL is relative or absolute.


LocalRedirect should be used when you're dealing with a "return URL", i.e. you're passing around a URL that the user should be redirected back to after some process is complete, such as logging in. In such cases, a malicious actor could send a user to your login form, for example, with a return URL back to a malicious site. Using LocalRedirect ensures that the "return URL" is a route actually on your site, instead of some malicious third-party bad actor's.

All the other redirect result types can be used when you are directly controlling where the user is being redirected to.