[英]Azure Websites - 502 - Web server received an invalid response while acting as a gateway or proxy server
[英]Get “502 - Web server received an invalid response while acting as a gateway or proxy server” error when opening register page on Azure
我一直在玩Azure,並希望在那里發布我的.net core 2應用程序。 到目前為止,這很好地建立在我的本地計算機上。 我可以注冊為用戶,所以我知道本地一切正常。 我可以看到用戶,甚至設法注冊了具有某些聲明的某些用戶。
我可以將網站發布為蔚藍:
https://mytrade20180517093224.azurewebsites.net/
我還可以使用我在appsettings.json中提供的相同憑據從vs2017登錄到Azure數據庫。 但是,我遇到的問題是我的azure網站然后在您去注冊時跌倒了:
https://mytrade20180517093224.azurewebsites.net/帳戶/注冊
我得到:
502-Web服務器在充當網關或代理服務器時收到無效響應。
您要查找的頁面有問題,無法顯示。 當Web服務器(充當網關或代理)聯系上游內容服務器時,它從內容服務器收到無效響應。
我擁有的身份驗證類型是“個人用戶帳戶”,我已經在我參考的azure db上為此重新創建了表。 在startup.cs中,如果環境是開發環境,則調用“ DefaultConnection”字符串,如果環境不是(我猜測Azure將默認情況下),則調用另一個連接字符串,即一個蔚藍的字符串:
if (HostingEnvironment.IsDevelopment())
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
else
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("azure")));
}
Azure是否需要執行其他操作來選擇連接字符串? 我試圖打開某種登錄天藍色的功能,但這似乎沒有任何區別。 關於我可能做錯了什么的任何線索嗎?
根據您的描述,您將根據環境動態選擇連接字符串,因此我進行測試,這是主要步驟,請參考它。
2.按照ASP.NET Core MVC和Entity Framework Core進行入門。
3.使用兩個連接字符串設置appsetting.json。
{
"ConnectionStrings": {
"DefaultConnection": "connectiondefault",
"azure": "connectionazure"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
注意 :您還可以在門戶網站上的數據庫中將連接字符串設置為此處,然后可以在本地對其進行測試,並可以使用調試進行故障排除。
另外,您可以嘗試使用一個連接字符串進行測試,以確保連接數據庫沒有問題。
4.通過使用app.UseDeveloperExceptionPage();
開發人員異常頁面app.UseDeveloperExceptionPage();
以及啟動類中的app.UseExceptionHandler
方法, app.UseExceptionHandler
方法將顯示錯誤。
public Startup(IHostingEnvironment env)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
HostingEnvironment = env;
}
public IConfigurationRoot Configuration { get; }
public IHostingEnvironment HostingEnvironment { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
if (HostingEnvironment.IsDevelopment())
{
services.AddDbContext<SchoolContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
else
{
services.AddDbContext<SchoolContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("azure")));
}
services.AddMvc();
}
如果仍然有任何問題,可以在門戶網站上啟用“ 診斷”日志 ,並參考本文進行故障排除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.