I created an out-of-the-box ASP.NET 5 application with Windows Authentication as a test. If I hit F5 and launch it in Edge, I get presented with a login prompt. If I browse to an application on an internal web server that requires Windows Authentication, it works fine.
Is there something specific I need to do in order to be able to debug web application with Windows Authentication from localhost?
EDIT: The same application works fine in IE11 and other browsers. This is Edge 25.10586.0.0.
Related
I have implemented Microsoft authentication using IIS Express and everything worked as expected (like the one from https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/microsoft-logins?view=aspnetcore-5.0).
However after I publish it to IIS, when a user tries to access the application, instead of the Microsoft login page, I get a page with the message
No webpage was found for the web address: <redirecturl>?code=...
I should mention that there is no other way to login. Only the Microsoft one has to be supported.
After further investigation I found out from where the problem was.
The server was protected and the IIS did not have access to the internet and a proxy was required. Hence the reason on IIS Express was working on the development machine but on the server IIS did not.
I have two application, both running on the same Windows machine. One application is IdentityServer4, and the other is my own web application (Server side Blazor app).
Both web apps are build with .NET Core 3.1.
When I navigate to my web app, I first get redirected to my IdentityServer4 app. I login, and after that I get redirected back to my web app.
The login was successful, because there are no errors in the logs of IdentitServer. Also, I see a certain claim value on my Blazor webpage. I display this claim through CascadingAuthenticationState in my Blazor page. Through that path everything works fine.
But, whenever I try to get the logged in user through HttpContext in my "code behind" files, I get a Null reference back. For example:
public UserService(IHttpContextAccessor httpContextAccessor)
{
// HttpClient is NULL...
var httpCtx = _httpContextAccessor.HttpClient;
}
The strange thing is, that it all works fine when I run my application locally in Visual Studio. When I debug in Visual Studio I see that the HttpContext is set with all my user data.
But, for some reason HttpContext is NULL when I run the app from IIS.
How can I solve this issue?
If the HttpContext null-reference exception happens after deployment to Azure App Services or IIS, you might have forgotten to enable WebSockets.
Here is the deal:
If the app runs on Windows with IIS: WebSockets must be enabled.
See the IIS/IIS Express support section.
It seems that this is a prerequisite that you have to follow. I only recently discovered this myself after dealing with the same issue and deciding to publish my app to Azure from within Visual Studio. After I did so, Visual Studio gave me a nice warning telling me to enable WebSockets protocol on the Azure App Service.
To enable websockets in azure app service. Open app service in azure portal -> configuration -> general settings -> websockets on or off. Described here
We have an intranet site web app. It's angularjs on the front end and asp.net web api on the backend. Because it started out as internal it uses windows authentication. Now we want to create a true mobile web app and be able to call these web api's from outside our network.
Since it's outside I'm assuming windows authentication no longer works?
Is there a way to mimic this windows authentication from the client so the api's still work or is there something else that needs to be done on the web api to make them work both internally and externally? Any direction would be great!
I just installed the Windows app version of Postman. Previously I have been using the Chrome plugin. It seems the Windows version is not passing through my Windows credentials to my ASP.Net Web API application. I get 401.2 errors.
The same exact call works fine from the Chrome plugin.
Is there a configuration I am missing perhaps?
Thank you
Karl
I remember, that I used to get Logged In user ID(for Intranet Application) using the following code:-
string WindowsLoginID= System.Web.HttpContext.Current.Request.ServerVariables["AUTH_USER"];// This is blank
It still works fine when I use it in code behind of ASP application.
But when I am using the same code in MVC4 Application it is returning me blank.
I am running my project as Use Local IIS Web Server and my web.config I have-
<authentication mode="Windows">
</authentication>
Please let me know, If I am doing some thing silly.
I was missing some configuration, I created a New MVC Intranet Application and did the setting changes as follows:-
Hosting on IIS Express:
Click on your project in the Solution Explorer to select the project.
If the Properties pane is not open, open it (F4).
In the Properties pane for your project:
a) Set "Anonymous Authentication" to "Disabled".
b) Set "Windows Authentication" to "Enabled".
Hosting on IIS 7 or later:
Open IIS Manager and navigate to your website.
In Features View, double-click Authentication.
On the Authentication page, select Windows authentication. If Windows
authentication is not an option, you'll need to make sure Windows authentication
is installed on the server.
To enable Windows authentication on Windows:
a) In Control Panel open "Programs and Features".
b) Select "Turn Windows features on or off".
c) Navigate to Internet Information Services > World Wide Web Services > Security
and make sure the Windows authentication node is checked.
To enable Windows authentication on Windows Server:
a) In Server Manager, select Web Server (IIS) and click Add Role Services.
b) Navigate to Web Server > Security
and make sure the Windows authentication node is checked.
In the Actions pane, click Enable to use Windows authentication.
On the Authentication page, select Anonymous authentication.
In the Actions pane, click Disable to disable anonymous authentication.
Source:- readme.txt of MVC Intranet Application
In the Properties pane for your project:
a) Set "Anonymous Authentication" to "Disabled".
b) Set "Windows Authentication" to "Enabled".
Hope it helps!