Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 ASP.NET MVC3表单身份验证不';不允许post登录操作_Asp.net Mvc 3_Forms Authentication - Fatal编程技术网

Asp.net mvc 3 ASP.NET MVC3表单身份验证不';不允许post登录操作

Asp.net mvc 3 ASP.NET MVC3表单身份验证不';不允许post登录操作,asp.net-mvc-3,forms-authentication,Asp.net Mvc 3,Forms Authentication,与此类似: 我无法让我的表单将用户名/密码提交给登录操作的post处理程序。但是,my AccountController继承自默认控制器,即no[Authorize]-属性。我的帐户控制器如下所示: [HttpGet] public ActionResult LogOn() { return View(); } [HttpPost] public ActionResult LogOn(LogOnModel model, string returnUrl = null)

与此类似:

我无法让我的表单将用户名/密码提交给登录操作的post处理程序。但是,my AccountController继承自默认控制器,即no
[Authorize]
-属性。我的帐户控制器如下所示:

 [HttpGet]
 public ActionResult LogOn()
 {
     return View();
 }

 [HttpPost]
 public ActionResult LogOn(LogOnModel model, string returnUrl = null)
 {
     ...
 }
<form action="/" id="LogOnForm" method="post">
@using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { id = "LogOnForm" }))
routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Account", action = "LogOn", id = UrlParameter.Optional } // Parameter defaults
);
my web.config包含以下内容:

    <location path="Account">
            <system.web>
                    <authorization>
                            <allow users="?"/>
                    </authorization>
            </system.web>
    </location>

    <authorization>
        <deny users="?" />
    </authorization>

    <authentication mode="Forms">
        <forms loginUrl="~/Account/LogOn" timeout="2880" defaultUrl="~/Home/Index" />
    </authentication>
如果我把
注释掉,一切正常。然而,在这种情况下,当我输入一个需要授权的页面的深度链接时,我不会被重定向到登录页面

我还尝试添加位置“帐户”并允许所有用户使用,但这似乎没有任何效果

有人能指出我做错了什么吗

编辑

在Fiddler中,我总是看到这种模式:

#   Result  Protocol    Host    URL Body    Caching Content-Type    Process Comments    Custom  
1   302 HTTP    localhost:36372 /   145 private     text/html; charset=utf-8    iexplore:6400           
2   200 HTTP    localhost:36372 /Account/LogOn?ReturnUrl=%2f    4,752   private     text/html; charset=utf-8    iexplore:6400           
为什么第一个URL总是
/

EDIT2

我突然想到要检查生成的HTML,令我惊讶的是它看起来是这样的:

 [HttpGet]
 public ActionResult LogOn()
 {
     return View();
 }

 [HttpPost]
 public ActionResult LogOn(LogOnModel model, string returnUrl = null)
 {
     ...
 }
<form action="/" id="LogOnForm" method="post">
@using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { id = "LogOnForm" }))
routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Account", action = "LogOn", id = UrlParameter.Optional } // Parameter defaults
);
我的路线是这样的:

 [HttpGet]
 public ActionResult LogOn()
 {
     return View();
 }

 [HttpPost]
 public ActionResult LogOn(LogOnModel model, string returnUrl = null)
 {
     ...
 }
<form action="/" id="LogOnForm" method="post">
@using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { id = "LogOnForm" }))
routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Account", action = "LogOn", id = UrlParameter.Optional } // Parameter defaults
);

您需要为/account/logon添加位置标记,并允许匿名访问该标记。

您可以使用MVC中的简单授权属性设置授权

    [Authorize]
    public ViewResult SubmitPost()
    {
        return View();
    }    
您必须为授权设置cookie,默认情况下,授权将创建加密cookie&will 仅在浏览器关闭时过期

   FormsAuthentication.SetAuthCookie("Name", false);

正如我在文章中提到的,我已经试过了,但没有效果。你能将你的帐户/登录位置标签与web.config中的表单身份验证内容一起粘贴吗?上面的web.config只有“Account”的位置,您能尝试一下将其更改为Account/logon吗?我在阅读了您的帖子后尝试过,但没有效果。也许这也不是问题所在。查看我的编辑。