感谢大家阅读我的主题。但我需要你的帮助! 我遇到了Asp.NET MVC Action的问题。
在HomePage中。我有一个链接重定向到动作调用checkTicket(),但需要登录。
所以,在checkTicket()方法中。我正在使用以下代码来检查permision
if (Request.IsAuthenticated)
{
return View();
}
else
{
return RedirectToAction("Login", "Account");
}
但是在行动登录帐户控制器。我怎样才能返回checkTicket的View()?
这是我想要的。 首页(点击) - > checkTicket(require) - >登录(返回) - > checkTicket()
答案 0 :(得分:0)
创建一个设置的cookie,让您知道用户想检查但未登录:
if (Request.IsAuthenticated)
{
return View();
}
else
{
//The cookie's name is UserSettings
HttpCookie myCookie = new HttpCookie("UserSettings");
//The subvalue of checkticket is = true
myCookie["checkticket"] = "true";
//The cookie expires 1 day from now
myCookie.Expires = DateTime.Now.AddDays(1d);
//Add the cookie to the response
Response.Cookies.Add(myCookie);
return RedirectToAction("Login", "Account");
}
然后在您的登录操作中,检查cookie是否存在如下:
if (Request.Cookies["UserSettings"] != null)
{
string userSettings;
if (Request.Cookies["UserSettings"]["checkticket"] != null)
{
userSettings = Request.Cookies["UserSettings"]["checkticket"];
}
if(userSettings) {
//redirect to checkticket
} else {
// redirect to your normal view
}
}
*代码由MSDN提供:write cookie,read cookie