登录后,ASP.net MVC应用程序很快退出。

| 这可能是一个非常简单的问题,但是我看不到解决方案及其真正的困扰! 我有一个简单的ASP.Net MVC2应用程序,旨在作为一种学习辅助工具,要求用户通过提供用户名和密码来登录。使用成员身份提供程序对这些数据库进行身份验证,该成员资格提供程序是使用aspnet_regsql工具创建和配置的。 Web配置看起来像这样(我认为是正确的……但是可能不确定表单身份验证位):
<authentication mode=\"Forms\">
  <forms loginUrl=\"~/Account/LogOn\" timeout=\"2380\"/>
</authentication>
<membership>
  <providers>
    <clear />
    <add name=\"AspNetSqlMembershipProvider\" type=\"System.Web.Security.SqlMembershipProvider\" connectionStringName=\"ApplicationServices\" enablePasswordRetrieval=\"false\" enablePasswordReset=\"true\" requiresQuestionAndAnswer=\"false\" requiresUniqueEmail=\"false\" maxInvalidPasswordAttempts=\"5\" minRequiredPasswordLength=\"6\" minRequiredNonalphanumericCharacters=\"0\" passwordAttemptWindow=\"10\" applicationName=\"/\" />
  </providers>
</membership>
<profile>
  <providers>
    <clear />
    <add name=\"AspNetSqlProfileProvider\" type=\"System.Web.Profile.SqlProfileProvider\" connectionStringName=\"ApplicationServices\" applicationName=\"/\" />
  </providers>
</profile>
<roleManager enabled=\"false\">
  <providers>
    <clear />
    <add name=\"AspNetSqlRoleProvider\" type=\"System.Web.Security.SqlRoleProvider\" connectionStringName=\"ApplicationServices\" applicationName=\"/\" />
    <add name=\"AspNetWindowsTokenRoleProvider\" type=\"System.Web.Security.WindowsTokenRoleProvider\" applicationName=\"/\" />
  </providers>
</roleManager>
视图中执行日志过程的代码如下所示:
public ActionResult LogOn()
{
    return View();
}

[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
    if (ModelState.IsValid){
        if (MembershipService.ValidateUser(model.UserName, model.Password)){
            FormsService.SignIn(model.UserName, model.RememberMe);
            if (!String.IsNullOrEmpty(returnUrl)){
                return Redirect(returnUrl);
            }
            else{
                return RedirectToAction(\"Index\", \"Home\");
            }
        }
        else{   
            ModelState.AddModelError(\"\", \"The user name or password provided is incorrect.\");
        }
    }

    // If we got this far, something failed, redisplay form
    return View(model);
}
控制器中需要应用安全性的每个方法都被标记为:
[Authorize]
public ActionResult New() {
  return View();
}

[Authorize]
[HttpPost]
public ActionResult New(FormCollection collection) {
    //do something...
}
我也用
[Authorize]
标记了控制器类。 但是,当我通过创建新项目或编辑现有项目登录站点时,登录后很快就会注销。 控制器中的私有方法是否也需要标记“ 3”,这会导致某人注销吗? 谢谢你的帮助, 莫里斯     
已邀请:

要回复问题请先登录注册