c# - c# Webapi azure 发布错误:getaddrinfo ENOTFOUND
问题描述
我开发了一个.netcore webapi backend
并尝试将其发布到 Azure。
如果我在本地运行它,它可以完美运行,但是当我将它发布到 Azure 时,它就不再工作了。
我总是收到这个错误:
错误:getaddrinfo ENOTFOUND www.xxxxx.azurewebsites.net
我不明白为什么,这是我的创业公司,其他任何事情都非常标准。
public class Startup
{
private string _cors = "corsPolicy";
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public delegate IStorageService ServiceResolver(string key);
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddControllers()
.AddJsonOptions(o =>
{
o.JsonSerializerOptions.IgnoreNullValues = true;
#if DEBUG
o.JsonSerializerOptions.WriteIndented = true;
#else
o.JsonSerializerOptions.WriteIndented = false;
#endif
});
services.AddCors(o => o.AddPolicy(_cors, builder =>
{
builder
.AllowAnyOrigin()
// .WithOrigins("http://localhost:4200")
.AllowAnyHeader()
.AllowAnyMethod();
}));
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>
(options => options.SignIn.RequireConfirmedAccount = false)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
var jwtBearerProvider = new JwtBearerProvider(Encoding.ASCII.GetBytes(Configuration["Jwt:SecretKey"]));
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
{
x.RequireHttpsMetadata = true;
x.SaveToken = true;
x.TokenValidationParameters = jwtBearerProvider.ValidationParameters;
});
services.AddAuthorization(o =>
{
o.AddPolicy(AuthPolicies.AdminOnly, builder => builder.RequireRole(Roles.Admin));
o.AddPolicy(AuthPolicies.EditorsOnly, builder
=> builder.RequireAssertion(c => c.User.IsInRole(Roles.Admin) || c.User.IsInRole(Roles.Editor)));
});
services.AddSingleton(jwtBearerProvider);
services.AddScoped<ApplicationUsersService>();
services.AddScoped<IUserClaimsPrincipalFactory<ApplicationUser>, AppClaimsPrincipalFactory>();
services.AddScoped<...interfaces..., ...implementations...>();
services.AddControllersWithViews();
// .AddRazorRuntimeCompilation();
services.AddRazorPages();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var rewriteOptions = new RewriteOptions().AddRedirectToHttpsPermanent();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
// app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
rewriteOptions.AddRedirectToWwwPermanent();
}
app.UseRewriter(rewriteOptions);
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".webmanifest"] = "application/manifest+json";
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});
app.UseRouting();
app.UseCors(_cors);
app.UseStatusCodePages(async c =>
{
if (c.HttpContext.Response.StatusCode == 401)
{
c.HttpContext.Response.Redirect("/Account/Login");
}
});
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseAuthentication();
app.UseAuthorization();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseEndpoints(e =>
{
e.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
e.MapRazorPages();
});
}
}
我尝试在同一个服务应用程序上发布另一个 webapi 项目并且它可以工作,所以我很确定问题出在这个启动的某个地方或我周围某处的配置中。
我错过了什么?
解决方案
推荐阅读
- c# - 自动生成的 C# 客户端应该如何处理可以返回不同类型的 API 调用?
- typescript - 为什么我的 FormData 对象总是空的?
- python - 找不到入口点 mkl_blas_dgem2vu
- javascript - 如何在 JavaScript 中使 replace() 成为全局变量
- c# - c# selenium chrome webdriver shift + enter richtexbox
- sql - 计算 SAS 中的列累积总和和百分比
- c - 从 C/C++ BLPAPI SDK 访问 C 接口
- java - 两种方式 web 服务通信 REST
- java - 从 YAML 文件中读取
- asp.net-core - ITelemetryProcessor 中断依赖跟踪