当前位置 : 主页 > 网络编程 > ASP >

asp.net-mvc – 限制匿名访问ASP.Net MVC站点的问题

来源:互联网 收集:自由互联 发布时间:2021-06-24
每当我在MVC网站中限制匿名访问时,我都会收到404错误: Server Error in ‘/’ Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have bee
每当我在MVC网站中限制匿名访问时,我都会收到404错误:

Server Error in ‘/’ Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make > sure that it is spelled correctly.

Requested URL: /Account/Login

我刚刚第一次玩MVC (RC1 Refresh),在让我退出的会员提供商工作后,我想锁定网站以防止匿名访问.我尝试使用web.config的传统方式:

<configuration>
    <system.web> 
        <authorization> 
            <deny users="?"/> 
        </authorization> 
    </system.web> 
</configuration>

但即使我明确允许匿名访问登录页面,也会出现上述错误.

我还尝试了Scott Gu’s blog中提到的技术,并通过在HomeController中添加[Authorize]属性来保护About页面

[Authorize]
public ActionResult About()
{
    return View();
}

但是当我尝试访问该页面时遇到了同样的错误.

我甚至尝试在单独的机器上进行干净安装.

那么如何在ASP.Net MVC RC1 Refresh中启用授权?

默认的Web.Config包含错误.它有:

<authentication mode="Forms">
    <forms loginUrl="~/Account/Login"/>
</authentication>

这应该是:

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

(请原谅我提问并回答我自己的问题,但我花了很长时间才发现这一点,并且无法通过Google或SO找到任何线索.如果已发布,请随时关闭).

网友评论