将Azure托管在服务器上的Windows身份验证添加到域中

时间:2019-01-08 05:55:27

标签: .net asp.net-mvc azure-active-directory azure-web-sites windows-authentication

我在MVC 5上具有表单身份验证的应用程序托管在Azure上的Windows Server(2012)上。还将此服务器添加到域中。

我的客户要求我使用Windows凭据而不是表单身份验证来对用户进行身份验证。

因此,我更改了用于身份验证的web.config条目,如下所示:

<system.web>
  <authentication mode="Windows"/>     
  <identity impersonate="true" />    
</system.web>

<system.webServer>
  <security>
    <authentication>               
        <windowsAuthentication enabled="true" useKernelMode="true">
            <providers>
                <clear />
                <add value="NTLM" />
                <add value="Negotiate" />
            </providers>
            <extendedProtection tokenChecking="Allow" />
        </windowsAuthentication>
        <anonymousAuthentication enabled="false" />

    </authentication>
  </security>
</system.webServer>

其余的IIS v-8.5)设置如下:

  • 应用池:经典版4.0版
  • .Net版本的代码:4.5
  • 已启用Windows身份验证
  • 已禁用匿名身份验证
  • 已禁用表单身份验证

仍然,我无法通过以下任何方式获取Windows用户电子邮件或用户名:

uname=User.Identity.Name;
uname=UserPrincipal.Current.EmailAddress;
uname= Environment.UserName;

我想念什么?

1 个答案:

答案 0 :(得分:0)

您可以使用@ HttpContext.Current.User.Identity.Name,因为您的配置设置为使用Windows身份验证。许多浏览器会透明地传递用户名。

有关其他解决方法,请参考this thread