我正在尝试将其用于登录页面。
if (Session["UserID"] == null)
Server.Transfer("/Account/Login", true);
但我收到了异常 -> 执行子请求/Account/Login时出错。
我正在尝试将其用于登录页面。
if (Session["UserID"] == null)
Server.Transfer("/Account/Login", true);
但我收到了异常 -> 执行子请求/Account/Login时出错。
要使用服务器转移方法,您可以查看Simon Weaver的这篇文章,但在您的问题背景下,我建议使用重定向操作。
RedirectToAction(new {
controller="Account",
action="Login"
});
为了使其告诉登录控制器返回哪里尝试
RedirectToAction( new {
controller="Account",
action="Login",
new RouteValueDictionary {
{"actionToGoBackTo", "theActionName"},
{"controllerToGoBackTo", "theControllerName"}
});
public ActionResult Index() {
......
var url = "/MyContoller?param=xxx";
Server.TransferRequest(url, true);
return new EmptyResult();
}