question

bisondev-4989 avatar image
0 Votes"
bisondev-4989 asked ryanchill edited

Azure App Service running .net 5 API displaying Runtime error

Hi All,

I have recently deployed my .NET 5 API to an Azure App service, running .NET 5 as well. I have set up a CI/CD pipeline and release pipeline in Azure DevOps, which runs without issue. However when I try to access my API from the URL (which should open a swagger page), I see this:

140431-image.png


I have followed the instructions on the screen and modified my web.config so that it looks like the following:


140357-image.png


However I still see the same message when I try to visit my API. I am developing on a windows machine, using Kestrel, and I have no problems locally. I have checked the web.config on the App Service itself and it looks the same as my local web.config. The Azure App Service OS is: Microsoft Windows NT 10.0.14393.0.

I would really appreciate any assistance here! I've been stuck on this problem for a while and the other posts that I have reviewed on this topic haven't helped much... Thanks in advance!

azure-webapps
image.png (130.4 KiB)
image.png (23.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ryanchill avatar image
0 Votes"
ryanchill answered bisondev-4989 commented

First thing is to enable logging on your app service; see https://docs.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs to enable those logs. This will give you a better idea of what the runtime exception is. .NET Core bootstrapped project will have the following snippet in the ConfigureServices method in the Startup class.

if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

Adding ASPNETCORE_ENVIRONMENT set to Development will show the developer style exception page rather than this one. However, it's not advised to leave this setting permanently as it can display sensitive information. With regards to your Swagger, make sure you've added UseSwaggerUI() middleware to your ConfigureServices method as well. Feel free to look at my Startup.cs for reference.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @ryanchill !

Using your advice I was able to activate the logs properly and take a closer look at the root cause. The main issue was that my app service couldn't find my web.config because I had set the path mappings setting for the root of the application to be home/site/wwwroot/api which wasn't a valid path. I set it instead to home/site/wwwroot and it works great now!

Cheers.

1 Vote 1 ·