2014-09-22 54 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); 
    } 
}