It seems that instead of asking how I do it, you should ask yourself WHY I do it like this. Perhaps this is a design decision, not a technical issue.
Although, if you really have one controller action for multiple login pages, you can try ...
return Redirect(Request.UrlReferrer.ToString());
Or save the route name in TempData and just use RedirectToRoute (TempData ["LoginRoute"]);
Both solutions have a bad code smell though.
Please note that if you do not check cross-site injections that will simply return to another site. You can do some validation on the reference URL.
source share