I am developing an internal web app using Blazor (WebAssembly) and SQL Server Express 15. The web app will only be accessed while within our network.
As I am extremely early in development, I currently host the Blazor app and the SQL server on my workstation; eventually the app and SQL server will reside on a more traditional server inside our firewall.
I'm using the default Windows Authentication for SQL Server. What I'd like to do is, via Blazor, access the Windows userid of whoever is interacting with the SQL server by virtue of accessing the web app. I could then use that information to (for example) show that user their weekly timesheet when they go to My Timesheet within the web app.
Is there a way to access the Windows userid that authenticated into SQL Server? Or am I misunderstanding things / off-base is some fashion? Or is there another way to get the Windows userid without interacting with SQL Server?
What I've Tried
I've tried System.Environment.UserName, but that returns "Browser". I've also tried System.Environment.UserDomainName, but that returns "localhost". I've also tried System.Security.Principal.WindowsIdentity.GetCurrent().Name and code based on ManagementObjectSearcher, but both throw an exception under WebAssembly, as WebAssembly is not Windows (even when running on a Windows server and/or a Windows browser-client).
From the other suggestions in this question, I was unable to find the right using statements or other syntax in Blazor for
- Request.LogonUserIdentity.Name,
- System.DirectoryServices.AccountManagement.UserPrincipal.Current.DisplayName,
- User.Identity.Name,
- System.Windows.Forms.SystemInformation.UserName, and
- HttpContext.Current.User.Identity.Name.