I have this web.config file with the compilation option set as below
Web.config
<configuration>
...
<system.web>
<compilation debug="true" targetFramework="4.5" />
...
</system.web>
</configuration>
And here is what Visual Studio puts for release mode by default.
Web.Release.config
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
I am using this for MVC4 project. Based on this tutorial, I was expecting that minified versions of js and css would be served, when the application is run under Release Mode. But this doesn't seem to be working and non-minified versions of js and css are being served. On the other hand, if I explicitly set debug to false in web.config, then the min versions are served correctly.
It seems like compilation tag Transform issue when the application is run under Release Mode, but I don't understand what's wrong with the same in Web.Release.config.
In short, I am unable to get bundling and minification working, by running application under Release Mode.
Web.config transformations as they are defined in the Web.Release.config are only done when deploying/publishing the project for the relevant configuration.
Just changing the active configuration in Visual Studio to Release and running the application does not run the transformations. Therefore, the web.config remains unchanged. This behavior is reasonable by the way as a web application is run from the project directory that contains the original web.config. If Visual Studio were to transform the web.consign, your original web.config would be changed.
If you haven't created a deployment profile yet, you can publish your application to the file system to verify the behavior. Choose Release as the configuration to run the deployment for. The transformations should be executed as expected.
My answer might be late, however this what worked with me:
I've changed the line :
<compilation xdt:Transform="RemoveAttributes(debug)" />
to :
<compilation xdt:Transform="Replace" debug="false" targetFramework="4.5" />
this basically did the trick, as I think the optimizer is looking for Debug value to be be present and == "false".
Hope this helps people who don't want to manage this from code.
If you'd like to test your .NET bundling and minification that you've got set up in your Global.asax file, you can also use precompilation notation...for example
#if DEBUG
BundleTable.EnableOptimizations = false;
#else
BundleTable.EnableOptimizations = true;
#endif
With this, your application won't need to trigger the transform in the build operation and will run just like you want it to.
Possibly an improvement to Omar.Alani's answer:
In the Release transform, replace the line:
<compilation xdt:Transform="RemoveAttributes(debug)" />
with the following:
<compilation debug="false" xdt:Transform="SetAttributes" />
compilation debug="false" xdt:Transform="SetAttributes"
comes in handy when you are activating XML transformations at release azure deployment time to make configuration transformations specific to a target environment.
When you check XML transform at azure deployment time, the following sequence is done:
Apply web.release.config on web.config
Apply web.stageName.config on modified web.config.
But web.release.config has already been applied on web.base.config so if
compilation xdt:Transform="RemoveAttributes(debug)"
is used in web.release.config file, the web.config has already debug attribute been removed at compilation time and when it deploys it transform again with web.release.config, trying to apply the above command but it fails.
Removing debug attribute is sufficient RemoveAttributes(debug).
It will work similar to debug=false.
Related
I'm having trouble opening my projects in Visual Studio. I get the following error and the project does not load.
Creation of virtual directory failed with the following error: Filename: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config
Line number: 24
Error: The configuration section 'fulltrustassemblies' cannot be read because it is missing a section declaration.
I tried creating a new ASP.NET webform application with target framework 4.7.2 (same as the ones of the project that does not load) and get the same issue.
Did you try if adding the section to the file solve the problem?
<configuration>
<system.webServer>
<system.web>
<fullTrustAssemblies>
<clear/>
</fullTrustAssemblies>
</system.web>
</system.webServer>
</configuration>
In the respective web.config file, you need to removed following element:
<fullTrustAssemblies>
....
</fullTrustAssemblies>
<partialTrustVisibleAssemblies />
I am running IIS under Windows Server 2016 and I'm trying to run an ASP.Net core 3.1 application but I can't get past this error:
500.19 error
(The language in the picture is Hungarian, but it contains no useful information whatsoever, just an example)
Here is my web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Minibizz.Routing.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
What am I missing?
P.S.: The web.config was created by Visual Studio 2019.
The reason behind the issue:
That error message goes on to say what exactly is bad about your configuration file, hence you should refer the “Config Error” and “Config Source” sections. This problem occurs because of the ApplicationHost.config file or the Web.config file contains a malformed or unsupported XML element.
if you are using url rewrite rule then install url rewrite Extention of iis. Enable ANCM logging, ie. set stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout\" (I think the path needs to end by a backslash), then run the web app and see if something gets logged into the stdout folder. Verify that the log directory exists at the path referenced by the web config. If it does not, create it. The path shown in your config would place the "logs" directory in the root folder of the deployed site. Verify that the application pool has to write access to the logs directory.
Make sure you installed the .net bundle.check that you installed below iis feature:
You may also need to verify that the path to the dotnet executable exists in the deployment machine's environment variables. To check this, first find the path where dotnet.exe is installed. It is generally located in either C:\Program Files\dotnet or C:\Program Files (x86)\dotnet. Once you know the path, ensure that the path exists in your Environment Variables.
The web.config content seems to be correct. If you use a clean web.config copy, does the problem persist? If the issue can be solved by replacing web.config with clean configuration content, then the problem is exactly with this web.config. In this case, I suggest you remove parts of the web.config content to narrow down the issue. If the pages show correctly after you remove one section, then the problem is with that section. You need double-check what's wrong with the section and update the correct configuration.
If the problem remains even with clean web.config content, I suggest you access other pages in different folders in your site to see if the problem still exists.
you could refer this below link for how to publish asp.net core site in iis:
https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio
Is it possible to not include web.config in output directory, but still use web.config during building the application?
Unfortunatelly setting Build action to "None" doesn't copy web.config but application cannot compile because web.config is not used then.
I recommend you to look into web.config transformations.
They allow you to have one version for debug and one for release (deployment).
The most common transformation is for connection strings. You can do that like this:
<connectionStrings>
<add name="local" connectionString="Data Source=IPAddress,Port;Initial Catalog=SomeOtherDB;User ID=TopSecretUsername;Password=SecurePassword"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
Another very common transformation is removing the debug attribute for release:
<compilation xdt:Transform="RemoveAttributes(debug)" />
Read more here:
http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/web-config-transformations
A great (free) video course can be found here:
http://www.pluralsight.com/courses/table-of-contents/aspdotnet-mvc3-intro
Can you do something like what's suggested in this SO question?
something like replacing in your prj file where you find the include for web.config with (untested):
<Choose>
<When Condition=" '$(Configuration)'=='DEBUG' ">
<ItemGroup>
<Reference Include="web.config" />
</ItemGroup>
</When>
</Choose>
As Mihai-Andrei Dinculescu so 'Angryly' puts it - unless you have a good reason to really want the file not to be copies rather then use transformations, you should go with transformations. If you really have to not copy the file or transformations are not suited for your needs, you can try this one
I made a web.config (full file, it doesn't show XML errors)
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
...
<location path="." inheritInChildApplications="false">
<connectionStrings>
<add name="ElmahLog" connectionString="data source=~/App_Data/Error.db" />
<add name="database" connectionString="w" providerName="System.Data.EntityClient"/>
</connectionStrings>
</location>
...
with a transform file (web.Staging.config)
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="database"
connectionString="c"
providerName="System.Data.EntityClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<customErrors defaultRedirect="error.aspx"
mode="RemoteOnly" xdt:Transform="Replace">
</customErrors>
</system.web>
</configuration>
I am publishing in Staging mode (right click website > Publish > Method: File System ...)
------ Build started: Project: Drawing, Configuration: Staging Any CPU ------
Drawing -> D:\Project\bin\Staging\Drawing.dll
------ Build started: Project: MySystem, Configuration: Staging Any CPU ------
MySystem -> D:\Project\bin\Staging\MySystem.dll
...
But when I look at the web.config in the output folder it isn't changed.
I found the following on the Build log:
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
Transformed web.config using Web.Staging.config into obj\Staging\TransformWebConfig\transformed\web.config.
What could be the problem? Am I doing this right?
Answering late but perhaps I can save someone a headache. In Visual Studio 2013, there are two places to select configuration for your build and deploy. The Configuration Manager and then again with Publish Web where the third step in the Wizard entitled Settings allows you to select Config you want to use. If you don't select your new configuration it will use the transform for the selected configuration instead of yours.
I found out two things:
You cannot set a namespace on the <configuration> tag (ex: for <location path="." inheritInChildApplications="false">)
You have to watch for the correct hierarchy in the transform file.
Like
<configuration>
<location>
<connectionStrings>
Instead of
<configuration>
<connectionStrings>
Ensure that in the properties of the Web.Config file Build Action is set to Content.
If the build action is set to None, it will not be transformed, even if it is being copied to the output directory.
Make sure to include InsertIfMissing if the section you are trying to add does not already appear in the output.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<security xdt:Transform="InsertIfMissing">
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
</location>
</configuration>
Don't forget to copy all the other attributes of "configuration" from the original "web.config", as it seems that VS2012 doesn't do it automatically and of course there will be no match...
Answering late as well, but this may help someone.
I realized that if you have two websites in the same solution, when you try to publish one of them the transformation might not work if you have one only configuration for both projects.
One of my websites was always transforming, but the other sometimes was and sometimes wasn't.
For example, I had the configuration "Auto" in the solution, and had web.Auto.config for both websites.
I resolved that by creating a new configuration with a different name - "AutoAdmin" - creating also its web.AutoAdmin.config file for the second project, and when I published it again the transformation finally occurred.
I followed the below steps to fix this issue. Thanks, #michaelhawkins for pointing in the right direction. You need to make sure you change the configuration to release in two places.
And right click on your project and select "Properties". IF not working try selecting x86 in CPU Architecture
#Karthikeyan VK your post resolved my issue. Although I was selecting Production configuration in my publish profile, in configuration manager it was set to dev therefore It didn't transform my settings.
Microsoft needs to fix this bug. Once you pick a configuration in the publishing profile it should automatically update the configuration manager as well.
I seem to be having a problem with my visual studio 2005/2008 installation or something because it isn't providing any IntelliSense whatsoever for controls registered on web.config files in folders different from the root, but it isn't showing any errors neither. Is this behavior normal?
I have access only to the folder of my sub-app, so I can't modify the root's web.config file. Well I COULD, but I'm NOT allowed to.
What I'm trying is to register some WebUserControl's on the web.config file for my sub-app folder, so all the pages in my sub-app can use the WebUserControl's without having to register them on every page, but I'm not getting IntelliSense for those controls registered on the web.config file on my sub-app folder, but I do get IntelliSense if I register them on the root's web.config file. IntelliSense for everything else appears to be working fine.
In the web.config file on my sub-app folder I have something like the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<pages>
<controls>
<add tagPrefix="qme" tagName="EmptySearchMessage" src="~/QMinerals/WebUserControls/EmptySearchMessage.ascx"/>
<add tagPrefix="uc1" tagName="uc_general" src="~/uc_general.ascx" />
<add tagPrefix="uc1" tagName="uc_menu" src="~/uc_menu.ascx" />
</controls>
</pages>
</system.web>
</configuration>
am I doing something wrong?
Update
Now I have upgraded to VS2008 SP1 and the issue persist
Did you try removing "~" from the path and using it relative to web.config? (yeah, even if works now)
Do you have Visual Studio 2005 Service Pack 1?