0

Due to my limited reputation point (as I am still new to StackOverflow), I am unable to comment on other posts, so I have to create a new question. However, this does not appear to be the same problem indicated in the post .net-core-2.0 azure app service 502.5 error. I am not getting the 502.5 error but rather this message:

enter image description here

I did perform the steps in the other post anyway to no success. I am still getting the same problem shown above. I even completely deleted my Asp.Net Core 1.1 app service and related SQL database and then re-created a new one to host my Asp.Net Core 2.0 app service. Still, no success.

Does anybody have any fresh ideas about how to fix this problem?

Thank you for your feedback.

UPDATE:

I got the following error:

SqlException: Login failed for user 'null'. System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConne‌​ctionPoolIdentity identity, SqlConnectionString connectionOptions, object providerInfo, bool redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, bool applyTransientFaultHandling)

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35
  • Have you enabled the [developer exception page](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling), could you show more details about the error? Moreover, does your application could work well in your local side? – Bruce Chen Nov 13 '17 at 08:01
  • Thank you for your feedback Bruce. I do have the developer exception page enabled in the Startup.cs file. However, that is only useful while running in Development mode. The application works perfectly in development on my desktop. The problem is when I publish the application to the Azure App Service I get the message shown above in the browser when I navigate to the web address after the publish. This does the same thing whether I use VS publish or Team Services Build/Release... –  Nov 13 '17 at 17:19
  • I did an experiment with a simple non-database enabled Asp.Net Core 2.0 MVC project. I published it using the Visual Studio publish and it worked fine. The website came up with no issues. My suspicion is now that there might be a problem either with the database integration (using SqlServer) or possibly a NuGet package that I may have added to the project. I'm still trying incremental experimentation. –  Nov 13 '17 at 17:19
  • Does your solution work locally? – aaronR Nov 13 '17 at 17:24
  • I recommend you could enable `app.UseDeveloperExceptionPage();` in your production mode to quickly narrow this issue. Also, you could [Remote debugging web apps](https://learn.microsoft.com/en-us/azure/app-service/web-sites-dotnet-troubleshoot-visual-studio#remotedebug) and follow [Troubleshoot HTTP 502 & 503](https://learn.microsoft.com/en-us/azure/app-service/app-service-web-troubleshoot-http-502-http-503). – Bruce Chen Nov 14 '17 at 01:53
  • Yes, @aaronR it does work perfectly fin in dev on my local computer. –  Nov 14 '17 at 19:03
  • Thank you @BruceChen for this suggestion. I did try it and when I deployed the application using Visual Studio Deployment, I got the following error: SqlException: Login failed for user 'null'. System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, object providerInfo, bool redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, bool applyTransientFaultHandling) This is clearly an issue with accessing the SQL Server database. Any other ideas? –  Nov 14 '17 at 20:51
  • The strange thing about this issue is that I have no problems at all when deploying the Asp.Net **Core 1.1** MVC version of the same application. It is only when trying to deploy the Asp.Net **Core 2.0** MVC version of the app that I am having troubles. –  Nov 14 '17 at 21:02
  • How did you configure the connection string, could you show your `appsettings.json`? Also, you could provide the tutorial you followed for us to narrow this issue. Or you could check this [tutorial](https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro). – Bruce Chen Nov 15 '17 at 03:25

1 Answers1

1

I just did a migration for our Azure web app from ASP.Net Core 1 to 2.0. It also uses Azure SQL. Interestingly it didn't throw any SQL related errors as you experienced. Here are some note hopefully helpful to you:

  1. use 'Tools|Nuget package manager' to update all components to the latest 2.0 version, including ASP.Net Core and EF Core.

  2. fix errors shown after the updates. Some are easy to fix simply following the visual studio suggestions. Some might be tricky, and needs a lot of googling and researching. the key places needs to be careful are shown below:

  3. in Program.cs:

    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }
    
    
    public static IWebHost BuildWebHost(string[] args)
    {
       return  WebHost.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    var env = hostingContext.HostingEnvironment;
                    config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
                    config.AddEnvironmentVariables();
                })
                .ConfigureLogging((hostingContext, logging) =>
                {
                    logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                    logging.AddConsole();
                    logging.AddDebug();
                })
                .UseSetting("detailErrors", "true")
                .UseStartup<Startup>()
                .UseSetting("DesignTime", "true")
                .CaptureStartupErrors(true)
                .Build();
    }
    
  4. startup constructor becomes:

    public IConfiguration Configuration { get; }
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }
    

    in ConfigureServices methods,

            // authentication cookie
        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath = "/"; //new Microsoft.AspNetCore.Http.PathString("/");
                options.AccessDeniedPath = "/"; //new Microsoft.AspNetCore.Http.PathString("/");
            });
    
        // Add EntityFramework's Identity support.
        services.AddEntityFrameworkSqlServer();
    
        // Add ApplicationDbContext.
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])
            );
    

    In Configure method, I added this for server side debugging:

     public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
            app.UseBrowserLink();
        }
    
  5. on Azure web portal, add a new setting key/value pair, Hosting:Environment Development:

Note: this is for debugging purpose (server-side mainly), and can be removed from production version.

  1. during publishing, check the box to remove additional files at destination:

Here are my lessons learned while upgrading to ASP.Net Core 2.0. If you start from your original project again, the SQL bug might not be there by following one or two points mentioned above.

Joseph Wu
  • 4,786
  • 1
  • 21
  • 19
  • Why set `Hosting:Environment Development:` in a non-development environment? – Alex Wiese Nov 15 '17 at 04:16
  • The app runs fine locally but shows server 500 error. In order to see the detail error messages, I've tried remote debug and logging setting via web.config without success. This method enables the server side error to be displayed which I found very helpful. The original SO is here:https://stackoverflow.com/questions/31992141/show-asp-net-5-error-page-in-azure-web-app?rq=1 – Joseph Wu Nov 15 '17 at 04:19
  • Maybe put a notice that you shouldn't ever do this for a production website. – Alex Wiese Nov 16 '17 at 00:12