加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 09:29:39 所属栏目:asp.Net 来源:网络整理
导读:每当我在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
每当我在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找到任何线索.如果已发布,请随时关闭).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读