简体   繁体   English

ASP.NET Web 表单应用程序 User.Identity.Name 在 IIS 中不起作用

[英]ASP.NET web form application User.Identity.Name not working in IIS

I am using ASP.NET web form application and trying to access User.Identity.Name in one of the page.我正在使用 ASP.NET Web 表单应用程序并尝试在其中一个页面中访问 User.Identity.Name。

However, it is working fine in VS but returns blank in IIS.但是,它在 VS 中运行良好,但在 IIS 中返回空白。

Most likely you are using the correct code within your application, but the configuration file is not set up for Windows Authentication.很可能您在应用程序中使用了正确的代码,但配置文件未针对 Windows 身份验证进行设置。

Make sure these portions are within your web.config file确保这些部分在您的 web.config 文件中

<configuration>
    <system.web>
    <authentication mode="Windows" />
        <authorization>
            <deny users="?"/>    <!-- Require everyone to log in -->
            <!-- add specific allow deny for users and roles here -->
        </authorization>
    </system.web>
</configuration>

Once these elements are in place, you can access the logged in user information一旦这些元素到位,您就可以访问登录的用户信息

// this will be in form Domain\Username
string UserIdentity = User.Identity.Name;

// or we can split and grab the second element
string[] DomainAndUser = User.Identity.Name.split('\\');
string UserDomain = DomainAndUser[0];
strung UserName = DomainAndUser[1];

MS: how to implement Windows Authentication MS:如何实现 Windows 身份验证

Scott Gu Blog at ASP.NET ASP.NET 上的 Scott Gu 博客

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 会话与User.Identity.Name进行比较,以使用Windows身份验证检查ASP.net核心应用程序的登录用户名 - Session vs User.Identity.Name to check the loggeduser name for ASP.net core application with windows authentication User.Identity.Name 是 null 在我的 ASP.NET 核心 Web ZDB974238714CA8A14A7CE1D0 - User.Identity.Name is null in my ASP.NET Core Web API ASP.NET控制器基类User.Identity.Name - ASP.NET Controller Base Class User.Identity.Name User.Identity.Name 在 ASP.NET Core MVC 应用程序中返回 null - User.Identity.Name returns null in ASP.NET Core MVC application 测试使用User.Identity.Name的Asp.Net控制器操作方法? - Test an Asp.Net Controller action method which uses User.Identity.Name? 如何在ASP.NET中使用User.Identity.Name作为SqlDataSource的参数? - How to use User.Identity.Name as a parameter for SqlDataSource in ASP.NET? 对于托管在 asp.net core 中的 Blazor Wasm,User.Identity.Name 为 null - User.Identity.Name is null for Blazor Wasm hosted in asp.net core User.Identity.Name 在 asp.net core + angular 客户端应用程序中为空 - User.Identity.Name is null in asp.net core + angular client app 将参数值传递给SqlDataSource ASP.NET User.Identity.Name - Pass parameter value to SqlDataSource ASP.NET User.Identity.Name 为什么运行 ASP.NET 6 项目时 `User.Identity.Name` `null`? - Why is `User.Identity.Name` `null` when running ASP.NET 6 project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM