ASP.net 1.0核心web.config文件被覆盖造成CGI例外 [英] ASP.net core 1.0 web.config is being overwritten causing CGI exceptions
问题描述
我有一个工作web.config中,如下所示:
<?XML版本=1.0编码=UTF-8&GT?;
<结构>
<! -
在appsettings.json配置您的应用程序设置。了解更多http://go.microsoft.com/fwlink/?LinkId=786380
- >
< system.webServer>
<&处理GT;
<添加名称=aspNetCore路径=*动词=*的模块=AspNetCoreModule= resourceType为未指定/>
< /处理器>
<\\ Example.dllaspNetCore processPath =dotnet的论据= stdoutLogEnabled =假stdoutLogFile =\\\\?\\%HOME%\\ LogFiles文件\\标准输出forwardWindowsAuthToken =FALSE/>
< /system.webServer>
< /结构>
但不知何故,Visual Studio是更新我的web.config中:
<?XML版本=1.0编码=UTF-8&GT?;
<结构>
<! -
在appsettings.json配置您的应用程序设置。了解更多http://go.microsoft.com/fwlink/?LinkId=786380
- >
< system.webServer>
<&处理GT;
<添加名称=aspNetCore路径=*动词=*的模块=AspNetCoreModule= resourceType为未指定/>
< /处理器>
< aspNetCore processPath =%LAUNCHER_PATH%参数=%LAUNCHER_ARGS%stdoutLogEnabled =假stdoutLogFile =\\\\?\\%HOME%\\ LogFiles文件\\标准输出forwardWindowsAuthToken =FALSE/>
< /system.webServer>
< /结构>
这通过公布菜单的工作在Visual Studio(和作品一旦部署到蔚蓝的Web应用程序)。如果我使用,无论DOTNET CLI如DOTNET发布,这是行不通的,因为它保持与变量web.config文件:%LAUNCHER_PATH%和%LAUNCHER_ARGS%,而不是我所希望的:。DOTNET和\\ Example.dll
请注意:使用DOTNET恢复和DOTNET通过命令行建立的时候我的构建服务器不污染web.config中。使用也不时的MSBuild建立我的SLN。我的Visual Studio 2015年在本地和我的生成服务器上,我已经验证了dotnet的我的CLI命令行版本匹配。
我怎么能不被回滚我的web.config之前每次提交打架的Visual Studio?我清楚地做错事,应该是一个简单的配置解决?
更新:
Startup.cs
公共启动(IHostingEnvironment ENV)
{
VAR建设者=新ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile(appsettings.json,可选:真的,reloadOnChange:真)
.AddJsonFile($。AppSettings的{} env.EnvironmentName以.json,可选:真)
.AddEnvironmentVariables();
配置= builder.Build();
}
Appsettings.json
{
记录:{
IncludeScopes:假的,
LogLevel的:{
默认值:调试,
系统:信息,
微软:信息
}
}
}
Program.cs的
公共静态无效的主要(字串[] args)
{
VAR主机=新WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<&启动GT;()
。建立(); host.Run();
}
Project.json
{
版本:1.0.0- *,
compilationOptions:{
emitEntryPoint:真实, 排除:[
wwwroot的
分型,
node_modules
]
publishExclude:[
**。用户,
**。vspscc
]
}, 依赖:{
Microsoft.NETCore.App:{
版本:1.0.0
类型:平台
}
}, 工具:{
Microsoft.AspNetCore.Server.IISIntegration.Tools:{
版本:1.0.0- preview2决赛
进口:便携式net45 + win8的+ netstandard1.6
}, Microsoft.AspNetCore.Razor.Tools:{
版本:1.0.0- preview2决赛
进口:便携式net45 + win8的+ netstandard1.6
}
}, 构架: {
netcoreapp1.0:{
进口:[
netstandard1.4
dnxcore50
]
依赖:{
Microsoft.AspNetCore.Diagnostics:1.0.0,
Microsoft.AspNetCore.Mvc:1.0.0,
Microsoft.AspNetCore.Server.IISIntegration:1.0.0,
Microsoft.AspNetCore.Server.Kestrel:1.0.0,
Microsoft.AspNetCore.StaticFiles:1.0.0,
Microsoft.Extensions.Configuration.EnvironmentVariables:1.0.0,
Microsoft.Extensions.Configuration.Json:1.0.0,
Microsoft.Extensions.Logging:1.0.0,
Microsoft.Extensions.Logging.Console:1.0.0,
Microsoft.Extensions.Logging.Debug:1.0.0,
Microsoft.VisualStudio.Web.BrowserLink.Loader:14.0.0,
Microsoft.Extensions.Configuration.UserSecrets:1.0.0,
Microsoft.AspNetCore.Mvc.TagHelpers:1.0.0,
Microsoft.AspNetCore.Hosting:1.0.0,
System.ServiceModel.Primitives:4.1.0,
System.ServiceModel.Http:4.1.0,
System.Private.ServiceModel:4.1.0,
presentation.Common:*,
System.Runtime:4.1.0,
System.Runtime.Numerics:4.0.1,
SharedContract:*
}
}
}, 运行时间:{
win10-64:{},
win10-86:{},
win8的-64:{},
win8的-86:{}
}, buildOptions:{
emitEntryPoint:真实,
preserveCompilationContext:真
}, publishOptions:{
有:
wwwroot的
意见
appsettings.json
的web.config
]
}, 脚本:{
prepublish:故宫安装,一饮而尽重建,吞掉分钟],
postpublish:DOTNET发布 - iis的--publish文件夹%发布:OutputPath%--framework%发布:FullTargetFramework%]
}, devDependencies:{
吞掉:^ 3.9.1
吞掉干净:^ 0.3.2
吞掉-CONCAT:^ 2.6.0
吞掉少:3.0.2
吞掉-TSC:^ 1.1.5
一饮而尽,打字稿:^ 2.13.1
精简版服务器:^ 2.2.0
路径:^ 0.12.7
rimraf:2.3.2
打字稿:^ 1.8.10
分型:^ 0.8.1
}
}
更好地迁移您的配置设置JSON文件,如appsettings.json,然后用startup.cs设置configurationbuilder这些文件作为配置源。
I have a working web.config as shown below:
<?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="dotnet" arguments=".\Example.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>
But somehow Visual studio is updating my web.config to:
<?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="\\?\%home%\LogFiles\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>
This works in Visual studio through the publish menus (and works once deployed to an azure web app). If I however use dotnet CLI such as dotnet publish, it doesn't work as it keeps that web.config with the variables: %LAUNCHER_PATH% and %LAUNCHER_ARGS% instead of my desired: dotnet and .\Example.dll .
Note: My build server doesn't pollute the web.config when using dotnet restore and dotnet build via command line. Nor when using MSBuild to build my sln. I have visual studio 2015 locally and on my build server and I have verified my command line versions match for "dotnet" cli.
How can I not fight Visual studio by rolling back my web.config before every commit? I am clearly doing something wrong that should be an easy configuration fix?
Update:
Startup.cs
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
Appsettings.json
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
Program.cs
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
Project.json
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true,
"exclude": [
"wwwroot",
"typings",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
},
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
}
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview2-final",
"imports": "portable-net45+win8+netstandard1.6"
},
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"imports": "portable-net45+win8+netstandard1.6"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"netstandard1.4",
"dnxcore50"
],
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
"Microsoft.AspNetCore.Hosting": "1.0.0",
"System.ServiceModel.Primitives": "4.1.0",
"System.ServiceModel.Http": "4.1.0",
"System.Private.ServiceModel": "4.1.0",
"Presentation.Common": "*",
"System.Runtime": "4.1.0",
"System.Runtime.Numerics": "4.0.1",
"SharedContract": "*"
}
}
},
"runtimes": {
"win10-x64": {},
"win10-x86": {},
"win8-x64": {},
"win8-x86": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "gulp rebuild", "gulp min" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.0",
"gulp-less": "3.0.2",
"gulp-tsc": "^1.1.5",
"gulp-typescript": "^2.13.1",
"lite-server": "^2.2.0",
"path": "^0.12.7",
"rimraf": "2.3.2",
"typescript": "^1.8.10",
"typings": "^0.8.1"
}
}
Better to migrate your configuration settings in json files like appsettings.json and then set these files as configuration source using configurationbuilder in startup.cs.
这篇关于ASP.net 1.0核心web.config文件被覆盖造成CGI例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!