使用本地IIS上托管的dot net Web API进行工作,每次尝试从开发中的移动应用程序调用API时,都会收到内部服务器错误(500)。经过几个小时的调试,我复制了正在Chrome上使用的波纹模拟器将其发送到API的方法,并尝试手动执行get操作。我注意到的是,在指定本地主机url和所有必要的内容之后,浏览器尝试通过google搜索而不是使用指定的地址。
> public class Program
> {
> public static void Main(string[] args)
> {
> CreateWebHostBuilder(args).Build().Run();
> }
>
> public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
> WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
上面的程序文件,下面的启动文件
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddCors(options => options.AddPolicy("AllowCors", p => p.AllowAnyOrigin()
.AllowAnyMethod()
.AllowCredentials()
.AllowAnyHeader()));
services.Configure<IISOptions>(options =>
{
options.ForwardClientCertificate = false;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseCors("AllowCors");
app.UseHttpsRedirection();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseCookiePolicy();
//app.UseMiddleware<RequestResponseLoggingMiddleware>();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Account}/{action=Login}/{id?}");
});
}