The user account, more specificallly the SQL Server login, that logs on SQL Server depends on:
a.. The authentication type you are using to connect SQL Server.
b.. The authentication type you are using in your ASP.NET application.
c.. The use of impersonation in your ASP.NET application
The authentication type used to connect SQL Server is stablished in the connection string and can be either integrated (also called Windows or trusted) or standard (also called SQL Server).
a.. The connection string for integrated security includes the attribute "integrated security=SSPI" or "Trusted = Yes".
b.. The connection string for standard authentication includes the user and password "UserID = someuser; Password=The password"
If you are using standard authentication to connect SQL Server, the login used to log on SQL Server is the one specified in the connection string.
If your ASP.NET application is using Windows authentication and you are using integrated security to connect SQL Server:
a.. If you are not using impersonation on your ASP.NET application, then the actual login that logs on SQL Server is the windows account under which credentials ASP.NET is running.
b.. If you are using impersonation on your ASP.NET application, the actual login that logs on SQL Server is the windows user that uses the ASP.NET application. This user might be the anonimous user specified for anonimous access if you allow anonimous access to your ASP.NET application.
If your ASP.NET application is not using Windows authentication and you are using integrated security to connect SQL Server:
a.. The actual loging that logs on SQL Server is the windows account under which credentials ASP.NET is running.
You can obtain the user that logged on SQL Server by runing the following T-SQL statement:
SELECT SUSER_SNAME()
You can get the user that is using your ASP.NET application by means of the following:
HttpContext.Current.User
Regards from Madrid (Spain)
Jesús López
VB MVP
Solid Quality Learning
www.solidqualitylearning.com
Hi Jesús,
>The user account, more specificallly the SQL Server login, that logs on SQL Server depends on:
> a.. The authentication type you are using to connect SQL Server.
> b.. The authentication type you are using in your ASP.NET application.
> c.. The use of impersonation in your ASP.NET application
I'm using the user defined in the IIS virtual directory for anonymous
access, which is a Windows user on my IIS machine. Authentication in
ASP.NET is set to "Windows", and impersonation is set to true. My
connection string only contains a "Integrated Security=SSPI" statement
- no explicit user name is given.
And that user (defined on the virtual directory in IIS, and used to
log onto SQL Server) is the one I'd like to be able to find. It's
*NOT* the user running the app (e.g. running the browser which
connects to my web site) - it's the user defined on the virtual
directory for anonymous access.
>You can get the user that is using your ASP.NET application by means of the following:
>HttpContext.Current.User
This only returns an empty string, since I'm using anonymous access to
the web site..... yet, in the background, the page still uses a valid
Windows user to access the database.
Marc
Jesús López - 09 Jan 2006 07:08 GMT
Hi Mark,
Since you are using impersonation you can get the user by means of:
System.Security.Principal.WindowsIdentity.GetCurrent()
Regards from Madrid (Spain)
Jesús López
VB MVP
> Hi Jesús,
>
[quoted text clipped - 25 lines]
>
> Marc
Marc Scheuner [MVP ADSI] - 11 Jan 2006 06:12 GMT
Hi Jesús,
>Since you are using impersonation you can get the user by means of:
>System.Security.Principal.WindowsIdentity.GetCurrent()
Works like a charm - thanks a lot!
Marc