得到“ 502-Web服务器在充当网关或代理服务器时接收到无效响应”。在Azure上打开注册页面时出错 [英] Get "502 - Web server received an invalid response while acting as a gateway or proxy server" error when opening register page on Azure

查看:409
本文介绍了得到“ 502-Web服务器在充当网关或代理服务器时接收到无效响应”。在Azure上打开注册页面时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Azure,并且希望在那里发布我的.net core 2应用程序。到目前为止,这很好地建立在我的本地计算机上。我可以注册为用户,所以我知道本地一切正常。我可以看到用户,甚至可以设法注册具有某些声明的某些用户。



我可以将网站发布为蔚蓝:





2。关注使用带有实体框架核心的ASP.NET Core MVC 开始。



3。使用两个连接字符串设置appsetting.json。

  {
ConnectionStrings:{
DefaultConnection: connectiondefault,
azure: connectionazure
},
Lo gging:{
IncludeScopes:否,
LogLevel:{
默认:警告
}
}
}

注意:您还可以在门户网站的数据库中将连接字符串设置为此处,那么您可以在本地对其进行测试,并可以使用调试来进行故障排除。



此外,您可以尝试使用一个连接字符串进行测试,以确保您拥有



4。使用 app.UseDeveloperExceptionPage(); 和启动类中的 app.UseExceptionHandler 方法将显示错误。

  public Startup(IHostingEnvironment env)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile( appsettings.json,可选:true ,reloadOnChange:true)
.Build();

HostingEnvironment = env;
}

public IConfigurationRoot配置{ }
public IHostingEnvironment HostingEnvironment {get; }

//运行时调用此方法。使用此方法将服务添加到容器。
public void ConfigureServices(IServiceCollection服务)
{
if(HostingEnvironment.IsDevelopment())
{
services.AddDbContext< SchoolContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString( DefaultConnection))));
}
else
{
services.AddDbContext< SchoolContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString( azure))));
}
services.AddMvc();
}

如果仍有问题,可以启用诊断日志,请参阅此文章进行故障排除。


I have been playing around with Azure and am looking to publish my .net core 2 application there. So far, this builds on my local machine fine. I can register as a user, so I know everything is okay, locally. I can see users and have even managed to register certain users with certain claims.

I can publish the site to azure:

https://mytrade20180517093224.azurewebsites.net/

I can also log into the azure database from vs2017 using the same credentials I supplied in my appsettings.json. However, the problem I'm getting is my azure site then falls over when you go to register:

https://mytrade20180517093224.azurewebsites.net/Account/Register

I get:

502 - Web server received an invalid response while acting as a gateway or proxy server.

There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.

The authentication type I have is the "individual user accounts" one, I have re-created the tables for this on the azure db I'm referencing. In the startup.cs I'm calling the "DefaultConnection" string if the environment is development and if its not (which I'm guessing Azure wont be by default) calling another connection string, the azure one:

if (HostingEnvironment.IsDevelopment())
{
    services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
else
{
    services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("azure")));
}   

Does azure require something different to be done to pick the connection string? I tried to switch on the some kind of logging on azure but this didn't seem to make any difference. Any one, any clues as to what I could be potentially doing wrong?

解决方案

From your description, you would dynamiclly choose a connection string based on Environment, so I test and here is main steps, please refer to it.

  1. Set the ASPNETCORE_ENVIRONMENT value to azure in webapp>property>debug.

2.Follow ASP.NET Core MVC with Entity Framework Core to get started.

3.Set the appsetting.json with your two connection string.

{
  "ConnectionStrings": {
    "DefaultConnection": "connectiondefault",
    "azure": "connectionazure"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  }
}

Note:You could also set the connectionstring in database on portal to here, then you could test it in local and could use debug to troubleshooting.

Also, you could try to test with one connectionstring to ensure you have no problem with connecting to database.

4.Enable Developer exception page by using app.UseDeveloperExceptionPage(); and the app.UseExceptionHandler methods in your startup class which would display the errors.

        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();
        }

If you still have any problem, you could enable Diagnostics logs on portal and refer to this article to troubleshooting.

这篇关于得到“ 502-Web服务器在充当网关或代理服务器时接收到无效响应”。在Azure上打开注册页面时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆