【发布时间】:2020-01-28 21:02:57
【问题描述】:
我有一个 Web API Get。这会生成正确的 JSON 响应。当我在 Azure 上运行代码时,应用程序会删除 questions 名称。非常感谢任何帮助!
[HttpGet]
public ActionResult<IEnumerable<Question>> Get()
{
var questions = _repo.GetQuestions();
return Ok(new { questions });
}
本地结果
{
"questions": [
{
"property": "test",
"required": true,
"type": "string",
"label": "test ID",
"constraints": {
"minSize": "9",
"maxSize": "10"
}
},
{
"property": "Email",
"required": true,
"type": "string",
"label": "Email Address",
"constraints": {
"minSize": "1",
"maxSize": "128"
}
}
]
}
天蓝色
[
{
"property": "test",
"required": true,
"type": "string",
"label": "test ID",
"constraints": {
"minSize": "9",
"maxSize": "10"
}
},
{
"property": "Email",
"required": true,
"type": "string",
"label": "Email Address",
"constraints": {
"minSize": "1",
"maxSize": "128"
}
}
]
启动
public void ConfigureServices(IServiceCollection services)
{
var connectionString = string.Empty;
services.AddControllers(configure =>
{
configure.ReturnHttpNotAcceptable = true;//makes sure that content type is requested
});
services.AddDbContext<YLS_FAASTContext>(options =>
{
options.UseSqlServer(Configuration.GetConnectionString(connectionString ));
});
services.AddScoped<IAPIRepo, APIRepo>();
services.AddAuthentication("BasicAuthentication")
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{//prod only show 500 error
app.UseExceptionHandler(appBuilder =>
{
appBuilder.Run(async context =>
{
context.Response.StatusCode = 500;
await context.Response.WriteAsync("An unexpected error has occured. Try again later.");
});
});
}
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
【问题讨论】:
标签: c# .net azure asp.net-core