【问题标题】:MVC 3 FormsAuthentication Not working when deployedMVC 3 FormsAuthentication 部署时不起作用
【发布时间】:2011-11-29 12:03:21
【问题描述】:

我有一个在我的开发环境中运行良好的 MVC 3 应用程序(你 之前一定听说过..)我正在将它部署到免费主机上 服务http://somee.com 进行测试,.NET 框架设置为 4. 我有一个自定义会员提供商。我可以注册一个用户,因为我可以在数据库中看到它,但是用户永远不会通过身份验证。我总是被重定向到登录页面,无论是在注册之后还是登录时。我已经完成了一个 bin 部署,并且在我的 bin 文件夹中有这个 dll:

•System.Web.Mvc
•Microsoft.Web.Infrastructure
•System.Web.Razor
•System.Web.WebPages •System.Web.WebPages.Razor
•System.Web.Helpers

在配置中: ...

   <add key="loginUrl" value="~/Account/Logon" />
  </appSettings>
....
    <membership defaultProvider="ServiceMembershipProvider">
      <providers>
        <clear/>
        <add name="ServiceMembershipProvider"
             type="Infrastruture.ServiceMembershipProvider, Infrastruture" />
      </providers>
    </membership>
  <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

控制器:

  [HttpPost]
        public ActionResult Register(FormCollection registration)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var registrationViewModel = MapFormToRegistrationViewModel(registration);
                    companyManager.RegisterCompany(registrationViewModel);
                    FormsAuthentication.SetAuthCookie(registrationViewModel.SystemUserViewModel.Email, false);
                    return RedirectToAction("Welcome", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "LogId already taken");
                }
            }
            catch(Exception ex)
            {
                               return View("Register", new RegistrationViewModel(dataReferenceService));
            }

            return View("Register", new RegistrationViewModel(dataReferenceService));
        }
    /* /Home/Welcome */
    [Authorize]
    public ActionResult Welcome()
    { return View(); }

现在没有想法了......

【问题讨论】:

  • 您是否缺少自定义 Infrastruture.ServiceMembershipProvider 的 dll?
  • 不,我认为自定义提供程序可能是原因,但我检查了 dll 是否存在并测试了它输入用户名和错误密码,它给了我正确的行为。当我提供正确的用户名 - pwd 时,我只是被重定向,就像我没有通过身份验证一样,当我使用错误的 pwd 时,我可以看到错误消息。
  • 我应该已经明确了,除了我的部署 dll,我还添加了 System.Web.MVC ...等

标签: asp.net-mvc-3 deployment formsauthentication


【解决方案1】:

我知道这是一个老问题,但我遇到了类似的问题,并在搜索答案时发现了这个问题。

解决方案是将以下设置添加到您的网络配置文件中。

<appSettings>
<add key="enableSimpleMembership" value="false"/>
</appSettings>

这是必需的原因是某些应用程序启动前代码似乎与默认设置存在一些问题。

一个更好的解释和我找到这个解决方案的地方是here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多