用户名仍然存在 [英] username remains contants

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

问题描述

我正在尝试检索已登录用户的用户名,但是即使我使用其他帐户登录也应该给我一个不同的用户名,它仍继续为我提供一个用户的名字. /> 在我的网络配置文件中,我给了:

I''m trying to retrieve to username of the loged user, but it keeps on giving me the name of only one user even though if I log in with a different account which should give me a different username..
in my web config file I gave:

<authentication mode="Windows" />
                <!--<forms loginUrl="Login.aspx" protection="All" path="/" timeout="2880">
                                </forms>
             </authentication>-->
        <authorization>
            <deny users="?"/>
        </authorization>


      <identity impersonate="true"/>

        <membership defaultProvider="MyADMembershipProvider">
            <providers>
                <add name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider,         System.Web, Version=2.0.0.0, Culture=neutral,         PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnection" attributeMapUsername="sAMAccountName"/>
            </providers>
        </membership>
        <profile>
            <providers>
                <clear/>
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
            </providers>
        </profile>
        <roleManager enabled="false">
            <providers>
                <clear/>
                <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
                <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
            </providers>
        </roleManager>


我尝试使用以下方式,但没有任何效果.它再次给我相同的用户名:


I have tried to use the following ways below but nothing worked. It again give me the same username:

string username = System.Web.HttpContext.Current.User.Identity.Name;
System.Security.Principal.WindowsIdentity user = System.Security.Principal.WindowsIdentity.GetCurrent();

推荐答案

看看:^ ]才能使其正常工作.

尝试删除下面的内容
Have a look at: Credentials and Delegation[^] for a few things that must be in place for this to work.

Try removing the stuff below
<identity impersonate="true"/>




WindowsIdentity.GetCurrent();应该返回通过支持集成Windows身份验证的浏览器访问您的应用程序的用户-Firefox可能会引起一些麻烦,但是只要一切配置正确,Chrome和IE都可以正常工作.请记住,IIS服务用户必须是AD用户.

最好的问候
Espen Harlinn




WindowsIdentity.GetCurrent(); should return the user accessing your application through browsers supporting Integrated Windows Authentication - Firefox may cause some trouble, but Chrome and IE should work as long as everything is configured correctly. Remember that the IIS service user must be an AD user.

Best regards
Espen Harlinn


这篇关于用户名仍然存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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