2014-09-22 67 views
0

我正在使用Asp.net MVC 5.1.1并面临这个奇怪的问题。每当我将我的web应用程序部署到测试服务器(具有IIS 8.5)时,当前会话就会过期(这很明显),然后他们重定向到帐户/登录而不是帐户/登录。正常注销或新建页面正确命中需要用户帐户/登录(这是我在我的配置中设置的)。但会话到期后,它会显示这种奇怪的行为。我查了一下,没有提及webmatrix.dll。即使this问题也没有帮助。请建议最新错误。 感谢asp.net MVC 5有时形式认证重定向到帐户/登录而不是帐户/登录

编辑1:

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/Logon" timeout="2880" /> 
</authentication> 
+0

你可以添加'标签在你的web.config中? – ekad 2014-09-22 07:35:51

+0

ZafarYousafi 2014-09-22 07:49:08

+0

奇怪的是,尝试搜索当前的“login”或“account/login”项目与“匹配全字”选项打勾。如果您的项目中没有任何地方提及“登录”或“帐户/登录”网址,则可能是IIS中的设置。 – ekad 2014-09-22 07:57:28

回答

-1

据我所知,MVC 5配备了新的OWIN/ASP.NET身份认证位。在一个新的MVC 5项目的web.config文件,其实我注意到,FormsAuthenticationModule被禁用

<system.webServer> 
    <modules> 
     <remove name="FormsAuthenticationModule" /> 
    </modules> 

此外,还有是在App_Start文件夹名为Startup.Auth.cs创建一个新文件。在这个文件中的与“/帐号/登录”的默认登录路径

public void ConfigureAuth(IAppBuilder app) 
{ 
    // Enable the application to use a cookie to store information for the signed in user 
    app.UseCookieAuthentication(new CookieAuthenticationOptions 
    { 
     AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
     LoginPath = new PathString("/Account/Login") 
    }); 

尝试更改为您的应用正确的路径是路径,CookieAuthenticationOptions(新FormsAuthentication名称)的定义。或者,您无法使用新的ASP.NET标识位,并删除web.config中删除FormsAuthenticationModule的行。

如果你不使用或想要使用新的身份验证选项,在您的应用程序的根目录中删除调用ConfigureAuth()Startup.cs文件并删除上面的行中删除FormsAuthenticationModule web.config中。这应该恢复预期的行为(同样,不知道你对默认代码做了多少定制)。

1

我有同样的问题,你应该检查你StartupAuth.cs

这是帮了我很多答案:http://coding.abel.nu/2014/11/using-owin-external-login-without-asp-net-identity/

而且这种添加此项的帮助: https://stackoverflow.com/a/6081661/79379

为了将来的参考,我将在这里包括相关的代码:

<add key="loginUrl" value="~/Account/LogOn" /> 

public partial class Startup 
{ 
    private void ConfigureAuth(IAppBuilder app) 
    { 
    var cookieOptions = new CookieAuthenticationOptions 
     { 
     LoginPath = new PathString("/Account/Login") 
     }; 

    app.UseCookieAuthentication(cookieOptions); 
    } 
}