ASP.NET Windows Authentication - Page cannot be displayed - c#

I have created a simple WebForm asp.net web site. I have disabled the Windows Authentication checks within the code but set IIS8 to "Windows Authentication" as well as the web.config. I perform the Indentity.IsAuthenticated check in the backend to ensure the user is authenticated.
My issue is I get "The page cannot be displayed, please check your URL is correct". (This is in IE)
If I set my authentication to Anonymous the site works fine. I disable Anonymous Authentication and enable Windows Authentication only and receive this error. I have done quite abit of reading now and think I am just missing something small.
I used the IIS "default site" and set it to Windows Authentication and got a login prompt (as expected).
The server is running IIS8, windows 2012. Windows Authentication is installed as a feature, IIS site settings is set to use Windows Authentication only, as is the web.config. The web.config doesn't have Authorization tags for deny and allow but has <authentication mode="Windows" />. The errors occur on both IE and FireFox. No windows events are logged so i assume it's purely a authentication error that isn't displaying the site. The AppPool is set to Identity.
I think what confuses me most is the "default site" (with no code or logic) works and my site doesn't. The default site also doesn't have a web.config.
Any ideas would be grateful.

The issue may have to do with Kereberos.
I had the same issue and whilst troubleshooting server side issues, my co worker indicated that he was able to access the site.
It was then I realized my issue was a client side issue. Something may have been wrong with my Kerberos tickets. Maybe the domain controller that initially issued the ticket to me went offline. Rebooting my workstation was what got windows authentication working for me again.
Some other things you can try are:
Try changing your windows authentication provider to NTLM as a test.
Click on the site -> Click Authentication -> Click Windows Authentication -> Click Providers
Move NTLM to the top or add it if it isn't there.
Click ok.
IISReset. And try again.
If you prefer to use Kerberos, you may have to set the service principal names using the setspn.exe command.
For more information on Kerberos
https://blogs.msdn.microsoft.com/chiranth/2014/04/17/setting-up-kerberos-authentication-for-a-website-in-iis/
Other things to check:
- Check your authorization rules and .NET Authorization Rules to ensure All Users are allowed to access the site.
Look in your IIS logs located at C:\inetpub\logs for more clues. In the folder, you'll find a folder for each site named after the site's id. You can find the site id clicking Sites on the IIS Management console. The site ids of each site will be displayed there.
Verify the application pool identity of the site has enough permissions.

Related

MVC 5 Authentication working in IIS Express but not in IIS

I have created an ASP .NET Web Application with MVC and Authentication as Individual User Accounts.
I have populated the app with some controllers, actions and views. Some of them are [AllowAnonymous] and other [Authorize].
It works perfectly in IIS express. I can create multiple accounts. And logging. And see the pages I have access to.
When I deployed the app to my local IIS, the authentication stopped working. I can create accounts. But I cant log in. When I try to log in it only redirects me toward the home page and I cant see the pages. When i try to put fake access it detects that they are incorrect.
I tried to fiddle around in the IIS settings but a don't know what to do.
Please, help me.
In IIS, for the site search for Authentication feature and enable windows authentication and disable Anonymous.
You need to keep your application to run anonymous authentication instead of windows authentication. Otherwise, you login page will get into infinite loop.
Besides,are you trying to connect a localdb with individual user account template in IIS?
Have you tried to set applciation pool like this in applicationhost.config and remove "AttachDbFilename=....." from your web.config connection string? If I take the steps above, I can get both register and create work in my IIS.
<add name="my app pool" autoStart="true">
<processModel identityType="ApplicationPoolIdentity" setProfileEnvironment="true" />
</add>

ASP.NET and IIS impersonate not working [duplicate]

I have a .NET 3.5 application running under IIS 7 on Windows 2003 server and cannot get integrated windows authentication working properly as I continue to get prompted for a login. I have set Windows Authentication to enabled in IIS with all other security types disabled and my application web.config file authentication/authorization is set up as:
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="3.5" />
<authenticationmode="Windows"/>
<authorization>
<deny users = "?" />
</authorization>
</system.web>
With this setup, I'm expecting behind the scene verification of the Windows user to allow access and deny anonymous users. However, what I'm getting is a Windows login pop-up when I try to access the site.
I have been troubleshooting this issue for a few days now and cannot figure out the problem. Based on posts with similar problems, I confirmed my URL does not include any periods, double checked that my IE settings are set to Enable Integrated Windows Authentication, and also added my URL to my intranet sites, but still getting the pop-up.
To troubleshoot it further, I enabled Anonymous Authentication in IIS and modified my web.config file to which lets me right in and then added Response.Write(System.Security.Principal.WindowsIdentifity.getcurrent().user.name.toString()) to try to see what user is being used in the authentication. The result I'm getting is IIS APPPOOL\myapp which is obviously the IIS application pool for my application.
I really appreciate any help anyone can provide so that I'm still using only windows authentication but don't get the pop-up and the windows authentication is performed against the actual Windows user.
Thanks.
Additional note after troubleshooting further:
Just noticed that when the login fails and the Windows login prompt displays again, it is showing the username that attempted to login as "SERVERNAME"\"USERNAME" which led me to believe it was trying to validate the user against the server vs. the domain. To confirm this, I created a local user account directly on the app server with the same username and password as the network domain user and tried to login again. The result was that I received the login prompt again but when I entered the username and password this time, I was able to successfully login. The network user and app server are on the same domain so really not sure why IIS authentication is pointing to the local app server accounts and not to the domain accounts. I realize this is an IIS question at this point so posting on forums.iis.net as well but appreciate any advice anyone may have since have been troubleshooting this for days.
I have a Windows 2008 server that I'm working on, so my answer is not completely the same as what the OP has on a Windows 2003 server.
Here is what I did (recording this here so I can find it later).
I was having this same issue:
In my Web.config file, I had this section:
<system.web>
<authentication mode="Windows" />
<authorization>
<allow users="*" />
<deny users="?" />
</authorization>
</system.web>
Under IIS, all of these seems to be solved under the Authentication icon.
Edit Permissions: Make sure your ASP.NET account has permission. Mine was not originally added.
Now go into the features of Authentication:
Enable Anonymous Authentication with the IUSR:
Enable Windows Authentication, then Right-Click to set the Providers.
NTLM needs to be FIRST!
Next, check that under Advanced Settings... the Extended Protection is Accept and Enable Kernel-mode authentication is CHECKED:
Once I did this, I went back to my web application, clicked the Browse link, and logged in without having to provide my credentials again.
I hope this proves beneficial to many of you, and I hope it is useful for me later as well.
Just for other people's benefit. If the error is a 401.1 Unauthorized and your error code matches 0xc000006d, then you're actually running into to a security "feature" that blocks requests to FQDN or custom host headers that don't match your local machine name:
Follow this support article to fix the issue:
https://webconnection.west-wind.com/docs/_4gi0ql5jb.htm (original, now defunct: http://support.microsoft.com/kb/896861)
From the support article, to ensure it doesn't get lost:
The work around is a registry hack that disables this policy
explicitly.
To perform this
configuration manually find this key in the registry on the server:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
and edit or add a new key:
DisableLoopbackCheck (DWORD)
then sent the value to 1 to disable the loopback check (local
authentication works), or to 0 (local authentication is not allowed).
Or more easily you can use Powershell:
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name
"DisableLoopbackCheck" -Value "1" -PropertyType dword
It looks like
recent builds of Windows 10 (1803 and later?) also require this
configuration setting in order to authenticate locally.
This one took me awhile because everyone else's comments here failed to help me. I found this article and it fixed it!
I had a similar issue whereby I wanted to protect only a certain part of my website. Everything worked well except in IE. I have both Anonymous and Windows Authentication enabled.
For Anonymous, the Identity is set to the Application Pool identity. The problem was with the Windows Authentication. After some digging around I fired up fiddler and found that it was using Kerberos as the provider (actually it is set to Negotiate by default). I switched it to NTLM and that fixed it.
HTH
Daudi
Add permission [Domain Users] to your web security.
Right click on your site in IIS under the Sites folder
Click Edit Permissions...
Select the Security tab
Under the Group or usernames section click the Edit... button
In the Permissions pop up, under the Group or user names click Add...
Enter [Domain Users] in the object names to select text area and click OK to apply the change
Click OK to close the Permissions pop up
Click OK to close the Properties pop up and apply your new settings
If your URL has dots in the domain name, IE will treat it like it's an internet address and not local. You have at least two options:
Get an alias to use in the URL to replace server.domain. For example, myapp.
Follow the steps below on your computer.
Go to the site and cancel the login dialog. Let this happen:
In IE’s settings:
Don't create mistakes on your server by changing everything. If you have windows prompt to logon when using Windows Authentication on 2008 R2, just go to Providers and move UP NTLM for each your application.
When Negotiate is first one in the list, Windows Authentication can stop to work property for specific application on 2008 R2 and you can be prompted to enter username and password than never work. That sometime happens when you made an update of your application. Just be sure than NTLM is first on the list and you will never see this problem again.
This fixed it for me.
My Server and Client Pc is Windows 7 and are in same domain
in iis7.5-enable the windows authentication for your Intranet(disable all other authentication.. also No need mention windows authentication in web.config file
then go to the Client PC .. IE8 or 9- Tools-internet Options-Security-Local Intranet-Sites-advanced-Add your site(take off the "require server verfi..." ticketmark..no need
IE8 or 9- Tools-internet Options-Security-Local Intranet-Custom level-userauthentication-logon-select automatic logon with current username and password
save this settings..you are done.. No more prompting for username and password.
Make sure , since your client pc is part of domain, you have to have a GPO for this settings,.. orelse this setting will revert back when user login into windows next time
WindowsIdentity.GetCurrent is correct: you should get the APPPOOL user. This is because the ASP.NET process, which is executing your code, is the current identity. If you want it to return the user hitting the site's identity, you'll need to add the following line in your web.config:
<identity impersonate="true" />
This causes the process to assume the identity of the user requesting the page. All actions will be performed on their behalf, so any attempts to read folders on the network or access database resources and the like will mean the current user will need permissions to those things. You can read more about impersonation here. Note that depending on how your web/database server topology is set up, you may run into delegation issues with impersonation turned on.
But your original issue is that it appears the identity cannot be determined and you're getting a login popup. I'll note that you do not need the <deny> block if you have disabled anonymous authentication in IIS. We never include it (except in special <location> blocks and such) so I would say you might try removing it and trying again. Everything else sounds right, though.
You didn't specify what user is running the application pool in IIS. Is it a custom account or is it the default one? If it is custom, is it a domain account or a local account on the web server? Custom accounts can sometimes require a few more steps, such as registering a SPN. Also, it may be a problem with the custom account not having permission in AD for resolving the incoming user's account.
You might also check the IIS logs to see what response is being returned. It'll most likely be a 401, but it should have a sub number after it like 401.2 or something. That sub-number can sometimes help determine the root problem. This KB article lists five.
Can be browser related. If you are using IE, you can go to Advanced Settings and check you the "Enable Windows Integrated Authentication" checkbox is checked.
In my case the authorization settings were not set up properly.
I had to
open the .NET Authorization Rules in IIS Manager
and remove the Deny Rule
In our Intranet the issue was solved on the client side by tweaking settings in security as shown here. Either of the check boxes on the right worked for us.
I just solved a similar problem with an ASP.Net application.
Symptoms:
I could log in to my app using a local user, but not a domain user, even if the machine was correctly joined to the domain (as you say in your Additional Note). In the Security event viewer, there was an event with ID=4625 "Domain sid inconsistent".
Solution:
I found the solution here. The problem was that my test machines where cloned virtual machines (Windows Server 2008 R2; one Domain Controller, and one web server). Both had the same machine SID, which apparently caused problems. Here is what I did:
Remove the web server from the domain.
Run c:\Windows\System32\Sysprep\Sysprep.exe in the VM.
Reboot the VM.
Join the web server to the domain.
You loose some settings in the process (user preferences, static IP, recreate the self-signed certificate), but now that I have recreated them, everything is working correctly.
I also had the same issue. Tried most of the things found on this and other forums.
Finally was successful after doing a little own RnD.
I went into IIS Settings and then into my website permission options added my Organizations Domain User Group.
Now as all my domain user have been granted the access to that website i did not encounter that issue.
Hope this helps
I tried the above IIS configuration tricks and loopback registry hack, and I reviewed and recreated app pool permissions and a dozen other things and still wasn't able to get rid of the authentication loop running on my development workstation with IIS Express or IIS 7.5, from a local or remote browsing session. I received four 401.2 status responses and a blank page. The exact same site deployed to my IIS 8.5 staging server works flawlessly.
Finally I noticed markup in the Response Body that was rendered blank by the browser contained the default page for a successful log in. I determined that Custom Error handling for ASP.NET and HTTP for the 401 error was preventing/interfering with Windows Authentication my workstation but not the staging server. I spent several hours fiddling with this, but as soon as I removed custom handling for just the 401 error, the workstation was back to normal. I present this as yet one another way to shoot your own foot.
I was having this issue on .net core 2 and after going through most suggestions from here it seems that we missed a setting on web.config
<aspNetCore processPath="dotnet" arguments=".\app.dll" forwardWindowsAuthToken="false" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
The correct setting was forwardWindowsAuthToken="true" that seems obvious now but when there are so many situations for same problem it's harder to pinpoint
Edit: i also found helpful the following Msdn article that goes through troubleshooting the issue.
Have you tried logging in with your domain prefix, e.g. DOMAIN\Username? IIS 6 defaults to using the host computer as the default domain so specifying the domain at logon may solve the problem.
add to registry
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa solved my problem.
Create the Local Security Authority host names that can be referenced in a NTLM authentication request.
To do this, follow these steps for all the nodes on the client computer:
Click Start, click Run, type regedit, and then click OK.
Locate and then click the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
Right-click MSV1_0, point to New, and then click Multi-String Value.
In the Name column, type BackConnectionHostNames, and then press
ENTER.
Right-click BackConnectionHostNames, and then click Modify.
In the Value data box, type the CNAME or the DNS alias, that is used
for the local shares on the computer, and then click OK.
Note
Type each host name on a separate line. If the
BackConnectionHostNames registry entry exists as a REG_DWORD type,
you have to delete the BackConnectionHostNames registry entry. Exit
Registry Editor, and then restart the computer.
Source: Error message when you try to access a server locally by using its FQDN or its CNAME alias after you install Windows Server 2003 Service Pack 1: Access denied or No network provider accepted the given network path
For what it's worth, I did not need to restart after making the change on Windows Server 2019.
Windows authentication in IIS7.0 or IIS7.5 does not work with kerberos (provider=Negotiate)
when the application pool identity is ApplicationPoolIdentity
One has to use Network Service or another build-in account.
Another possibility is to use NTLM to get Windows Authenticatio to work (in Windows Authentication, Providers, put NTLM on top or remove negotiate)
chris van de vijver
I had the same problem cause the user (Identity) that I used in the application pool was not belowing to IIS_IUSRS group. Added the user to the group and everything work
In my case the solution was (on top of adjustments suggested above) to restart my/users' local development computer / IIS (hosting server).
My user has just been added to the newly created AD security group - and policy didn't apply to user AD account until I logged out/restarted my computer.
Hope this will help someone.
I encountered the same credential prompting issue, and did a quick search and nothing on the internet would fix it. It took some time to find the problem, a silly one.
In IIS -> Advance Setting -> Physical Path Credential (is empty)
As soon as i added a machine ID (domain/user) that has access to the VM/server, the password prompting would stop.
Hope this helps
I got the same issue and it was resolved by changing the Application pool identity of the application pool under which the web application is running to NetworkService

ASP.NET MVC Windows Authentication is displaying login prompt instead of logging me in

Based on this article I've created a basic ASP.NET MVC site using the Visual Studio 2013 Intranet Site template with the default settings and changing nothing.
When running the site in debug mode instead of logging me in and displaying my domain\username, I am getting prompted to enter my username/password in a Authentication Required dialog.
I was under the impression, since I am already authenticated against the domain, I should be logged straight into the application using my AD account without having to enter in anything. When I do try explicitly entering my AD name or a local user account, nothing is accepted.
EDIT
If I type in my username/password with Firefox I am authenticated, but not with Chrome and IE.
Any ideas?
What you're encountering is something that's frustrated me about windows authentication for a long time. Internet explorer has a feature called pass-through authentication that authenticates you automatically when using windows auth. Other browsers have work arounds: https://addons.mozilla.org/en-US/firefox/addon/integrated-auth-for-firefox/ .
It's up to the sys admins to implement those measures for the other browsers, but nobody ever does, so we get stuck typing in our full usernames and passwords in every browser but IE.
What you can do is follow this approach : http://blogs.msdn.com/b/chunliu/archive/2010/09/21/creating-a-custom-login-page-for-windows-authentication.aspx
Not nearly as simple as enabling windows auth, or even implementing forms auth for that matter, but consider a scenario where you want infrastructure to manage permissions and administer user accounts, or if you want to expose your login page globally without exposing AD.
IE won't pass credentials to a site unless it's in the intranet security zone or the same domain. You can add your site to IE's list of trusted sites using
Internet Options > Security > Trusted sites > Sites
Chrome takes its trusted site settings from IE's settings, so once you add to IE, it should also work in Chrome
Check with your IIS (Internet Information Server) Manager and see if your application has the right permissions for the user.
Go to the "Connections" panel on the left-hand side
Under "Sites", navigate to your application or folder holding the application
Right click and select "Edit Permissions..."
Go to the "Security" tab
Check if your Windows ID or Windows Group (if multiple users) have the correct permissions to this site under the "Group or user names" box
If the user or group is not there, click on the "Edit" button and then click the "Add" button
Also check if "Windows Authentication" is enabled and both "Anonymous Authentication" and "ASP.NET Impersonation" are disabled for the application on the IIS.

windows and anonymous authentication on IIS 7.5, allow auto login for internal and manual login for external

Scenario:
https asp/asp.net website running of IIS 7.5 (windows server 2008)
IIS currently configured to allow anonymous authentication and forms authentication ,asp.net impersonation are disabled while windows authentication is not installed (I understand that windows authentication needs to installed for this.)
a single custom login page for both internal and external users
Requirment:
Internal users seamlessly login while capturing their LOGON name (window authentication)
External users (not on domain) should be prompted a manual login
Questions:
What approach can be used to implement this?
Looking for the IIS 7.5 and web.config settings
Approaches Found:
make 2 pages within 1 website, winlogin and weblogin(front page). Allow windows auth=true and anonymous auth=false on winlogin.aspx and vice versa on weblogin.aspx
user with a ip hits weblogin, if ip is known redirect to winlogin to capture logon and redirect to weblogin if the ip is unknown
have winlogin.aspx as the main page and redirect 401 errors to weblogin.aspx
This is how to configure IIS for integrated authentication.
http://netpl.blogspot.com/2012/06/iis-75-integrated-security-with-no.html
This will make your site available for intranet users WITHOUT the prompt for credentials.
Note that this also works for web users. A built-in web browser window is displayed as a result of HTTP 401. A user provides his/her credentials and is in.
If you rather want to show your custom web form as a result of 401 (unauthorized), you'd have to trick the browser a little:
http://www.codeproject.com/Articles/11202/Redirecting-to-custom-401-page-when-quot-Access-de
This way you can redirect an unauthorized response to a web form of your choice (for example, to show an asp.net login form).
Although the integrated authentication can be easily configured, prepare for a lot of experiments when setting up your mixed (integrated/forms) authentication. Things change with every version of IIS; also IIS7 behaves differently if a pool is in classic vs integrated mode.

HttpContext.User.Identity.Name in a deployed application

For an ASP.NET MVC 2 application, we are using HttpContext.User.Identity.Name to get the user name for authentication purposes. This works fine when testing. Users who are in the database are able to access areas for which they have permissons, and redirected to a 401 page otherwise. The 401 page displays their username, explaining that this user is not authorized to access this content.
However, in a deployed environment, all attempts to access any portion of the application redirect to the 401 page, and the displayed username is blank!
How can we enable the deployed application to access the username of the request?
From my research, I should go to the following screen and enable Windows Authentication, but it's not in the list!
We had an issue like this to, what we ended up doing was turning off Anonymous Access in IIS. Remember to check the Integrated box at the bottom.. Hope this helps
Ah, if you are using IIS 7, you probably need to install it first! Here's a good overview. FTA:
The default installation of IIS 7 does not include the Windows
authentication role service. To use Windows authentication on IIS, you
must install the role service, disable Anonymous authentication for
your Web site or application, and then enable Windows authentication
for the site or application.
If you're not seeing it as an option, you probably don't have it installed.
(Dictated from my Winodws 7 machine,) Go to your Start menu and type: Turn Windows features on or off.
Next, in the dialog's treeview, go to Internet Information Services - World Wide Web Services - Security and then check the Windows Authentication checkbox.

Categories

Resources