我怎样才能找回登录的用户在ASP.NET Web应用程序? [英] How can I retrieve Logged In user in an ASP.NET web application?

查看:137
本文介绍了我怎样才能找回登录的用户在ASP.NET Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Windows身份验证在ASP.Net Web应用程序,并在code-身后试图检索登录的用户名。我使用这个程序WindowsIdentity.GetCurrent()名称而是获得了用户的名称,我得到 - NT AUTHORITY \\ NETWORK SERVICE。我需要做什么改变或者是我的用户比预期不同的方式记录?

I am using windows authentication in a ASP.Net Web Application and in the code-behind attempting to retrieve the logged in user name. I am using this routine WindowsIdentity.GetCurrent().Name but instead of getting the name of the user, I am getting - NT AUTHORITY\NETWORK SERVICE. What do I need to change or are my users logging in a different way than expected?

推荐答案

以下内容添加到你的web.config:

Add the following to your web.config:

<system.web>
    <identity impersonate="true"/>
</system.web>

这会使你的web应用程序冒充当前登录的用户。这确实有一定的影响。一个重要的是,在登录的用户必须有文件,文件夹,数据库的正当权益等。

This will make your web app impersonate the currently logged in user. That does have some implications. An important one is that the logged in user must have the proper rights to files, folders, databases and so on.

如果你不希望出现这种情况,你可以使用 User.Identity 而不是 WindowsIdentity.GetCurrent()

If you don't want that, you can use User.Identity instead of WindowsIdentity.GetCurrent().

这篇关于我怎样才能找回登录的用户在ASP.NET Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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