How do I get the referrer URL in an ASP.NET MVC action? I am trying to redirect back to the page before you called an action.
First: Add a route pattern to the end of your routing table that matches to any URL. Second: Set the default controller and action values for this pattern to the controller/action method that will display the "more helpful" View you want to provide. (And, I guess, a third step: Provide that controller/action/View.)
There might be several reasons why the referer URL would be blank. It will/may be empty when the enduser: entered the site URL in browser address bar itself. visited the site by a browser-maintained bookmark.
You can use Request.UrlReferrer
to get the referring URL as well if you don't like accessing the Request.ServerVariables
dictionary directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With