0

I am trying to host a .net core application on A2hosting shared hosting windows option, which uses IIS. However, once I used UserSecretsId in the .csproj file for the secret manager, I was getting the 502.5 error. This is odd since production doesn't use the secret manager. After doing some digging I found adding the following line in my .csproj file gets rid of the 502.5 error again:

<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>

Now, I need to store my secrets outside the web folder. I am trying to use the following code in my program.cs to set this up:

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseConfiguration(new ConfigurationBuilder()
                        .AddJsonFile("<path here>")   // line causing issue
                        .Build())
        .Build();

This code brings back the error 502.5. When I comment out the AddJsonFile line alone, the error is gone. I was trying to understand what is wrong with AddJsonFile.

In conclusion, the issue seems to revolve around IConfiguration (with secret manager and AddJsonFile).

Any idea how I can get the AddJsonFile function working? Any good alternates to access an external json file? I am trying for something that is not messy like reading a while file and serializing it into AddInMemoryCollection function. Is the a way to log the errors shown as 502.5? I have noticed that with this errors, middlewares don't run. This means I can't use the ILogger in them.

Neville Nazerane
  • 6,622
  • 3
  • 46
  • 79
  • I doubt that all the 502's are the result of the functionalities you added in general, but rather *how* you added them. There was most likely exceptions being raised in various places for various reasons. When you have an exception raised in Startup.cs, it prevents the process from loading at all, which gives you the 502. It might be helpful to start you app up in the console using `dotnet MyApp.dll`. There, you'll be able to see exceptions that are being thrown, and you can fix them accordingly. – Chris Pratt May 03 '18 at 15:29
  • thanks. but this is a shared hosting service. that don't provide cli access. locally everything works perfectly – Neville Nazerane May 03 '18 at 15:34
  • Then, don't use shared hosting. You can get a full VPS for $5/mo or less. – Chris Pratt May 03 '18 at 15:43
  • i was using VMs for a while now. Needed hosting service for a couple of reasons now. I don't think it is right that we pay more just because there is no knowledge base for shared hosting of .net core yet. That is the main hurdle I find in shared hosting as of now. – Neville Nazerane May 03 '18 at 17:59
  • I had talked to the support. I had posted their response earlier. However, once I managed to resolve the issue, I removed the portion about the support (since their info didn't help) – Neville Nazerane May 11 '18 at 06:20

1 Answers1

0

This error was no longer shown when AddJsonFile("<path here>") showed a valid path. I could use the overload AddJsonFile("<path here>", true) which would ignore this function if the file is not found. This way the 502.5 was resolved once the path was valid. It is however still a mystery as to how an invalid path shows a 502.5 error. I am also not sure if this has something to do with the configuration package.

Neville Nazerane
  • 6,622
  • 3
  • 46
  • 79