【问题标题】:Verify if Active Directory windows authorization is correctly set up in MVC5 app?验证是否在 MVC5 应用程序中正确设置了 Active Directory Windows 授权?
【发布时间】:2014-11-18 20:28:26
【问题描述】:

我已经开始为内部网站开发一个小型网络应用程序。默认视图将是一个简单的表,其中列出了 Oracle 数据库中的所有数据,其中包含多个用于搜索条件的文本框。此表中的数据还将有一个“管理”视图,我想通过 Active Directory 凭据锁定它。

参考 ASP.Net 文章“Autheticating Users with Windows Authentication”,我试图实现这一点。按照文章中的说明,我修改了我的主要 Web.config 以进行 Windows 身份验证:

<authentication mode="Windows" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Extensibility.Web.RequestTracking.WebRequestTrackingModule, Microsoft.ApplicationInsights.Extensibility.Web" />
    </httpModules>

由于我目前正在通过 Visual Studio 中包含的 ASP.NET 开发 Web 服务器进行开发,因此我认为此时不需要启用 NTLM 身份验证或 IIS 功能(如果我忽略了某些内容,请随时纠正我主要)。

然后我通过设置与示例类似的 Controllers\HomeController.cs 继续阅读本文:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using InventoryTracker.Models;
using InventoryTracker.DAL;
using System.Web.Mvc.Ajax;

namespace InventoryTracker.Controllers
{
    public class HomeController : Controller
    {
        InventoryTrackerContext _db = new InventoryTrackerContext();
        public ActionResult Index(INV_Assets defModel)
        {
            return View(defModel);
        }

        [Authorize(Roles="IT Group")]
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        [Authorize(Roles="SomeDomain\\aguy")]
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}

我觉得奇怪的是,当我第一次登录时,我首先被强制注册?注册后我现在可以登录,但我不确定[Authorize] 属性是否真正生效。

例如,当我访问当前为Roles="IT Group"(以前使用Roles="Managers")设置的About() 页面时,由于我是 IT 组的一员,我没有出现在那里,而是要求我重新登录?

谁能提供一些关于我可能做错了什么的见解?

【问题讨论】:

    标签: c# asp.net asp.net-mvc authentication windows-authentication


    【解决方案1】:

    运行 Windows 身份验证的应用程序的默认行为是让您自动登录。但是,如果您尝试访问您的用户无权访问的站点的某些部分,它可以退回到实际的登录表单,让您有机会通过登录到另一个帐户而不是您的帐户来“升级”您的权限'在系统上重新运行。总而言之,如果您进入登录屏幕,那是因为您的用户帐户没有必要的权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多