cod*_*ast 3 asp.net-mvc authorization
每当我在MVC网站中限制匿名访问时,我都会收到404错误:
'/'应用程序中的服务器错误.无法找到该资源.说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用.请查看以下网址,并确保拼写正确.
请求的URL:/帐户/登录
我刚刚第一次玩MVC (RC1刷新),在让我退出的会员提供商工作后,我想锁定网站以防止匿名访问.我尝试使用web.config的传统方式:
<configuration>
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但即使我明确允许匿名访问登录页面,也会出现上述错误.
我还尝试了Scott Gu博客中提到的技术,并通过在HomeController中添加[Authorize]属性来保护About页面.
[Authorize]
public ActionResult About()
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试访问该页面时遇到了同样的错误.
我甚至尝试在单独的机器上进行干净安装.
那么如何在ASP.Net MVC RC1 Refresh中启用授权?
默认的Web.Config包含错误.它有:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login"/>
</authentication>
Run Code Online (Sandbox Code Playgroud)
这应该是:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn"/>
</authentication>
Run Code Online (Sandbox Code Playgroud)
(请原谅我提问并回答我自己的问题,但是我花了很长时间才发现这一点,并且无法通过Google或SO找到任何线索.如果已发布,请随时关闭).
归档时间: |
|
查看次数: |
4211 次 |
最近记录: |