Viv*_*ndi 2 c# forms-authentication asp.net-mvc-3
我正在研究一个MVC3项目,我必须添加一个登录机制.我必须使用这种<authentication>
方法.我以为这会自动将用户重定向到登录页面?但什么都没发生.
我在我的web.config
文件中有这个:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
但我的登录控制器不会自动调用.我需要做些什么才能让它按照我想要的方式工作?
如果用户尝试访问受保护资源(例如,使用该[Authorize]
属性修饰的控制器操作)并且未进行身份验证,则会将用户重定向到LogOn页面.
如果要将LogOn
操作用作起始页面,则可以更新路径设置Global.asax
以提供默认控制器和操作:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Account", action = "LogOn", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
现在,当用户导航到/
他时,他将自动显示登录屏幕.