Tôi đã một web.config làm việc như hình dưới đây:ASP.net lõi 1.0 web.config đã được ghi đè gây ngoại lệ CGI
<?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>
Nhưng bằng cách nào đó Visual studio đang cập nhật web.config của tôi để:
<?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>
Điều này hoạt động trong Visual studio thông qua các menu xuất bản (và hoạt động khi được triển khai cho một ứng dụng web xanh). Tuy nhiên, nếu tôi sử dụng CLI dotnet như xuất bản dotnet, nó không hoạt động vì nó giữ cho web.config đó với các biến:% LAUNCHER_PATH% và% LAUNCHER_ARGS% thay vì mong muốn của tôi: dotnet và. \ Example.dll.
Lưu ý: Máy chủ xây dựng của tôi không gây ô nhiễm web.config khi sử dụng khôi phục dotnet và tạo dotnet qua dòng lệnh. Cũng không phải khi sử dụng MSBuild để xây dựng sln của tôi. Tôi có studio trực quan năm 2015 tại địa phương và trên máy chủ xây dựng của tôi và tôi đã xác minh các phiên bản dòng lệnh của mình phù hợp với cli "dotnet".
Làm cách nào tôi không thể chống lại Visual studio bằng cách quay lại web.config của mình trước mỗi lần commit? Tôi rõ ràng đang làm điều gì đó sai mà phải là một sửa chữa cấu hình dễ dàng?
Cập nhật:
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"
}
}
Tôi đã biết được điều đó đang xảy ra khi tôi nhấp vào chạy trong studio trực quan để xem trang web cục bộ. Vẫn chưa chắc cách khắc phục điều này. – Dessus