【发布时间】:2019-12-12 05:44:22
【问题描述】:
我有一个 MVC 站点,我想检查打开此站点的用户名并根据用户名做出决定。无论如何,我编写了下面的代码并正确运行并正确显示用户名,但是当我在服务器端将 MVC 项目发布到 IIS 时,我无法获取用户名,我看到 IISAPPPOOL 或 NT AUTHORITYIUSR。我搜索了但我找不到任何东西。即使我在我网站的功能视图的身份验证部分中也找不到 Windows 身份验证(我在 Web 服务器下面的安全性下安装了 Windows 身份验证)
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
.
</configSections>
.
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
</system.webServer>
<connectionStrings>
.
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.web>
<customErrors mode="Off"/>
<authentication mode="Windows"/>
<identity impersonate="false" />
</system.web>
</configuration>
代码:
System.Security.Principal.WindowsIdentity context =
System.Security.Principal.WindowsIdentity.GetCurrent();
var domainName = context.Name; ---> show domain/username in local and IISAPPPOOLL after host on IIS
WindowsIdentity identity =
System.Web.HttpContext.Current.Request.LogonUserIdentity;
string domainName1= identity.Name;--> show NT AUTHORITYIUSR
或在其他代码中用于在本地显示域名中获取域名,但在 IIS 端显示 domain.local 的主机之后..
如何在 IIS 上的主机站点后获取域用户名?
【问题讨论】:
标签: asp.net-mvc authentication iis config