Basic Authentication on IIS Express - iis-express

I've searched for a while now but I can't seem to find the answer. There are ways of disabling/enabling anonymous and windows authentication. Does anyone know how to enable basic authentication on IIS Express (8.0) in Visual Studio 2013?

Update ApplicationHost.config
In the the ApplicationHost.config file, find the following nodes and update the values:
<sectionGroup name="authentication"&gt
<basicAuthentication enabled="false" /> <!-- set to false -->
</sectionGroup&gt
<!-- ... -->
<authentication&gt
<section name="basicAuthentication" overrideModeDefault="Allow" /> <!-- set to allow -->
</authentication&gt
Locate ApplicationHost.config
VS 2015 and above (per Joost's answer):
sln_folder/.vs/applicationhost.config
VS 2013 and below:
%UserProfile%\Documents\IISExpress\config\applicationhost.config
As far as I know, there is no way to enable it for only one project.

An additional heads up, in Visual Studio 2015, the location of the applicationhost.config file that is actually being used is inside a folder called .vs inside your solution folder. The one in your user profile is not being used

Here are slightly more details than the previous answer had:
%USERPROFILE%\Documents\IISExpress\config\applicationhost.config:
<basicAuthentication enabled="true" />
In the same file: set
<anonymousAuthentication enabled="false" userName="" />
If you are not using domain test accounts, create a local user account with the password for the test login.

Related

Visual studio update behind a proxy server

I'm using Visual studio 2015 inside our organization. I want to be able to use the Extensions and updates features but I always get a connection problem when I try to access the "online" or "update" section. We are behind a proxy server.
The problem is related to the configuration of the proxy because the feature work well if I connect my pc on a direct internet connection.
The proxy is managed by another organization and I don't know much about that subject.
I need help on what I should say so they understand what they need to change.
Does someone knows what configuration need to be put in place to make that VS feature works?
thanks
Assuming you're working on Windows, you can try to set the Proxy for VS in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe.config
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy bypassonlocal="True" proxyaddress="http://proxy.bn.ch:8080" />
</defaultProxy>
</system.net>
This overrules the standard Proxy Settings from IE.
the answer of tk78 is correct but if you are behind a company proxy probably you need to add user, password and domain on the proxy address like this:
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy bypassonlocal="True" proxyaddress="http://domain%5Cusername:password#youproxyaddress:portnumber" />
</defaultProxy>
</system.net>
The '%5C' is the escape for '' .

Possible to add iis express configuration (windows authentication) to asp.net mvc6 project?

Is it possible to setup an asp.net mvc6 application to run with windows authentication when debugging using IISExpress without having to edit the global iis express configuration file?
In visual studio 2013, you had the possibility to go to properties on your web application project and edit it from there. The changes resulted in some extra xml in the .csproj file with the information.
However, the .kproj file from asp.net mvc6 projects does not have the configuration listed.
I have tried to add the xml properties from vs2013 to the .kproj file which has had no effect.
Is this not yet implemented?
Right-click on ASP.net 5 / MVC 6 project and select properties.
On the left click on Debug.
At the bottom of the Properties->Debug page
uncheck enable anonymous authentication
check Enable Windows Authentication
In your controllers you'd put something like
[Authorize(Roles = "Domain\\Group")]
above the class or action methods
Yes, simply add your web.config file to your wwwroot directory with the IIS configurations that you want.
web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</configuration>

"Missing web components" error when opening MVC3 project in Visual Studio 11 Beta

When I open a solution containing an MVC3 project in Visual Studio 11 Beta, I see the following message:
The Web project 'Landboss.Web' requires missing web components to run
with Visual Studio. Would you like to download and install them using
the Web Platform Installer now? (Note: Some components might require
restart to take effect.)
ASP.NET Web pages with Razor syntax 1.0.0.0
When I click Yes, the Web Platform Installer opens and tells me this:
The product you are trying to install is not supported on your
operating system. Click here for more information.
So far I've installed Visual Studio 11 Beta on two machines and both have this same problem.
I believe this was caused by the fact that I had previously installed Visual Studio 11 Developer Preview. I did uninstall it before installing the Beta, but you know how that goes.
To fix it, I did the following:
Uninstalled "Microsoft ASP.NET MVC 3 - Visual Studio 11 Tools Update"
Uninstalled "Microsoft ASP.NET Web Pages - Visual Studio 11 Tools"
Ran the Visual Studio 11 Beta "Repair" from the installation ISO.
It worked! Razor syntax highlighting and intellisense are back, and the warning message no longer shows when I open the project.
This is related to the configuration setting webpages:Version
[appSettings]
...
[add key="webpages:Version" value="x.0.0.0" /]
...
[/appSettings]
if you have multiple versions of razor on the system (1 or 2 for now), better add this setting if it's missing.
Choose the version you want/need at the appropriate level. (Obviously replace the brackets...)
I have also had this error happen when a Subversion conflict was committed to the repository - the presence of this block in the web.config's app settings seemed to trigger the message when loading the project:
<<<<<<< .mine
<add key="blogCommentsApprovedByDefault" value="false" />
(other appsettings)
=======
<add key="blogCommentsApprovedByDefault" value="false" />
(other appsettings)
>>>>>>> .r358
Cleaning up the Subversion conflict in appSettings resolved this error.
While #silent__thought's solution may correct the problem, it's not the easiest way to fix it.
#Costas solution may exactly address the problem, but here is a more detailed explanation if you need it.
In my case, I needed the following in my web.config file (for MVC 4):
<configuration>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<httpHandlers></httpHandlers>
</system.web>
</configuration>
Of course, you may not need all of these configurations for your app. These just happen to be the default settings for an MVC 4 project.
I got this error because the appSettings section was setup to be encruypted, and the encryption keys were not setup correctly. It seems this error has a tendancy to popup whenever there is something wrong/malformed with web.config even if unrelated to MVC.
I got this error when something in the web.config file was corrupted. I simply formatted the file and then resaved it. Then I restarted Visual Studio.
I've just been bitten by this and it's another variation of the web.config problem. In my case we do not store a web.config file in our repo but generate one from a template as a custom build step. When we do a clean of the workspace* this file was being deleted (rightly so because it's not in the repo) and so the next time Visual Studio was started it complained. A command line build via msbuild was never affected by this.
*We have a "partial" clean, which deletes all the build artefacts (including those VS leaves behind) and a "full" clean that resets the workspace to the same state as if you had just pulled it from the repo.

IIS Express Windows Authentication

I'm trying to use IIS Express with VS2010 to host a silverlight application. I modified my applicationhost.config file to allow for modification of the proper configuration settings. I have the following in my web.config:
<location path="">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<windowsAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
</location>
I am not being authenticated and my domain service call returns a null record as the user. I was able to get this to work after installing VS2010 SP1 BETA but I'm trying to get this to work with only IIS Express.
How do I enable Windows Authentication to work with IIS Express. Is there a configuration setting that I am missing?
Visual Studio 2010 SP1 and 2012 added support for IIS Express eliminating the need to edit angle brackets.
If you haven't already, right-click a web-flavored project and select "Use IIS Express...".
Once complete, select the web project and press F4 to focus the Properties panel.
Set the "Windows Authentication" property to Enabled, and the "Anonymous Authentication" property to Disabled.
I believe this solution is superior to the vikomall's options.
Option #1 is a global change for all IIS Express sites.
Option #2 leaves development cruft in the web.config.
Further, it will probably lead to an error when deployed to IIS 7.5 unless you follow the "unlock" procedure on your IIS server's applicationHost.config.
The UI-based solution above uses site-specific location elements in IIS Express's applicationHost.config leaving the app untouched.
More information here:
http://msdn.microsoft.com/en-us/magazine/hh288080.aspx
option-1:
edit \My Documents\IISExpress\config\applicationhost.config file and enable windowsAuthentication, i.e:
<system.webServer>
...
<security>
...
<authentication>
<windowsAuthentication enabled="true" />
</authentication>
...
</security>
...
</system.webServer>
option-2:
Unlock windowsAuthentication section in \My Documents\IISExpress\config\applicationhost.config as follows
<add name="WindowsAuthenticationModule" lockItem="false" />
Alter override settings for the required authentication types to 'Allow'
<sectionGroup name="security">
...
<sectionGroup name="system.webServer">
...
<sectionGroup name="authentication">
<section name="anonymousAuthentication" overrideModeDefault="Allow" />
...
<section name="windowsAuthentication" overrideModeDefault="Allow" />
</sectionGroup>
</sectionGroup>
Add following in the application's web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
</configuration>
Below link may help:
http://learn.iis.net/page.aspx/376/delegating-configuration-to-webconfig-files/
After installing VS 2010 SP1 applying option 1 + 2 may be required to get windows authentication working. In addition, you may need to set anonymous authentication to false in IIS Express applicationhost.config:
<authentication>
<anonymousAuthentication enabled="false" userName="" />
for VS2015, the IIS Express applicationhost config file may be located here:
$(solutionDir)\.vs\config\applicationhost.config
and the <UseGlobalApplicationHostFile> option in the project file selects the default or solution-specific config file.
Building upon the answer from booij boy, check if you checked the "windows authentication" feature in
Control Panel -> Programs -> Turn windows features on or of -> Internet Information Services -> World Wide Web Services -> Security
Also, there seems to be a big difference when using firefox or internet explorer.
After enabeling the "windows authentication" it works for me but only in IE.
In addition to these great answers, in the context of an IISExpress dev environment, and in order to thwart the infamous "system.web/identity#impersonate" error, you can simply ensure the following setting is in place in your applicationhost.config file.
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
</configuration>
This will allow you more flexibility during development and testing, though be sure you understand the implications of using this setting in a production environment before doing so.
Helpful Posts:
http://forums.iis.net/post/1873372.aspx
http://www.iis.net/learn/application-frameworks/building-and-running-aspnet-applications/aspnet-20-breaking-changes-on-iis
In IIS Manager click on your site.
You need to be "in feature view" (rather than "content view")
In the IIS section of "feature view" choose the so-called feature "authentication"
and doulbe click it.
Here you can enable Windows Authentication.
This is also possible (by i think in one of the suggestions in the thread) by a setting in the web.config ( ...)
But maybe you have a web.config you do not want to scrue too much around with.
Then this thread wouldnt be too much help, which is why i added this answer.
This answer may help if: 1) your site used to work with Windows authentication before upgrading to Visual Studio 2015 and 2) and your site is attempting to load /login.aspx (even though there is no such file on your site).
Add the following two lines to the appSettingssection of your site's Web.config.
<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>
On the same note - VS 2015, .vs\config\applicationhost.config not visible or not available.
By default .vs folder is hidden (at least in my case).
If you are not able to find the .vs folder, follow the below steps.
Right click on the Solution folder
select 'Properties'
In Attributes section, click Hidden check box(default unchecked),
then click the 'Apply' button
It will show up confirmation window 'Apply changes to this folder, subfolder and files' option selected, hit 'Ok'.
Repeat step 1 to 5, except on step 3, this time you need to uncheck the 'Hidden' option that you checked previously.
Now should be able to see .vs folder.
After doing everything in the above answers, I figured out I was not running Visual Studio as Admin. After running as Admin, problem solved.
If none of the answers helps, you might need to adjust the project properties. Check this other StackOverflow answer on how to do that:
https://stackoverflow.com/a/20857049/56621
I'm using visual studio 2019 develop against ASP.Net application. Here's what been worked for us:
Open your Project Property Windows, Disable Anonymous Authentication and Enable Windows Authentication
In your Web.Config under system.web
<authentication mode="Windows"></authentication>p
And I didn't change application.config in iis express.

IIS Express - Visual Studio - Running multiple sites on the same port

I have multiple APIs that use the same port (8888). These APIs are part of different solutions.
http://localhost:8888/api1
http://localhost:8888/api2
....
When I run any of the APIs in visual studio 2013 (hit F5), iis express starts and all of the APIs are running. This happens even though the APIs are part of different solution. I can see them when I click on the iis express icon under View Sites.
I installed VS 2015 and when I run one API in visual studio the other APIs do not run. I cannot even run the other APIs in the other solution since I get:
unable to launch iis express.. port is in use
how can I get the other APIs to run when I run any API? I need to mimic the behavior that exists in VS 2013 in VS 2015.
Thanks.
I solved this for a similar scenario, although in my case I chose to run IISExpress via the command line and passed through the config file as an argument.
Edit the applicationhost.config file. I found mine via the folder path %USERPROFILE%\Documents\IISExpress\config
Locate the <sites> section (found under <system.applicationHost>)
As an example, I have two applications that I want to host simultaneously on port 80 on localhost:
<sites>
<site name="test" id="1" serverAutoStart="true">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\codepath" />
</application>
<application path="/api1" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\codepath\api1" />
</application>
<application path="/api2" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\codepath\api2" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":80:localhost" />
</bindings>
</site>
<!-- other settings relevant to your installation of IISExpress-->
</sites>
The key things I had to do to get this working was:
Make sure applicationhost.config is well-formed XML
Make sure you specify the root path in addition to the two api application paths
serverAutoStart="true" ensures the site starts when IISExpress is called
All the applications share the same applicationPool
I defined just one site and bundled in all my applications as sub paths
Update to this in Visual Studio 15+ the IIS config folder is in the projects hidden .vs folder [ProjectFolder]/.vs/[ProjectName]/config/applicationhost.config
Other than that, Ivor's Answer still worked for me.
If you do want the old behavior, use global application host file in your project file please,
<UseGlobalApplicationHostFile>True</UseGlobalApplicationHostFile>
http://blog.majcica.com/2018/03/15/using-global-application-host-file-in-visual-studio-2015/

Resources