简体   繁体   English

asp.net Web应用程序返回IIS信息而不是当前用户凭据

[英]asp.net web app returning IIS info instead of current user credentials

I am working with an asp.net web application using custom authentication. 我正在使用自定义身份验证的asp.net Web应用程序。 I wrote a quick test app to put out on our web server to make sure I could grab the necessary credentials from the user. 我编写了一个快速测试应用程序以发布到我们的Web服务器上,以确保可以从用户那里获取必要的凭据。 I am trying to get the current logged in user (which I have done before) using the following line of code: 我正在尝试使用以下代码行获取当前登录的用户(之前已经完成):

   string username=System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

This normally returns a string in the format "domain\\user\u0026quot;. 这通常返回格式为“域\\用户”的字符串。 What I'm getting instead is something like this: IIS APPPOOL\\ASP.NET v4.0 相反,我得到的是这样的:IIS APPPOOL \\ ASP.NET v4.0

I'm sure I'm missing something simple, is there a setting in IIS that needs to change? 我确定我缺少一些简单的东西,IIS中是否有需要更改的设置? Or is there a different way to grab the username? 还是有其他方法来获取用户名?

尝试这个:

Page.User.Identity.Name

Since you are using custom/forms authentication, it sounds like you aren't setting the IPrinicipal details after the user is authenticated. 由于您使用的是自定义/表单身份验证,因此听起来好像您没有在对用户进行身份验证后设置IPrinicipal详细信息。

You can follow this documentation (find the "Creating the Forms Authentication Cookie section) on how to set this code up in your app. It isn't as difficult as it looks. 您可以按照本文档 (在“创建表单身份验证Cookie”部分中找到)来了解如何在您的应用中设置此代码。这并不像看起来那样困难。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM