Azure Website Deploys but displays 500 error - asp.net

I've published an app to Azure for the first time. When I go to the site I get an HTTP 500 error saying
The page isn't working. *****.azurewebsites.net is currently unable to handle this request.
Looking at the Live Metrics Stream on the Azure Portal it says
Not available: your app is offline or using an older SDK
This is a .Net Core app.
When I published it there were no errors. It said the build and publishing were successful. I'm not sure what other information I can give to help someone help me resolve this. I'm including some screenshots that may have some helpful information. I've been stuck for a whole day now.
Below is an error from the Azure Portal:
Here is my web.config file:
Here are the general settings from Azure:
Here are some errors from Azure:
Here is the Publish page from Visual Studio (disregard the arrow):

I figured it out.
Earlier I had briefly experimented with using the .net Google Oauth library in my project. I eventually incorporated Oauth by hand and never removed the code for Google Oauth in Startup.cs. This didn't cause a problem locally but, the streaming logs showed an error saying the "ClientID option must be provided". ClientID is related to the Oauth library.
Viewing the Streaming Logs in Visual Studio is what helped me solve this. Maybe this will help someone in the future.

Related

"Adding sign-in with Microsoft" example does not work on my working VDI

Good day everyone!
Background: I have old legacy ASP.NET MVC on premise application running on local windows IIS. I'm investigating ways to integrate this application with Azure AD authentication. As far as I can understand (Windows IIS integration with Azure AD) it's not possible to do it directly because of the Azure AD authentication can be added at the application level only. So I'm thinking integrating one of the MSAL library for adding Azure AD authentication.
Using this windows manual (Quickstart: Add sign-in with Microsoft to a web app), I've downloaded sample windows application (ASP.NET code sample) from this learn page and tried to run it within the Visual Studio 2022 in debug mode on my azure virtual work machine (based on VDI platform).
And Azure AD authentication does not work. When I click "Sign in with windows" button on the start application page, I get the error:
Server Error in '/' Application.The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.
Requested URL: /login.aspx
This sample works fine on my local laptop in exactly the same state. I suggest that any security utilities might be the reason, but I don't know how to check it. I can't disable security apps on my working machine, and maybe there are any restrictions on the network level I don't even know nothing about.
Could somebody suggest any ways to solve this problem? Or maybe still ways to find the reason of this problem?
Thank you in advanced!

Why is my WebAPI making calls to https://dc.services.visualstudio.com/v2/track?

I am running Visual Studio 2022 (17.0.2), and I just created a new Web API Core project from the template. I enabled Microsoft Identity as the identity provider (Azure AD).
Then I ran the solution and it brings up swagger. I did a "Try It Out" on the WeatherForecast operation. (Which failed with a 401 because the template does not enable swagger's security abilities.)
But the odd part is that in my Chrome DevTools, after the 401 line, I got this:
Why is my new project (from the standard Web API Core template) making calls to an external site? I don't have anything in my code referencing https://dc.services.visualstudio.com/v2/track. There are strict privacy laws around the code I write, and I get very nervous when there are suddenly random calls to unknown URLs.
I did some googling, and it seems this is related to something called "Microsoft Telemetry" or "Application Insights". But all the fixes that I can find have you removing or disabling code that does not come in the default WebAPI template. Like this answer.
I did see a fix that had you modify the hosts files so that the traffic would not leave your machine. That seems like it would work, but then I have to get this change done to my production machines (which I would rather not).
Why is this in there by default?
And more importantly how can I remove it so that it is not in my code when it is deployed to production?
I believe it's this bug https://developercommunity.visualstudio.com/t/Visual-Studio-2022-Application-Insights-/1578628
The fix is to upgrade your Visual Studio (for example 17.3.0 as of June 2022).

Where can I see logs or details for error Azure "An error has occurred." for an API call on Azure?

I have an ASP.NET API and works great as local and using Postman.
Then I decided to publish to Azure since I tried on other free host SOMEE and never worked.
Principal API page on Azure works fine but when I tried to call a controller shows the error
{"Message":"An error has occurred."}
and I don't even know where to check more details about this error.
I tried the same on a Somee.com host and same thing happens
Azure portal offer to you some resources to investigate your issue
Log stream (in your App Service page, under Monitoring section), can give you some info of you api call.
Advanced Tools (in your App Service page, under Development Tools), can give you more information of your app settings, deployment info, wwwroot folder, etc...
It can be a deployment issue(related to the app service configuration, maybe you are using a docker container?) or a simple error in your connection string, so review your app service settings:
it's usually one of these(some) problems.
all the best

Application Insights extension breaking Azure web app

I had Application Insights running smoothly on an Azure Web App via the AI SDK, reporting to an AI instance hosted in Azure.
The only niggle was it didn't show detailed dependancy diagnostics, according to this page this was because I was using the SDK only, I needed to "Instrument your web app on the server", which looking at the docs can't be done if you already have an instance of AI running....helpful!
Reluctantly I deleted the AI instance, stripped the SDK from my code so I was starting fresh, and followed the steps, however as soon as I finished the process in the previous link my website broke and now responds to every single request (MVC5 and Web API) with an empty 404 request
The AI status page is showing green ticks for everything, and I can't discern anything from diagnostic log dump from KUDO or manage to remotely debug the site.
Deleting the AI extension under Web App -> Extensions in the Azure portal and then restarting the web app fixes the problem.
I've run out of ideas on how to fix this, is there anything else I can do to get to the bottom of the problem?
To fix this problem, delete the following 2 files from your web app's (or slot's) filesystem:
D:\home\siteextensions\Microsoft.ApplicationInsights.AzureWebSites\Instrumentation32\ProductionBreakpoints_x86.config
D:\home\siteextensions\Microsoft.ApplicationInsights.AzureWebSites\Instrumentation64\ProductionBreakpoints_x64.config
You can do this easily through Kudu.
Edit: Apparently this is/was an issue with the ProductionBreakpoints interacting with precompiled views. Microsoft has informed me a fix should be out within the next couple days. The version of Application Insights extension I have now that is still broken is 2.4.6 - I will post the "fixed" version when I can confirm it.
Edit 2: Confirmed this is fixed in 2.4.7 which is out now.

ASP.NET Core 2 Web API, Azure publish issue

I have created a sample Web API that returns some sample data from an SQLite database which is included in the project.
I am able to browse and run the API on my local computer. This is all good.
I am also able to publish that API on Azure, all files are getting deployed I am getting "Publish successful" message as expected.
After, whenever I try to browse the azurewebsites.net domain, it doesn't browse it at all.
Once I create empty web site/web app, I am able to browse the welcome page on azurewebsites.net. But once I publish the API, I am getting 404 not found error, 503 error or IIS 502.5 error.
I tried to change settings from Azure portal, all settings seems good, .NET framework version is set to 4.7, as well as my project is too. Anyone has any idea?
I found the problem
I was using SQLite DB, and my SQLite database was open in a database editor. So, Even though Visual Studio published the database, the database file was 0 byte since it was in use and locked.
I think this is short of a bug. If Visual Studio says I published it successfully, I believe it. Obviously it wasn't successful at all. I reported this as a bug to the VS team.
So, making sure non of your files are in use is a good idea to check.

Resources