I have a C# web project. I opened the configuration manager, for "Active solution configuration" I chose
In the new window I typed the name (Dev), and didn't copy any settings. I checked off "Create new project configurations".
I right-clicked on my Web.config and chose "Add Config Transform". Web.Dev.config appeared indented under web.config as expected.
My web.config contains erroneous database values:
<connectionStrings>
<add name="PdxContext" connectionString="Data Source=badServer; Initial Catalog=badDB; Integrated Security=true; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
My Web.Dev.config, in part, contains valid DB values:
<connectionStrings>
<add name="PdxContext" connectionString="Data Source=.\sql2012; Initial Catalog=test; Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
...but when I select the Dev configuration and hit run, the site is run using the web.config file and not web.dev.config (it tries to connect to a non-existent database named "badDB" on host "badServer").
If I right-click on web.dev.config and choose "Preview Transform" the Transformed Web.config correctly shows that it will use the connectionStrings value from web.dev.config.
Oh, and in the Configuration Manager for Active Solution Configuration for "Dev" the configuration column has "Dev".
Any thoughts?
The solution can be found here:
https://stackoverflow.com/a/3994081
If you're using Visual Studio 2013 also see Matti Price's reply to that post, "For anyone struggling with this in later versions of VS, I had to change <Target Name="CopyWebTemplateConfig" BeforeTargets="Build"> To <Target Name="CopyWebTemplateConfig" BeforeTargets="PrepareForBuild"> And it all worked after that."
Related
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>
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">
<basicAuthentication enabled="false" /> <!-- set to false -->
</sectionGroup>
<!-- ... -->
<authentication>
<section name="basicAuthentication" overrideModeDefault="Allow" /> <!-- set to allow -->
</authentication>
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.
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.
I'm having a bit of trouble with my web.debug.config and web.release.config files.
To be more specific, my webpage will only use the default web.config file, and completely ignore the debug and release files.
This happens not only when I run the project locally, but also when I publish it to an IIS server.
I am using Visual Studio 2010 Ultimate (no Service Pack).
Here are the config files:
web.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="MyConn" connectionString="SomeConnectionString"
providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
web.debug.config and web.release.config:
<?xml version="1.0"?>
<configuration xmlns:xtd="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyConn" connectionString="SomeOtherConnectionString"
providerName="System.Data.SqlClient"
xtd:Transform="Replace"
xtd:Locator="Match(name)"/>
</connectionStrings>
</configuration>
As I mentioned before, the website uses the connection string from the web.config file, and not from the web.release.config.
Another interesting point is that in the physical folder to which I published the project, all three config files exist; each exactly the same as they appear in the VS solution.
Suggestions, anyone?
You need to run the transformations. It will not work if you just put the 3 web.config in your folder. You can run this and it will transform your web.config
MSBuild.exe Project.csproj /T:TransformWebConfig /P:Configuration=Release
You will then have a folder in your obj folder created at build that will be called TransformWebConfig. The transformed web.config will be in this.
You can also take a look at this post, he creates a build target to achieve this automatically.
http://vishaljoshi.blogspot.com/2010/05/applying-xdt-magic-to-appconfig.html
I figured out what I have been doing wrong.
Instead of a Web Application, I was using a Web Site Project.
(The difference between the two is that a Project doesn't actually contain a .proj file. How ironic.)
Now that I've realized the actual problem, it turns out that I'm not the first with it...
Here's a link to a previous post with a workaround solution:
How do I do Web.config Transformations with Visual Studio Website Projects?
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.