ASP.NET Core detecting Mac OS user - asp.net

I have created a .Net Core RC2 Web Application using VS2015 with windows authentication.
I then copied the project over to Mac OSX El Capitan and launched the app using the Terminal.
The application started as expected, however, as the application is running on my Mac there is no Windows user to display.
How can you return the Mac user and display the name?
This would also be useful for Linux users.

To get the username of a user visited the website
You may be thinking of the "Windows Authentication" feature of IIS. IIS does some magic to authenticate the user visiting the website against a Windows domain and then forwards that Windows auth token to ASP.NET Core. ASP.NET Core can only use this feature when hosted using IIS (or IIS Express) and using the IIS Integration middleware. See https://github.com/aspnet/IISIntegration. Because IIS is Windows only, this means it is not possible to get a client username when hosting the website on Linux or OSX.
To get the username of the account hosting the web server
As of .NET Core 1.0, there is no cross-platform API for getting a username directly. If you are on windows, System.Security.Principal.WindowsIdentity works, but this will throw PlatformNotSupported on Linux/macOS.
By convention, many systems set the username in an environment variable. You can use System.Environment to fetch this.
var username = Environment.GetEnvironmentVariable("USERNAME") ??
Environment.GetEnvironmentVariable("USER");
Another but more complicated approach is to p/invoke to native system calls that return information about the user, such as getpwuid_r (See the man pages for Linux and OSX.)

Related

Single Sign On with Identity Provider vs Integrated Windows Authentication with IIS

I'm working on on-premise web application (front end hosted on IIS) that currently uses traditional form-based authentication. Our client wants the application to support "single sign on", which basically means he wants the users to automatically log in to the application. AFAIK there are two ways I can take to achieve the desired effect:
Most articles that I found suggest using some kind of Identity Provider system (like Active Directory Federated Services), which my application can communicate with over SAML/OIDC in order to obtain user's claims.
On the other hand, I could set up IIS to use Integrated Windows Authentication and get user claims directly from Active Directory through Kerberos/NTLM. This approach seems easier.
Given that my application will not be used outside of intranet, it is hosted in environments using Microsoft products (Active Directory, Windows Server, users using Windows machines), is there any reason I should consider the first approach?

ASP.NET (macOS) - Send Windows Credentials in SQL Connection

I'm a contractor working remotely on a legacy ASP.NET application. I'm struggling to stand up a local instance of the project due to the error SQL Exception - SQL Server does not exist or access denied. I suspect this is because of the use of Windows Authentication for the SQL databases backing the project.
Before I launch into a lot more detail I'll ask my question: what are my options to pass Windows credentials to an SQL server in an ASP.NET project built on OSX?
I believe I've proven this is possible with some steps I'll detail below, but the actual implementation in an ASP.NET project is escaping me due to my inexperience with everything .NET, and the many-fold differences between my setup and the typical dev.
Standard Dev Setup
The devs I'm working alongside are using Windows machines housed in their corporate domain, running Visual Studio 2012. Because they're already logged into their machines with the appropriate credentials, the use of Integrated Security=SSPI in the SQL connection string "just works".
My Setup
I'm running a Mac Mini outside of their corporate domain, and using Visual Studio in conjunction with Mono to support the .NET Framework-based project. Passing the SSPI option won't work out of the box because I'm not connected to any Active Directory. That said, I do have valid credentials to log into their network.
What's worked so far
I've proven that a connection to their network resources is possible:
When logged into a virtual Windows machine, I can connect to a shared drive on that network with the credentials I was provided.
I then set up that same shared drive on my Mac Mini with those same credentials.
Using SQL Pro for MSSQL, I was able to connect to the desired database using my credentials.
As I understand it, what I'm looking for can be accomplished on Windows with Credential Manager, so bottom line I think I'm looking for the equivalent solution on OSX that plays nicely with ASP.NET project as compiled by Visual Studio.

.net core app somehow prompted for password when there are more users

I built .net core web application using windows authentication. It works nicely at the development or production environment with a few users. However when the app was installed and test on the production environment with more users(20 users) users are been kicked out and prompted for users all the time. I am not sure why this is happening. On IIS concurrent connection is set to 4294967295 as default the same setting for mssql is 32767. What else could be wrong. Is there any monitor tools or applications to find out what is the problem? IIS is 8 and windows2012 is for server.

Upgraded app to MVC 4, AUTH_USER is blank

I have a hybrid classic ASP + ASP.NET MVC 4 application running under Win Server 2k3 (IIS6) which we have upgraded to use MVC 4.
The ASP app is attached to the .NET application via a virtual directory. They run in the same application pool (if that matters). This particular app is an admin control panel, and uses basic authentication:
Before upgrading the project, when access the url for the virtual folder, the browser would display a login prompt, where I enter my domain-qualified username and password. The ASP code then retrieves the user name via Request.ServerVariables("AUTH_HEADER"), compares that against an application-level permissions list stored in the database, and enables or disables features in the admin site based on that.
After upgrading the project, I still get the login prompt, but Request.ServerVariables("AUTH_USER") returns an empty string.
I've added the old project into a new website so I can run them in parallel on the same server. The old code continues to work. The new code refuses to. The admin virtual directory in each version of the .NET application points to the same physical location on disk, and the authentication configuration for the folder in both .NET apps is identical.
Suggestions? Note that the MVC 4 app is using the .NET 4 framework, not .NET 4.5, which is not installed on the server.
Note that, although the default domain field in the screenshot is blank, it is properly configured. I've removed it from the image for obvious reasons.
Request.ServerVariables("AUTH_USER") can be obtained when you configured your application to use Forms authentication not Windows Authentication. If it is Windows Authentication you should use Request.ServerVariables("LOGON_USER")

Installing Windows Application on Client system through ASP.NET (Example: windows update from Microsoft Site)

I have a ASP.NET application. From that, User register, User will get email after registration.
My Req : When user click on link provided in email. Then it should go to my ASP.Net application page . That page should install a wincows application on Client system through web ( I was inspired by Microsoft Windows update from Microsoft site)
Please provide the best approach for this
Sounds like you should look at ClickOnce Deployment but this is for Windows based applications and if you have an ASP.Net application that will always run from a web server.

Resources