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

发布于 2024-08-08 18:06:23 字数 963 浏览 2 评论 0原文

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

现在的问题是,当用户(内联网)访问该网页时,
用户通过 Windows 身份验证进行身份验证。

该网页调用存储过程SaveClientInfo。 当我尝试获取调用 SaveClientInfo 的用户名(例如 User1)时,
我通过 SYSTEM_USER

有没有办法从SaveClientInfo获取User1而无需传入用户名到存储过程?

这是存储过程定义的相关部分

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

I have a web page that runs under an account named, WebUser (IIS runs under this account)

Now the problem here is that, when the webpage is accessed by users (intranet),
users are authenticated through Windows Authentication.

The webpage calls a stored procedure, SaveClientInfo.
When I was trying to get the user's name (say, User1) who was calling SaveClientInfo,
I was getting WebUser instead of User1 through SYSTEM_USER

Is there a way to get User1 from SaveClientInfo without having to pass in the user name to the stored procedure?

Here is the relevant piece of sproc definition

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

待天淡蓝洁白时 2024-08-15 18:06:23

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

Unless you use impersonation in your web app, so the web application connects as the Windows authenticated user, no you can't.

熟人话多 2024-08-15 18:06:23

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

在 .NET 端,您可以使用 (C#)

string s = Environment.User.Identity.Name

检索登录到您站点的用户的名称。我们用它来跟踪谁通过我们的管理站点对数据库进行了更改,等等。

Retrieving the name of the user from the SQL should just give you the username associated with the connection - typically, the user account used by ASP.NET.

On the .NET side, You can use (C#)

string s = Environment.User.Identity.Name

to retrieve the name of the user logged into your site. We use this to track who's making changes to the db through our admin site, among other thngs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文