2013-07-17 37 views
2

嘿,我開始玩ASP.NET MVC 5預覽版,到目前爲止一切都很順利(我只能推薦它) 。ASP.NET MVC 5(Visual Studio 2013預覽版)更改登錄網址[授權]

但是,我想知道我可以在哪裏設置內置[Authorize]-屬性的Login-Url。我已將AccountController移動到某個區域,因此登錄操作的路徑不再是/Account/Login,而是MyArea/Account/Login[Authorize] -Attribute將忽略此參數,這反過來意味着無論何時導航到控制器或操作屬性集,一個被重定向到錯誤路徑/Account/Login

回答

9

查找範圍web.config像這樣的部分:

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/LogOn" timeout="2880" /> 
</authentication> 

更改loginUrl值以指向更新後的登錄頁面。

+0

哦OK,沒想到,這會工作 - 應該已經嘗試過了。但是當我想到它時,認證的「新」方式當然還是基本上是表單身份驗證。謝謝你,馬特! –

14

當使用新的OWIN表單身份驗證(而不是舊的ASP.NET表單身份驗證)時,將在Startup類中進行設置。在默認的模板,它在App_Start/Startup.Auth.csConfigureAuth方法:

public void ConfigureAuth(IAppBuilder app) 
{ 
    app.UseCookieAuthentication(new CookieAuthenticationOptions 
    { 
     AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
     LoginPath = new PathString("/Account/Login") 
    }); 
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 
} 
+0

謝謝:) @slypete –