简体   繁体   English

给定文件夹ASP.NET MVC的IIS密码提示

[英]IIS Password prompt for given folder ASP.NET MVC

How can I configure IIS to prompt for passwords on a web application running on ASP.NET MVC in IIS? 如何配置IIS以在IIS中的ASP.NET MVC上运行的Web应用程序上提示输入密码?

I want to password protect the Views\\ApplicationLog\\ folder, so that browsers ask for username and password when users try to access this folder. 我想密码保护Views\\ApplicationLog\\文件夹,以便浏览器在用户尝试访问此文件夹时询问用户名和密码。

How could I accomplish this? 我怎么能做到这一点? Can this be done directly from IIS, or do I need to set something in web.config? 这可以直接从IIS完成,还是我需要在web.config中设置一些东西?

Please try to be thorough, I don't know IIS all that well. 请尽量彻底,我不太了解IIS。

If you're using MVC, you shouldn't have anyone directly accessing anything under your Views folder at all. 如果您正在使用MVC,则根本不应该有任何人直接访问您的Views文件夹下的任何内容。 Instead, your Controllers (or their actions) will assert whatever authentication is required. 相反,您的Controllers (或其操作)将断言所需的任何身份验证。

In this specific case, it looks like your controller is named ApplicationLogController . 在这种特定情况下,看起来您的控制器名为ApplicationLogController So you'd add an [Authorize] attribute on the controller as follows, and it will automatically ensure that anyone accessing the controller methods is authorized. 因此,您将在控制器上添加[Authorize]属性,如下所示,它将自动确保访问控制器方法的任何人都被授权。

[Authorize] // You can also do [Authorize(Roles="MyRole,YourRole")], etc...
public class ApplicationLogController : Controller
{
...
}

In the IIS 6 manager, go to the "Directory Security" tab, click on "Edit" then check "Integrated Windows Authentication" and / or "Basic Authentication" depending on the modes you want to support. 在IIS 6管理器中,转到“目录安全性”选项卡,单击“编辑”,然后选中“集成Windows身份验证”和/或“基本身份验证”,具体取决于您要支持的模式。

In system.web within your app's web.config: 在应用程序的web.config中的system.web中:

<authentication mode="Windows">
<authorization>
  <deny users="?" />
</authorization>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM