Reputation: 5332
I have two actions named 'abc' and 'def' in Home Controller
. The action 'abc' returns RedirectToAction("def"). So can I get the name of the action in 'def' from which the Redirect
ion triggered.
public ActionResult abc()
{
//Some code
return RedirectToAction("def");
}
public ActionResult def()
{
//Some code
string str = "You have been redirected from action 'abc'";
return Content(str);
}
How can I get this name abc in the action def ?
Upvotes: 3
Views: 1451
Reputation: 6728
Because Request.UrlReferrer
it is not 100% correct way as there are many ways that URLReferrer
can be blocked by security software/Antivirus, Firewall, Proxy program. URLReferrer
will be null in Pop Ups. That's the reason I can't use URLReferrer
to check from where this page is opened up.
Request.RequestContext.RouteData.Values["action"]
Upvotes: 1
Reputation: 1938
You can use Request.UrlReferrer
to get the referring URL or the Request.ServerVariables
dictionary, something like Request.ServerVariables["http_referer"]
Upvotes: 1