I have a dotnet core application I am deploying remotely on a test server. The ASPNETCORE_ENVIRONMENT variable should be set to "Development" on the remote machine. Each time I deploy, the ASPNETCORE_ENVIRONMENT variable is overwritten with "Develop". I have to go into the IIS Admin Configuration Editor and replace the incorrect ASPNETCORE_ENVIRONMENT variable each time I deploy.
Can anyone help me understand why this variable is being overwritten each time I deploy?
Here is my web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation>
<buildProviders>
<remove extension=".xml" />
<add extension=".xml"
type="System.Web.Compilation.ForceCopyBuildProvider" />
</buildProviders>
</compilation>
</system.web>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*"
modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet"
arguments=".\WorkersCompensation.dll" stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true">
<environmentVariables>
<clear />
<environmentVariable name="ASPNETCORE_ENVIRONMENT"
value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
Here is my Dev.pubxml file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>netcoreapp1.0</PublishFramework>
<UsePowerShell>True</UsePowerShell>
<publishUrl>\\esdev2.elwood.local\D$\Core\WorkersCompensation</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeFoldersFromDeployment>wwwroot\node_modules</ExcludeFoldersFromDeployment>
<UseMsDeployExe>true</UseMsDeployExe>
</PropertyGroup>
<ItemGroup>
<MsDeploySkipRules Include="SkipNodeModules">
<AbsolutePath>wwwroot\node_modules</AbsolutePath>
</MsDeploySkipRules>
</ItemGroup>
</Project>
I believe I have found the issue/solution for anyone else having this issue.
The web.config file deployed did not have the environmentVariable entry until I edited the environment variables in IIS Admin.
I altered the web.config and web.Debug.config files in my deploy and now I am getting the correct environment variables on the IIS server.
The web.config file should match the one in my question above, but the web.Debug.Config now looks like this:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<aspNetCore>
<environmentVariables>
<clear />
<environmentVariable name="ASPNETCORE_ENVIRONMENT"
value="Development" xdt:Locator="Match(name)" />
</environmentVariables>
</aspNetCore>
</configuration>
Related
I have this in my dotnet core 3.1 webapp tasks.json:
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000",
"LOCAL": "true"
},
When I run dotnet publish this is what the Debug web.config contains:
<?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=".\App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
</system.webServer>
</location>
</configuration>
Because I want to host under IIS, this is what I want it to contain, so for now I need to manually edit it:
<?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=".\App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariable name="ASPNETCORE_URLS" value="http://localhost/app" />
<environmentVariable name="LOCAL" value="true" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
How can I configure either my solution or the .vscode .json files to make this change when I run dotnet publish?
1)You could use the below command to add the environment variable at the time of publishing:
dotnet publish -c Debug -r /p:EnvironmentName=Development
2)Add environmnet variable in publish profile
<PropertyGroup>
<EnvironmentName>Development</EnvironmentName>
</PropertyGroup>
3)Modify the project file (.CsProj) file
Referance link:
Publish to IIS, setting Environment Variable
how to set ASPNETCORE_ENVIRONMENT to be considered for publishing an asp.net core application?
If you want to do more than just setting the EnvironmentName:
On a project using "Microsoft.NET.Sdk.Web" target, config transforms are applied.
Add a web.{CONFIGURATION}.config in the project folder:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<aspNetCore>
<environmentVariables xdt:Transform="InsertIfMissing">
<environmentVariable name="Configuration_Specific"
value="Configuration_Specific_Value"
xdt:Locator="Match(name)"
xdt:Transform="InsertIfMissing" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Then after running a dotnet publish -c {CONFIGURATION}, the publish output contains the following auto generated web.config (some parts removed for brevity):
...
<aspNetCore ...>
<environmentVariables>
<environmentVariable name="Configuration_Specific" value="Configuration_Specific_Value"/>
</environmentVariables>
</aspNetCore>
...
See https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-6.0#build-configuration
I try to do to following:
setx /M PATH "%PATH%;D:\home\python364x86\Lib\site-packages"
But I am getting the following:
ERROR: Access to the registry path is denied.
How can I solve this?
Modifying the PATH is not straightforward, but possible.
You could use the code as below:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<runtime xdt:Transform="InsertIfMissing">
<environmentVariables xdt:Transform="InsertIfMissing">
<add name="FOO" value="BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
<add name="PATH" value="%PATH%;%HOME%\FolderOnPath" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</environmentVariables>
</runtime>
</system.webServer>
</configuration>
For more details, you could refer to this article.
Like said in the title i'm publishing an ASP.NET Core 3 API to IIS. When i publish that API the system create a web config file in the deploy directory containing that :
<?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=".\xxxxx.Api.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: daddb75b-3c54-4970-8945-8404ade81fbc-->
Everything is ok but what's i want to do is to add the three lines below in the System.webServer section in order to cover the issue described in this link : https://fantinel.dev/net-core-api-method-not-allowed-on-put-and-delete-requests/
Extract for explanations :
What happens is that, when published, .NET Core enables the
WebDAVModule, which disables PUT and DELETE requests by default.
So to get PUT and DELETE verbs we have to disable this WebDAVModule with this lines :
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
Is there a way to automatize the include of this lines to the produced/published web.config ? In the VS solution i don't see any Web.Config file or option to drive the output of deploy.
Thanks you all for your advices.
I just found out that when you add a web.config file yourself, the publishing wizard combines the normally generated web.config with the file you define yourself. Eg:
No web.config ==> Produces following 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=".\MintPlayer.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 7b031640-46da-4eac-b60c-740bd3659fce-->
Following web.config in the root of your ASP.NET Core project
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
</location>
</configuration>
Produces following 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>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
<aspNetCore processPath=".\MintPlayer.Web.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
So it seems that the ASP.NET Core deployment is combining both xml's. I'm using ASP.NET Core 3.1.
I have create 2 pages in asp.net core 2.0, both pages Login/Register open successfully as you can see in attached screen shot but when I click on login or register button after fill up all detail which is in form ,its giving me below error, I already try with changing environment variable , but its not helping me , please help !
Error.
An error occurred while processing your request.
Request ID: 0HLF8F6V3DFJ3:00000002
Development Mode
Swapping to Development environment will display more detailed information about the error that occurred.
Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
Modify your web.config file with the below. The web.config file is typically auto generated in the root folder of the application.
<aspNetCore processPath="dotnet" arguments=".\projectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
The web.config in its entirety should resemble the below (update "projectName.dll" for your project appropriately):
<?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=".\projectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Is there a way to run Go web application on IIS?
I found a setting for azure but its not working on my dev machine
this is a web config for azure :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="d:\home\site\wwwroot\go\bin\go.exe"
arguments="run d:\home\site\wwwroot\server.go"
startupTimeLimit="60">
<environmentVariables>
<environmentVariable name="GOROOT" value="d:\home\site\wwwroot\go" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
Your local IIS does not work simply because you need to install a separate component, called HttpPlatformHandler module,
https://azure.microsoft.com/en-us/blog/announcing-the-release-of-the-httpplatformhandler-module-for-iis-8/
http://www.iis.net/downloads/microsoft/httpplatformhandler
Reverse proxy or FastCGI were the older approaches which are no longer necessary with this new approach.
HttpPlatformHandler module doesn't work for me. I found this post by Sutean Rutjanalard on Medium very helpful, which use ASP.NET Core Module instead.
Basically, you need to create Application pool with "No Managed Code" as you do with a .net core app. And the following is the web.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\YourGoApp.exe" />
</system.webServer>
</configuration>