I am trying to use it for Login page.
if (Session["UserID"] == null)
Server.Transfer("/Account/Login", true);
But I get The Exception -> Error executing child request /Account/Login.
I am trying to use it for Login page.
if (Session["UserID"] == null)
Server.Transfer("/Account/Login", true);
But I get The Exception -> Error executing child request /Account/Login.
You don't. Use a redirect action instead.
RedirectToAction(new {
controller="Account",
action="Login"
});
to get it to tell the login controller where to go back to try
RedirectToAction( new {
controller="Account",
action="Login",
new RouteValueDictionary {
{"actionToGoBackTo", "theActionName"},
{"controllerToGoBackTo", "theControllerName"}
});
note that the Login action will need to take two string arguments, actionToGoBackTo, and controllerToGoBackTo.
return new MVCTransferResult(...);
Please see my answer (linked) as well as the accepted answer.