One way to get close to this is to look for a specific controller in RouteData . Assuming that the controller that you use for the home page is called "HomeController", then the RouteData for the request will contain the value "Home" for the key "Controller".
It will look something like this:
instead (or in addition to if you have other reasons for this):
@Html.Hidden("returnUrl", Request.Url.AbsoluteUri)
you will have:
@Html.Hidden("referrer", Request.RequestContext.RouteData.Values['Controller'])
and your controller will look like this:
[HttpPost] public ActionResult LogOnInt(LogOnModel model) { if (model.referrer = "Home") { return Json(new { redirectToUrl = @Url.Action("Index","Home")}); } }
This will eliminate the need to use .Contains()
Update :
You can also eliminate the need for a hidden field (and thereby reduce the total page weight for what will look like every page of your application) by matching the referrer URL ( Request.UrlReferrer.AbsoluteUri ) with the route. There is a message about this here.
How to get RouteData by url?
The idea would be to use the mvc mechanism to map the referrer URL to the MVC route in the LogOnInt method to completely isolate the code.
This will probably be cleaner than putting the controller name and the action name there so that the world sees along with the script in order to return it back to the server.
parKing
source share