Asp.net MVC and IIS 7 Remove Basic Authentication in web.config - asp.net-mvc

I published a site with a web hosting company and when someone hits the URL for the first time they are being prompted to log in using basic authentication. If you hit Cancel the site loads successfully and the user is not prompted again with the dialog box.
I contacted support and they are telling me (in a canned response) that it’s a programming issue. Is there something in the web.config that I need to either add or remove to stop basic authentication from happening on the first request?
Site is built with asp.net mvc 2, .net 4, and IIS 7. Thanks in advance for your help!
UPdate: I am using Forms based authentication on the site which is working once you click cancel on the Basic Authenciation dialog window.

Figured out the answer my question. I had to connect to the web site using IIS Manager and then disable Basic Authentication and enable anonymous.

Look for the authentication mode tag in the web.config (system.web node). Set the mode to "None".
So it will look something like this:
<authentication mode="None" />

Related

Google Auth does not work in template asp.net mvc project

So I have VS 2013 update 4 and I created ASP.NET MVC application from template and configured Google authentication by using UseGoogleAuthentication method and passing client ID and secret. But for some reason once I click 'Accept' button google page I'm redirected to the page I expect but there is an error 500 in the browser console and nothing on the page itself.
I read a lot of articles and enabled all required APIs in Google Developer console. But nothing seems to work for me.
Also I have another custom authentication middleware that worked just fine before and stopped working once I enabled Google. I use nuget package version 3.0.1.
If I disable my custom auth middleware Google still does not work.
Please advise.
OK, here's why should probably stay with default values. So default redirect URL is /signin-google built-in to Google middleware. And because my URL is /Account/ExternalLoginCallback I thought it was a good idea to set it when configuring GoogleOAuth2AuthenticationOptions.
Once removed CallbackPath = new PathString("Account/ExternalLoginCallback") from configuration it just worked.

MVC5 App redirects to login.aspx when calling secured actions

i have created a new ASP.NET MVC 5.1 Web App with VS 2013. In my local IIS Express all is working fine. One controller is decorated with an Authorize-Attribute. When i open a secured action in this controller without logging in before this, i was correctly redirected to the login page (/Account/Login). But in my productive IIS 7 (Windows Server 2008) the server redirects my to login.aspx.
Could this occure while i use OWIN Middleware and the old IIS 7.0 can#t work with it? In the bin dir there are all the OWIN-dlls from my project.
There are alos problem with the rediretion process while i use an external login provider like Google. Same procedure like above. :-(
Does anybody have some hints for me?
Thanks.
Andreas
I have the same setup and same problem too: instead of redirecting to /account/login or whatever login path you set up in CookieAuthenticationOptions, it always redirects to /login.aspx.
One workaround is, after you publish EVERY SINGLE TIME, you need to go in IIS, select the project, hit Authentication and disable the default Form Authentication.
If you select the form authentication and hit edit, you will see /login.aspx default route is there.
By the way, adding these 2 AppSettings won't fix it:
<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>
Simple solution : Go to IIS -> select your project -> Double tap on authentication
-> select forms authentication -> edit and set your default login redirect url .
This is where the login.aspx is hardcoded . This is configurable and changed based on project routes.

ASP.NET MVC intranet app with windows authentication, how to get the current domain user automatically?

I need my MVC4 app to get the current domain user that is logged on to the machine automatically logged in in my index.cshtml page.
the rest of the application works as intended by using the Authorize attribute the actions i need secured.
I just need to say to the app "get the current machine logged in user , dont secure anything and take the user to the landing page".
web.config:
<authentication mode="Windows" />
like this the user is BLANK on the landing page.
If i try to put just [Authorize] on my index action then it asks for credentials and then continues as i want, without securing anything on the landing page.
Is there any way around this?
UPDATE:
No matter what you do , it seems that there is no way to bypass the login prompt and make the application automatically get the current domain user and log him in the app.
Check this from MSDN
add impersonate="true" along with it
<identity impersonate="true"/>
<authentication mode="Windows" />
Then use
((HttpContext)context).User.Identity as WindowsIdentity
Use Windows Authentication and for ASP.NET and IIS and specify the ASP.NET URL Authorization in the web.config as shown in this answer. Whenever the current user is authorised, the user will be silently logged in.
Tested using IE 11, IIS 8.5, Windows Server 2012 R2.
i just finished fighting with this problem. i should preface that this is with iis 7 running on win 2k8r2. the fix for me was to go to authentication menu in iis -> select windows authentication -> click providers in the right pane -> adjust so that only ntlm is in the list of available providers. negotiate seems to be the culprit for forcing the log-in prompt.
You may also try adding the following to your <appSettings>:
<add key="enableSimpleMembership" value="false" />

MVC 3 Windows Authentication for site except Area with Forms Authentication

I have an intranet application using windows authentication that works great. Now I have a requirement to expose an Api area. This area should use basic authentication but to keep things easy I am first just trying to make this area allowed to anonymous.
I am using IIS 7.5 and it is configured like this:
IIS > My Intranet Site > Authentication > Windows Authentication Enabled,
everything else Disabled
in the application root web.config I have
<authentication mode="Windows"></authentication>
All the intranet controllers (except for Api Area) inherit from a BaseController that have an AuthorizeAttribute
I tried adding
<location path="~/Api">
<system.web>
<authentication mode="None" />
</system.web>
</location>
In the web.config for the API area, but no go, still get prompted for credentials.
My application structure looks like this
-IntranetApp
--Controllers
--Areas
----Area1
----Area2
----Api
All should be using Windows Authentication except for Api area.
Thanks for any help/pointers.
I don't know details, but the way I've seen "mixed" authentication done is two web applications. The one with windows authentication enabled will then use the ASP membership API to authenticate the user(and automatically create a username if necessary using information from domain account) and then redirect to the other site. Both site's membership config share the same application ID, keys, etc.
You are probably running into this:
"you cannot achieve this within a single application because in IIS once you set up Windows authentication for a virtual directory it will no longer accept users from different domains."
See this for more information on setting up one version of this:
ASP.NET MVC and mixed mode authentication

User.Identity.Name blank in ASP.Net MVC

Exactly as per the title.
Simply in my HomeController I have:
string Username = User.Identity.Name;
Why is this value always blank?
Is there something special I have to place in the web.config to get this value to come through. I've tried on both the VS dev web server as well as on a windows server 2003 IIS server.
It's got to be something simple, a server setting in IIS or something as the code is so simple and seems to be the correct way to reference this value.
Thx a lot
If you are wanting to use windows authentication it's not enough to just add
...
<system.web>
...
<authentication mode="Windows"/>
...
</system.web>
...
You also want to check the readme file instructions for the MVC project, especially if your running in IIS Express and using Visual Studio 2012.
See below:
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.
Sure is mate. You need to authenticate with the website. That's the name used for authentication.
You are authenticating, right?
It's not a setting, etc.
Click the LOG IN link, if you're using the stock standard ASP.NET MVC template (if my memory serves me right).
UPDATE (as the posted has added more info/comments)
So what you're after is Windows Authentication. A quick google search came up with this post. It's pretty helpful (though a bit old, but still relevant) .. check that out.
Found a better post with MVC code for Windows Authentication. Check that out instead.
Config setting that is important, is...
...
<system.web>
...
<authentication mode="Windows"/>
...
</system.web>
...
If you do not wish to Authorize on every controller or action, you can do a blanket authorization in the web.config file. This should work as long as you are using Windows authentication. If you allow ASP.NET to control the authentication, then you would not need to configure any IIS setting. It should then work well with whatever web server that you are running on. I do not know or assume what u have tried so far I'll try to be complete in my answer. First remark off the forms authentication tag in web.config. All following settings are placed in the system.web configuration section.
<!--
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
-->
Replace with the Windows authentication tag.
<authentication mode="Windows" />
Then add the authorization tag to deny access to anonymous users. If the users are using Internet Explorer and are connecting from an Intranet zone, IE automatically will login the user. But if the user is connecting from the Internet zone, IE will still display a login box though for safety. But these are options that can be set from IE.
<authorization>
<deny users="?" />
</authorization>
Setting authentication mode alone without authorization does not force the user to be authenticated in ASP.NET. If you want to control the security from IIS, I cannot help much with IIS settings but I know basically you can disable Basic Authentication , then enable Integrated Windows Authentication and then disable the Anonymous Login Account which will achieve the same or better results.
I am also working on an MVC project at the moment and I tested the above settings with my project and it works. You would not need the Authorize attribute since we have the authorization tag in the configuration. I hope this can be of help to you and not get another -1.
Have you attached Authorize attribute to ur action or controller?
public class HomeController : Controller {
[Authorize]
public ActionResult Index() {
string userName = User.Identity.Name;
return View();
}
}

Resources