密码在IIS 7中保护目录(.NET MVC 2) [英] Password protect a directory in IIS 7 (.Net MVC 2)

查看:103
本文介绍了密码在IIS 7中保护目录(.NET MVC 2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有建于.NET MVC 2的Web应用程序,我想保护目录的用密码(基本身份验证)。在IIS 6中,我会简单地去在安全设置的目录,并删除匿名的。

I have a web application built in .NET MVC 2. I'd like to protect a directory with a password (basic authentication). In IIS 6, I'd simply go to the directory in security settings and remove anonymous.

但在IIS 7,我无法得到它的工作。

But in IIS 7, I can't get it to work.

在身份验证的网站的根,我启用了匿名,因为我想任何人都可以访问的网站。很显然。

In the root of the website in authentication, I enabled anonymous because I want anyone to visit the website. Obviously.

然后我去我要保护(查看/ admin)和禁用匿名同时使基本验证了MVC目录。这是行不通的。我试着授权规则,但它也不能工作。

Then I go to the MVC directory I want to protect (Views/Admin) and disable anonymous while enabling basic authentication. This doesn't work. I tried authorization rules but it didn't work either.

这是因为MVC使用排序路由?我的意思是,意见/ admin文件夹实际上是website.com/admin是的,我想,那种虚拟目录。

Is this because MVC uses sort of routing? I mean, the views/admin folder is actually website.com/admin which is, I suppose, kind of a virtual directory.

所以,密码如何设置在IIS 7上受保护的子目录中.NET MVC 2?

So, how to setup a password protected sub-directory in .NET MVC 2 on IIS 7?

感谢

斯特凡

推荐答案

如果有人绊倒在这...

If someone stumbles upon this...

您需要添加的 AuthorizeAttribute 要么你的控制器,以保护整个事情或特定操作的方法。

You need to add the AuthorizeAttribute to either your Controller to protect the whole thing or specific Action methods.

由于在 ASP.NET教程描述,当请求过程中遇到这种属性,它会检查用户是否正确认证和访问控制或操作的作用适当授权。如果没有,它将从用户请求认证

As described in the ASP.NET Tutorials, when this Attribute is encountered during the request, it will check to see if the user is properly authenticated and properly authorized in a role to access the Controller or Action. If not, it will request authentication from the user.

这篇关于密码在IIS 7中保护目录(.NET MVC 2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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