1
사용자 지정 폼 인증 티켓을 설정 한 후 보안 된 작업으로 리디렉션하는 문제가 있습니다. 여기에 무슨 일이 일어나고 있는지입니다 : 내가 자동/계정 사이트로 리디렉션하고있어 ASP.Net MVC 4 사용자 지정 티켓 리디렉션 문제
- /통과
- RedirecToUrl () 함수는 나를 사이트/홈/색인으로 다시 리디렉션하려고 시도하지만 사이트/계정/로그인으로 자동으로 되돌아갑니다.
- 요청이 인증되었습니다. 사이트/홈/색인으로 수동 이동하면 허용됩니다.
아무도 빛을 비출 수 있습니까?
내 HomeController :
[Authorize]
public ActionResult Index()
{
return View();
}
내 AccountController : 나는 정의 티켓을 만드는 방법
다음[HttpGet]
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
bool bLogin = MyAuthentication.Login(model.UserName, model.Password);
if (bLogin)
{
Response.Cookies.Add(MyAuthentication.GetAuthenticationCookie(model.UserName.ToLower(), model.RememberMe));
RedirectToUrl(returnUrl);
}
else
ModelState.AddModelError("", "That is not a valid Username/Password combination");
}
return View(model);
}
private ActionResult RedirectToUrl(string returnUrl)
{
if (Url.IsLocalUrl(returnUrl))
return Redirect(returnUrl);
else
return RedirectToAction("Index", "Home");
}
입니다 (다만 추가 유저 데이터) :
public static HttpCookie GetAuthenticationCookie(string UserName, bool persistLogin)
{
var userData = null; // Code removed for brevity
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
1,
UserName,
DateTime.Now,
DateTime.Now.AddMinutes(20),
persistLogin,
userData);
string encTicket = FormsAuthentication.Encrypt(authTicket);
return new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
}