我想通过在Visual Studio 2017中发布配置文件来部署ASP.NET Core Web应用程序.一切都被复制到目标文件夹并且工作正常,但"site.js"文件除外.在目标文件夹中,我在wwwroot/js文件夹中看到site.js和site.min.js,但后者为空.我在浏览器中也遇到控制台错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
site.min.js
在页面源中,我看到文件正确加载:
<script src="/wwwroot/js/site.min.js"></script>
Program.cs文件:
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
Run Code Online (Sandbox Code Playgroud)
Startup.cs中的服务配置:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: …Run Code Online (Sandbox Code Playgroud) 我们有一个JSON,可以将其反序列化为自定义域模型,一点问题都没有。它包含一个作为自定义枚举的属性:
public enum UserType
{
President,
Chump
}
Run Code Online (Sandbox Code Playgroud)
现在,我们更改了枚举类,但仍然需要接受并反序列化到达的任何JSON的先前值。就像我们现在有两个版本的JSON
public enum UserType
{
President,
Vice-President,
Citizen // Chump maps to Citizen, now.
}
Run Code Online (Sandbox Code Playgroud)
以及json本身。
"userType": "chump"; // needs to map to Citizen
我不确定该怎么做。
这是使用JsonConverter吗?
同样,这是我们用于所有序列化和反序列化的自定义设置。注意:我们将任何枚举序列化为其string描述/值,而不是其int值。
internal static JsonSerializerSettings JsonSerializerSettings => new JsonSerializerSettings
{
Converters = new JsonConverter[]
{
new StringEnumConverter()
},
Formatting = Formatting.Indented
};
Run Code Online (Sandbox Code Playgroud)
干杯!