代码之家  ›  专栏  ›  技术社区  ›  dance2die

如何从通过网站调用的存储过程中获取网站用户的Windows登录名

  •  0
  • dance2die  · 技术社区  · 16 年前

    我有一个网页在一个名为, WebUser (IIS在此帐户下运行)

    现在的问题是,当用户(内部网)访问网页时,
    用户通过身份验证 Windows身份验证 .

    网页调用存储过程, SaveClientInfo . 当我试图获取用户名时(比如, 用户1 )是谁打来的 保存信息 ,请
    我得到 韦布斯 而不是 用户1 通过 SYSTEM_USER

    有办法吗 用户1 从 保存信息 不必将用户名传递给存储过程吗?

    这是相关的存储过程定义

    create procedure SaveClientInfo
        @ClientID int
        ... --; other parameters
    as
    begin
        declare @UserName sysname
        --; returns the name of user name that IIS runs under
        --; But I would like to log the name of the person 
        --; who is accesing the site through Windows Authentication
        select  @UserName = SYSTEM_USER 
    
        --; Save client data and the person who saved the info
        ...
    end
    GO
    
    2 回复  |  直到 16 年前
        1
  •  1
  •   Callie J    16 年前

    除非在Web应用程序中使用模拟,以便Web应用程序作为Windows身份验证用户进行连接,否则不能。

        2
  •  0
  •   3Dave    16 年前

    从SQL中检索用户的名称应该只提供与连接关联的用户名——通常是ASP.NET使用的用户帐户。

    在.NET方面,您可以使用(c)

    string s = Environment.User.Identity.Name
    

    以检索登录到您的站点的用户的名称。我们使用这个来跟踪谁通过我们的管理站点对数据库进行了更改,以及其他更改。