I have taken over the development of a software product that we currently deploy on an IIS server. Initially it was running with ASP.net core 2.0 but since I would like to use EF, I have configured the software to use 2.1.
The problem is, when I deploy a new version of our software, I cannot run it successfully. I tried to track down the error and i recognized that the web.config of the successfully running version and the new published version differ from each other.
Here's the version that runs just fine:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<aspNetCore processPath="dotnet" arguments=".\myProject.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 2b991c10-ec9f-493d-97b9-ee1f96458510-->
And this does not work:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\myProject.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 2b991c10-ec9f-493d-97b9-ee1f96458510-->
Obviously, it's just the handler that makes the difference. When I manually remove it, the software runs fine. How can i make sure that in future publishing processes via VB 2019, this handler is not added to the web.config? Is there any setting that I can make to prevent this error?
For ignoring the web.config during publishing, you could try <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled> in *.csproj like
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
</Project>
For more information, you could refer web.config file
Unfortunately I cannot reconstruct that initial error message but I solved the problem in the meantime.
The problem was a <handler> tag that was added to the web.config during the publishing. We use a nested website structure with one main website and 4 sub-sites. In this configuration, the handler in the web.config must be removed according to documentation from Microsoft. My former colleague wrote a small xdt-transform script a while ago that was supposed to remove the tag when publishing the software. It always worked fine but it stopped working when I updated the SDK to 2.1. So the handler-tag was added to the web.config and that's why I could not access the website in the first place.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document->Transform">
<system.webServer>
<handlers xdt:Transform="Remove" />
</system.webServer>
</configuration>
I figured out that the generated web.config had an additional <language>-tag before the <system.webServer>-tag. Adding the language-tag to the remove script made the script work again. Now that problem was solved and I could at least connect to the website.
But after connecting I received a HTTP Error 502.5. This was due to an old 2.0.7 version of the runtime that was installed on the server. After updating to 2.2 the website finally was rendered correctly.
Related
IIS Server gives "Method Not Found Error". After Exploring Google, I got that WebDAVModule should be removed in web config file.
Every time i publish my Project, i have to add this
<modules> <remove name="WebDAVModule" /> </modules>
in Webconfig
Please suggest me how do i add this in Startup.cs or any other solution?
Just add a web.config file to your project, like bellow:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</configuration>
You can do it in several ways
Remove from IIS model
Go to your site in IIS
Click "Modules"
Remove WebDAVModule
Restart site (might not be needed)
Remove from windows features
ASP.NET Core 3.1 project uses the following line in csproj to copy a customized web.config from the wwwroot folder into the output folder:
<ItemGroup>
<Content Update="wwwroot\Web.config" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" Link="%(Filename)%(Extension)" />
</ItemGroup>
The project is compiled using Azure DevOps classic (non-YAML) pipeline:
.NET Core task (Task version 2.0), command restore
.NET Core task (Task version 2.0), command build
.NET Core task (Task version 2.0), command publish with [x] Publish web projects, [x] Zip published projects and [x] Add project's folder name to publish path
Publish build artifacts task (Task version 1.0)
Builds up to July 2020 retained the customized web.config in the build artifact as expected, just with the following lines being injected to the customized web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<...>our custom settings defaultDocument, staticContent, rewrite and rewriteMaps</...>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2"
resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Something.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</configuration>
<!--ProjectGuid: SOME-GUID -->
But the builds made yesterday and today contains different web.config, missing the customized parts while adding a <location> tag:
<?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="dotnet" arguments=".\Something.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: SOME-GUID -->
Note: There were no builds between July and yesterday. The only change made in the project source was just a few unrelated minor text changes in Razor views. The pipeline definition is kept unchanged for at least a year.
July's build agent logged these versions:
Current agent version: '2.171.1'
Current image version: '20200630.0'
Downloading task: DotNetCoreCLI (2.171.3)
Downloading task: PublishBuildArtifacts (1.158.3)
November's build agent logged these versions:
Current agent version: '2.177.1'
Included Software: https://github.com/actions/virtual-environments/blob/win19/20201116.1/images/win/Windows2019-Readme.md
Current image version: '20201116.1'
Downloading task: DotNetCoreCLI (2.175.0)
Downloading task: PublishBuildArtifacts (1.158.3)
Why the web.config in the artifacts no longer contains the customized part? How to fix it?
I'm upgrading an existing ASP.NET Core 2.2 application to 3.0.
When I publish and host my APIs inside local IIS, I get the HTTP Error 502.5 - Process Failure page. The point is, I don't see the logs being written to the stdoutLogFile location.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\bin\MyApplication.dll" stdoutLogEnabled="true" stdoutLogFile=".\bin\Logs\" hostingModel="inprocess" />
</system.webServer>
</configuration>
I've changed the output folder from \bin\Debug\netcoreapp3.0\ to \bin\ via these configurations:
<PropertyGroup>
<OutputPath>.\bin</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
I also have a folder called Logs in my \bin\ folder.
But when I call my API, I get this error in Error Viewer:
Warning: Could not create stdoutLogFile
C:\PathToMyProjectFile\bin\Debug\netcoreapp2.2_19212_2019102292022.log,
ErrorCode = -2147024893.
The point is, I'm not using 2.2 anymore. How should I solve this?
you have to modify the generated web.config by removing the "V2" in modules="AspNetCoreModuleV2", in order to have: modules="AspNetCoreModule".
Hope this helps
I'm new to this .NET Core stuff and this is the first time I've tried to deploy one of these.
The project is an API for an Angular front end I'm building and takes HTTP requests and returns JSON. When I run it in Visual Studio on my box it is all fine. I'm running VS2017 and have .NET Core 2.0.0 installed.
I publish to a folder on the web server and it all seems to work fine, but when I try to access the API I get a 404 not found error. The server is running .NET 2.0.6 (I tried to get 2.0.0 but couldn't find it in the Hosting Bundle Installer.
If I delete the web.config the HTML file will then show up, but obviously the API doesn't work. But as the HTML file shows up there is no issue with permissions and access. There's nothing in the Event Viewer. I've also tried turning on the logging in the web.config, but it doesn't log... probably not getting far enough to.
Web config looks like this.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\RawMaterialsSystem.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: f01b1621-2ced-4ad2-9ae6-004e03b0e043-->`
STEP 1: Change your web.config file to this
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
STEP 2:
In visual studio, right click the .net core app project and select "Publish"
Then publish it as a folder under bin\Release\netcoreapp2.0\publish
STEP 3:
In IIS --> Sites --> Right click on YourSite --> Under "Manage Website" select "Advanced Settings"
Make sure the "Physical Path" you are pointing to is the "publish" folder as the app directory, and not the "netcoreapp2.0" folder
I've just came across with problem of web.config transformation in asp.net core.
There are two files: base web.config and web.prod-zone-a.config. My aim is to use transformation inside web.prod-zone-a.config when publishing my project.
I have the following "prod-zone-a" configuration settings in .csproj:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'prod-zone-a|AnyCPU' ">
<IntermediateOutputPath>obj\Debug\netcoreapp1.1</IntermediateOutputPath>
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_1</DefineConstants>
<Configuration>prod-zone-a</Configuration>
</PropertyGroup>
web.prod-zone-a.config looks like:
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore>
<environmentVariables xdt:Transform="Replace">
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="prod-zone-a" />
</environmentVariables>
</aspNetCore>
</system.webServer>
I tried to run publish by two commands:
dotnet msbuild /t:Publish /p:OutputPath=c:\delivery /p:Configuration=prod-zone-a
and
dotnet publish --configuration prod-zone-a --output c:\delivery
But no transformation applies to web.config on output - just the default value.
Do I miss something in configuration or command executing?
This worked for me:
Add web.release.config file to the project root.
In Visual Studio 2017, Publish using Web Deploy (make sure it is set to Release). Settings will automatically be picked up.
Sample transformation:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<aspNetCore>
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="PRODUCTION" xdt:Locator="Match(name)" xdt:Transform="SetAttributes" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
Update: If you want to remove web.config.release file and others on publish, simply edit your .csproj file and add something like this:
<ItemGroup>
<Content Remove="appsettings.Development.json" />
<Content Remove="web.release.config" />
</ItemGroup>
<ItemGroup>
<None Include="appsettings.Development.json" />
<None Include="web.release.config" />
</ItemGroup>
There is a well-documented tool on github for xdt-transformations.
Also it doesn't depend on command, both of dotnet publish and dotnet msbuild works fine
With the latest version of dotnet cli (2.1.400 or greater), you can just set this msbuild property $(EnvironmentName) and publish tooling will take care of adding ASPNETCORE_ENVIRONMENT environmentVariable to the web.config with the specified environment name.
Also, XDT support is available starting 2.2.100-preview1.
Sample: https://github.com/vijayrkn/webconfigtransform/blob/master/README.md
IIS Web Deploy ASP.NET Core (2.1) in Visual Studio 2017 (VS2017)
First do this: (ref:https://github.com/nil4/dotnet-transform-xdt#-use-with-msbuildcsproj-tooling)
Install package - dotnet add package DotNet.Xdt --version 2.1.0
Modify .csproj - add package - refer github
Modify .csproj - add transform code (ApplyXdtConfigTransform) at the end - refer github
Add web.DEV_Server.config transfor file by right-clicking on DEV_Server.pubxml
Added following to web.DEV_Server.config
<environmentVariable xdt:Locator="Match(name)" name="ASPNETCORE_ENVIRONMENT" value="Development" xdt:Transform="SetAttributes" />
Modify DEV_Server.pubxml to modify following setting value.
<LastUsedBuildConfiguration>DEV_Server</LastUsedBuildConfiguration>
Validate Connection & Publish
Deploy still uploads other config files, not sure how to stop that.
Following on from user1820686's answer above:
The github page misses out some of the steps required to add this for MSBuild/csproj tooling:
You need to open a command prompt in your project directory and run
dotnet add myProj.csproj package Microsoft.DotNet.Xdt.Tools --version 2.0.0
Then you need to open the csproj file and add
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.Dotnet.Xdt.Tools" Version="2.0.0" />
<!-- ... other package references ... -->
</ItemGroup>
may be i don't clear question. For mine case web.config override all settings in web.Release.config file.
Fix for me, i just add reference for transformation xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" to configuration file.
so, .config file should start:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
After some time, the best solutions is using dotnet-transform-xdt tool
This is now supported by dotnet publish from SDK version 2.2 with a whole bunch of options.
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-2.2
I think in the example from the question, it would then work when published as
dotnet publish --configuration prod-zone-a
This worked for me with the 1. & 2. above:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<httpErrors existingResponse="PassThrough"
xdt:Locator="Match(existingResponse)"
xdt:Transform="InsertIfMissing" />
</system.webServer>
</location>
</configuration>