java action result_ReturnUrl指向ActionResult

这是场景的方式:

从头开始创建MVC项目

Test Controller使用[Authorize]属性修饰

用户登录并定向到主页

用户单击重定向到 TestController 的 Index 方法的链接

用户等待60秒以使表单身份验证超时

用户单击调用驻留在 TestController 上的ActionMethod的链接

MVC框架将用户重定向到Login页面并将ActionMethod名称附加到URL而不是附加 Index Action方法

TestController :

[Authorize]

public class TestController : Controller

{

// GET: Test

public ViewResult Index()

{

return View();

}

[ValidateInput(false)]

public ActionResult ActionTest()

{

return new EmptyResult();

}

}

HomeController :

[Authorize]

public class HomeController : Controller

{

public ActionResult Index()

{

return View();

}

}

AccountController :

public class AccountController : Controller

{

[AllowAnonymous]

public ActionResult Login()

{

return View();

}

[HttpPost]

[AllowAnonymous]

[ValidateAntiForgeryToken]

public ActionResult Login(LoginViewModel model, string returnUrl)

{

if (ModelState.IsValid)

{

try

{

FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

if (Url.IsLocalUrl(returnUrl))

{

return Redirect(returnUrl);

}

else

return RedirectToAction(controllerName: "Home", actionName: "Index");

}

catch

{

return View(model);

}

}

return View(model);

}

}

Login.chtml

@model TestLoginProject.Models.LoginViewModel

@{

Layout = null;

}

.....................

@using (@Html.BeginForm("Login", "Account", new { returnUrl = Request.QueryString["ReturnUrl"] }, FormMethod.Post, new { @class = "form-signin" }))

{

@Html.AntiForgeryToken()

....................

....................

}

Web Config

The expectation of the return url is :

http:// localhost:2441 /帐户/登录?ReturnUrl =%2fTest%2fIndex

Instead, the current value is :

http:// localhost:2441 /帐户/登录?ReturnUrl =%2fTest%2fActionTest

Notes :

当用户在超时后单击链接时,在重定向到“登录”页面之前不会执行任何“测试操作”

所有路由都是在VS2017中从头开始执行Empty MVC项目时提供的默认路由

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值