我有一个ASP.NET MVC Application
,其中有一个Logs
文件夹,用于存储日志文件。通常,我将以localhost/Logs/Log.common.txt
的身份访问它并查看日志。但是,现在我要限制它。
现在我有了Logs控制器,该控制器的Authorize属性仅设置为Admin
:
namespace MyApp.Controllers
{
[Authorize(Roles = "Admin")]
public class LogsController : BaseController
{
public ActionResult Index()
{
LogFile logFile = GetLogFileByName("log.Common.txt");
return View(logFile);
}
}
}
因此,现在,如果我尝试转到localhost/Logs
,则会收到未授权的访问错误,但是,如果直接转到localhost/Logs/Log.common.txt
,仍然可以看到该文件。有什么方法可以禁用此功能吗?
答案 0 :(得分:0)
对于IIS7 +,将以下web.config文件添加到/ Logs
<configuration>
<system.webServer>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="" roles="Admin" />
</authorization>
</security>
</system.webServer>
</configuration>
早期版本具有slightly different syntax。
或者,将/ logs移至/app_data