Asp.net MVC ReturnUrl值始终为空

Asp.net MVC ReturnUrl值始终为空,asp.net,authentication,model-view-controller,login,returnurl,Asp.net,Authentication,Model View Controller,Login,Returnurl,好的,在发布这篇文章之前,我已经研究并尝试了每一个建议(当然是个别的),每次我都碰壁 这是我的登录视图,我使用ViewBag传递ReturnUrl值,正如我在这个问题的许多答案中看到的那样 <h2>Login</h2> @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { role = "form" })) {

好的,在发布这篇文章之前,我已经研究并尝试了每一个建议(当然是个别的),每次我都碰壁

这是我的登录视图,我使用ViewBag传递ReturnUrl值,正如我在这个问题的许多答案中看到的那样

   <h2>Login</h2>
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { role = "form" }))
{
    @Html.AntiForgeryToken()


  ...............
最后,这是我在web.config文件中添加的行

 <authentication mode="Forms">
      <forms cookieless="UseCookies"  loginUrl="/Account/Login"  timeout="30" slidingExpiration="true" protection="All"></forms>
    </authentication>

当我运行这个程序时,我从来没有真正登录过它,它总是将我发送回登录页面,并且returnUrl的值总是空的
那么这里发生了什么???

好的,经过多次搜索,我在这里找到了答案 [ ]

我必须在system.WebServer中的web.config模块中添加这些行

<remove name="FormsAuthentication" />
      <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />


您是否可以包括
登录
获取方法(您当前的示例只有POST方法)<如果GET action方法结果分配了URL,则code>ViewBag.ReturnUrl值存在,否则它作为
ViewBag
默认值为空。考虑使用<代码> VIEW.BACK.RUTURNURL=请求.QuielString(“ReururNurl”)< /代码>如果您确信返回的URL来自查询字符串。是的,我有get action方法<代码>公共ActionResult Login(String Retrurnl){VIEWBAG.RetrurNurl=RetrurNurl;Read VIEW();我将尝试此操作,但是否必须更改视图中的任何内容?它不起作用:(还有其他想法吗?我在这里感到迷茫已经好几天了,仍然没有找到任何解决这个令人沮丧的问题的方法。为什么不在
UserLogin
viewmodel类中添加return URL属性并通过
HiddenFor
传递返回的URL?当
UserLogin
使用POST提交时,它会自动传递返回的URL值,您可以n使用
ViewBag.ReturnUrl=login.ReturnUrl
分配它。好的,现在有一个进展返回Url有一个值,但我的用户仍然被重定向到登录页面,好像他没有授予身份验证…我想部分问题是我没有完全理解,我在另一个论坛上发布了这篇文章,有人指出我没有没有用户实际登录的代码你还有其他想法吗?谢谢web.config的模块在哪里,或者你指的是什么文件?在web.config文件中有modules标签,里面有system.WebServer标签,我把上面的代码放在那里。
<remove name="FormsAuthentication" />
      <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />