问题限制到一个ASP.Net MVC网站的匿名访问 [英] Problem restricting anonymous access to an ASP.Net MVC Site

查看:344
本文介绍了问题限制到一个ASP.Net MVC网站的匿名访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我限制我的MVC网站的匿名访问,我得到一个404错误:

Whenever I restrict anonymous access in my MVC site I get a 404 error:

在'/'应用程序的服务器错误。
    资源无法找到。
    说明:HTTP 404。您正在寻找(或它的一个依赖)可能已被删除的资源,更名或暂时不可用。请检查以下URL并>确认其拼写正确。

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.

请求的URL:/帐号/登录

Requested URL: /Account/Login

我刚刚在玩MVC <一个href=\"http://www.microsoft.com/downloads/details.aspx?FamilyID=f4e4ee26-4bc5-41ed-80c9-261336b2a5b6&displaylang=en\"相对=首次和让我退出成员提供工作,我想锁定现场prevent匿名访问后,nofollow的>(RC1刷新)。我试着用用web.config中的传统方式:

I've just been playing with MVC (RC1 Refresh) for the first time and after getting my exiting membership provider working I wanted to lock down the site to prevent anonymous access. I tried the traditional way using web.config with:

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

但得到上面的错误,即使我明确地允许在登录页面的匿名访问。

but got the above error even though I explicitly allowed anonymous access to the logon page.

我也试过在的斯科特谷的博客并通过在HomeController中添加[授权]属性担保关于页

I also tried the technique mentioned in Scott Gu's blog and secured the About page by adding the [Authorize] attribute in the HomeController

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

但得到了同样的错误,当我试图访问该页面。

but got the same error when I tried to access that page.

我甚至尝试了全新安装一个单独的机器上。

I've even tried a clean install on a separate machine.

那么,如何在ASP.Net MVC RC1刷新启用授权?

So how do you enable Authorization in ASP.Net MVC RC1 Refresh?

推荐答案

默认Web.Config中包含一个错误。它具有:

The default Web.Config contains an error. It has:

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

这应该是:

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

(原谅我提出和回答我的问题,但我花了年龄发现这一点,但没有找到通过谷歌或任何线索左右。如果这之前已经发布随意关闭)。

(Excuse me asking and answering my own question but it took me ages to spot this and couldn't find any clues via Google or SO. if this has been posted before feel free to close).

这篇关于问题限制到一个ASP.Net MVC网站的匿名访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆