我正在尝试获得returnURL,但可能我错过了一些东西。 webconfig是:
<authentication mode="Forms">
<forms loginUrl="~/UserAccount/Login" timeout="2880" />
</authentication>
<authorization>
<allow users="?" />
</authorization>
LogIn.cshtml的一部分是:
@model Models.UserModel
@{
// ViewBag.Title = "Home Page";
}
@using (Html.BeginForm("LogIn", "UserAccount", new { ReturnUrl = Request.QueryString["ReturnUrl"] }, FormMethod.Post))
{
<div>
<table>
和部分LogIn方法是:
[HttpGet]
public ActionResult LogIn(string ReturnUrl)
{
ViewBag.ReturnUrl = ReturnUrl;
var model = new UserModel();
return View(model);
}
[HttpPost]
public ActionResult LogIn(UserModel model, string returnUrl)
{
if (!ModelState.IsValid)
我认为这就是我要做的所有事情,将returnURL转换为LogIn方法,但是无法正常工作。我做错了什么? 感谢。
答案 0 :(得分:0)
我不知道自定义授权属性在此过程中起着至关重要的作用,因此我对其进行了更改:
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.Result = new System.Web.Mvc.RedirectResult("/UserAccount/LogIn/?ReturnUrl=" + filterContext.HttpContext.Request.Url.AbsolutePath);
现在它正在运作。