密码保护 IIS 7 (.Net MVC 2) 中的目录
我有一个内置于 .NET MVC 2 中的 Web 应用程序。我想使用密码(基本身份验证)保护目录。在 IIS 6 中,我只需转到安全设置中的目录并删除匿名。
但在 IIS 7 中,我无法让它工作。
在身份验证的网站根目录中,我启用了匿名,因为我希望任何人都可以访问该网站。明显地。
然后我转到我想要保护的 MVC 目录 (Views/Admin) 并禁用匿名,同时启用基本身份验证。这是行不通的。我尝试了授权规则,但它也不起作用。
这是因为 MVC 使用某种路由吗?我的意思是,views/admin 文件夹实际上是 website.com/admin,我想这是一个虚拟目录。
那么,如何在 IIS 7 上的 .NET MVC 2 中设置受密码保护的子目录?
谢谢
斯蒂芬
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.
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.
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.
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.
So, how to setup a password protected sub-directory in .NET MVC 2 on IIS 7?
Thanks
Stephane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人偶然发现这一点...
您需要添加 AuthorizeAttribute 到您的控制器以保护整个事物或特定的操作方法。
如ASP.NET 教程,当在请求过程中遇到此属性时,它将检查用户是否经过正确的身份验证并在角色中获得正确的授权来访问控制器或操作。如果没有,它将请求用户进行身份验证。
If someone stumbles upon this...
You need to add the AuthorizeAttribute to either your Controller to protect the whole thing or specific Action methods.
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.