仍无法在后面的代码中记录Windows用户名 [英] Still unable to log windows user name in code behind

查看:45
本文介绍了仍无法在后面的代码中记录Windows用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的代码中包含了web.httpcontext引用。



然后我包括:var username = system.security.principal.windowsidentity.getcurrent( ).name.tostring();



当我运行页面时,它仍然返回NT作者rityNetwork服务。



我也尝试将我的用户名变量设置为user.identity.name并仍然得到相同的结果。



我已经验证我的IIS设置已启用。



加载页面时没有记录错误。



我的.aspx页面位于顶部:<%@ Page Title =Language =C#MasterPageFile =〜\ Site.Master AutoEventWireup =true代码隐藏=mypagename.aspx.cs%>



/ .aspx.cs背后的代码位于此顶部问题。



为什么我仍然得到NT AuthorityNetworkService而不是我的用户名???



如何解决这个问题???



我尝试过的事情:



我更新了解决方案的参考,添加了对类和代码的调用,验证了我的IIS设置。

I have included the web.httpcontext reference in my code behind.

I then include this: var username = system.security.principal.windowsidentity.getcurrent().name.tostring();

When I run the page, it still returns NT Author rityNetwork Service.

I also tried setting my username variable to user.identity.name and still get the same result.

I have verified my IIS settings are enabled.

There are no errors logged when I load my page.

My .aspx page has this at the top: <%@ Page Title ="" Language="C#" MasterPageFile="~\Site.Master" AutoEventWireup="true" code behind="mypagename.aspx.cs" %>

The code behind/.aspx.cs has the code at the top of this question.

Why am I still getting NT AuthorityNetworkService instead of my username???

How do I resolve this???

What I have tried:

I have updated solution's reference, added the call to the class and code behind, verified my IIS settings.

推荐答案

那是因为你没有在Request对象中获取身份。您将获得运行代码的用户的身份,默认情况下是NetworkService。



对于ASP.NET应用程序,如果我没记错的话,它会被找到在 HttpContext.Current.User.Identity.Name
That's because you're not getting the identity in the Request object. You're getting the identity of the user running the code which is, by default, NetworkService.

For an ASP.NET app, if I remember correctly, it's found in HttpContext.Current.User.Identity.Name.


这篇关于仍无法在后面的代码中记录Windows用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆