无论我进行什么更改,我的 User.Identity.Name 都会返回 null。我正在使用 .net 7 和 IIS 7.
这是我的 webconfig 文件。 Windows 身份验证已启用,匿名身份验证已禁用。
`<configuration>
<location path = "." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name = "aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
<system.web>
<authentication mode = "Windows" />
< authorization >
< deny users="?"/>
</authorization>
</system.web>
</location>`your text`
</configuration>`
我在下面使用过,但它总是返回 null。
HttpContext.User.Identity.ToString().Split('\')[1] System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString().Split('\')[1]