[英]Defining the login URL with [Authorize] attribute
I'm making a private-pages-only application in MVC4. 我正在MVC4中创建一个仅限私有页面的应用程序。
I successfully (almost successfully) created the login page using a custom Membership provider based on NHibernate and my domain's entities/repositories. 我成功(几乎成功)使用基于NHibernate和我的域的实体/存储库的自定义成员资格提供程序创建了登录页面。
Every controller but AuthController
is marked with [Authorize]
. 除了
AuthController
每个控制器都标有[Authorize]
。
The webapp is supposed to redirect me to the login page when I'm not authorized. 当我未获得授权时,webapp应该将我重定向到登录页面。 I created the whole app from scratch, so I know that nowhere I'll find the
AuthController
to be declared as landing URL for unauthenticated users. 我从头开始创建整个应用程序,所以我知道无处可见我会将
AuthController
声明为未经身份验证的用户的登陆URL。
Assuming you're using the built-in forms authentication, the URL goes into web.config
, in the loginUrl
attribute of the forms
element. 假设您正在使用内置表单身份验证,则URL将进入
forms
元素的loginUrl
属性中的web.config
。
http://msdn.microsoft.com/en-us/library/1d3t3c61(v=vs.71).aspx http://msdn.microsoft.com/en-us/library/1d3t3c61(v=vs.71).aspx
<configuration>
<system.web>
<authentication mode="Forms">
<forms loginUrl="/membership/login" />
</authentication>
</system.web>
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.