我有一个MVC 4应用程序,对所有用户开放,无需登录.只有一个控制器,我需要通过Web.Config应用Windows身份验证,如下所示:authentication mode=Windows /authorizationallow users=domain\jsmith /deny user...
我有一个MVC 4应用程序,对所有用户开放,无需登录.只有一个控制器,我需要通过Web.Config应用Windows身份验证,如下所示:
<authentication mode="Windows" />
<authorization>
<allow users="domain\jsmith" />
<deny users="*" />
</authorization>
控制器将是MySite.Com/MyApp/MyAdminReportController
如果这是可能的,怎么样?
解决方法:
我认为您只需要Windows身份验证并指定只需要授权的路径.如果您不需要Forms auth,它看起来像这样:
<configuration>
...
<system.web>
......
<authentication mode="Windows">
</authentication>
</system.web>
<location path="MyAdminReport">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
</configuration>
这是Web配置方法,其他选项是将[Authorize]属性添加到您的控制器(即使不是孔控制器,您也可以仅为特定操作添加此attr).
[Authorize]
public class MyAdminReportController : Controller
{
//[Authorize]
public ActionResult PrivatePage()
{
return View();
}
}
沃梦达教程
本文标题为:c# – ASP.NET MVC 4将Windows身份验证应用于单个控制器?
猜你喜欢
- Oracle中for循环的使用方法 2023-07-04
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- c# 模拟线性回归的示例 2023-03-14
- Unity3D实现渐变颜色效果 2023-01-16
- user32.dll 函数说明小结 2022-12-26
- Unity Shader实现模糊效果 2023-04-27
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- .NET CORE DI 依赖注入 2023-09-27
- 如何使用C# 捕获进程输出 2023-03-10
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16