Azure Web App and .NetCore WebAPI - Missing web.config - azure

From what I understand .NetCore no longer uses/needs web.config -- opting instead for appsettings.json.
I have a .NetCore WebAPI that I am trying to host in an Azure WebApp. I've published the API to the WebApp but I keep getting a 500 error. Looking in the Application logs, I can see that the error is:
IIS was not able to access the web.config file for the web site or application.
I'm confused. If .NetCore uses appsettings.json instead of web.config and Azure won't work without web.config, how is one supposed to host a .NetCore app in Azure?
UPDATE
I now realize that this has nothing to do with web.config thanks to #joey-cai pointing me in the right direction.
It appears that Azure did not like my attempt to use Azure Active Directory Authentication in my Connection String. I changed my connection string to simply use SQL Authentication and everything worked. So I guess my question now is, how do I use AAD Authentication for my connection string rather than SQL Authentication.
This SO thread seems to indicate that my connection string was indeed set up correctly for AAD authentication, but I was getting the error:
Keyword not supported: 'authentication'
whenever I used the connection string like so:
Server=tcp:dbname.database.windows.net,1433;Initial Catalog=dbnamesqldb;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication="Active Directory Password";
Since the question has now changed, I'm going to create a new post with the new question.

does this mean I must have we.config? If so, can it just be an empty file?
When you deploy the .net core project to Azure, you could go to https://xxxxx.scm.azurewebsites.net and click Debug console> CMD > site > wwwroot > web.config. The web.config will be there.
Try to delete the site in azure and recreat the site in azure. Also, try to run the application that you are deploying by running dotnet MyApp.dll and making sure that works. You need more details as to why it’s having an application issue. This might help. Also consider testing using a self contained application. Also try installing the asp.net core extension on the azure app service.
For more details, you could refer to Deploy ASP.NET Core apps to Azure App Service.

Related

Azure database not working after deploying .net core react js project

I am completely noob to Azure. When I try to publish .net core app on Azure. its published and interface is showing, but it seems like database is not working i am unable to submit form data. in console it gives 500 error. here is the link:
Azure site link
There are a few steps that you can follow to solve this.
Check your appsettings.json - Check whether you have put the connection string in your appsettings.json
Validate the connection string - This might be a result of a wrong connection string. You can get the correct connection string from the Azure Database. It's something similar to this (Server=tcp:mssql-care-dev.database.windows.net,1433;Initial Catalog=sqldb-care-dev;Persist Security Info=False;User ID=MsSqlAdmin;Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;)
Replace {your_password} with your actual password. And the SQL server name.
Add a debug point in your application. And then run the local application against the hosted database. This will give you an insight into what's happening.

.NET5 Blazor Server app in Azure App Services returns "You do not have permission to view this directory or page"

I am trying to deploy a Blazor Server app using .NET5 to an Azure App Service via Azure DevOps.
The Blazor app runs and works correctly locally. The Azure DevOps pipeline appears to also be building and deploying correctly. If I use the console in the Azure portal I can see that the files I would expect are in the wwwroot folder (which I guess is correct?). In Configuration > General Settings I can see that the App Service is correctly configured for .NET 5. On the network side there are currently no access restrictions. I've also turned off all auth in the app for now just to make sure that wasn't having an impact.
When I try to access the site at https://my-app.azurewebsites.net (not the real url, just an example in case it's relevant) I get a white page with the following text: "You do not have permission to view this directory or page.". When I look in the Diagnostics dump from the Kudu page I can see more detail error pages which say 403.14 - Forbidden and the message "The Web server is configured to not list the contents of this directory.". If I look in App Insights for the times when I try to access it I can see requests with 403 response too (for some reason with url: http://localhost/). Unfortunately this error seems to cover a multitude of errors and so while I've found various sources with similar problems, none of the solutions I've found so far have had any positive impact.
EDIT: So I did some more digging and I think some files might be missing. I tried creating a new Blazor Server app and publishing it manually via Visual Studio. This worked and the only difference I've found from my app is that I have no web.config, hostingstart.html, or static css/js etc (from wwwroot). None of these files are in the output directory when I build for either my app or the test app I created so it looks like they must be getting added separately by something in the VS manual publish process and Azure DevOps publish step isn't doing it. Still not sure what the correct way to fix this is (or even entirely sure if any or all of this stuff is relevant).
Has anyone out there got any idea what I might be missing?
So after working out what was going on here I was going to delete this but I figured possibly someone else will make the same mistake I did and this might help. Basically I'd copied another deployment pipeline for an Azure function app as the basis for the deployment pipeline for this and in that I just did a dotnet build and that's enough. However it seems for this kind of app to get wholesome output you need to run dotnet publish.

Web app on azure doesn't show my asp.net core web app after I have published it without any problems

Landing Page of my web app
I have published my asp.net core mvc project in the Azure as web app, however it doesn't show anything. Instead of this it just shows the landing page as there was no code (which is not the case). I have checked few points on stackoverflow, but couldn't find anything, could anyone please help me with that?
There are few reasons causing it, you could refer to the following and troubleshoot it.
Go to your kudu site to check whether all your project file have uploaded to azure.
After publishing webapp to azure, wait for a moment.
Make sure you default page is listed in here and is above hostingstart.html
Deploy Continuous to Azure App Service.
Update:
Delete app and republish it.

Azure does not read web.config settings

I have to deploy my (old school) application to Azure using the Web deployment tools/Azure Web Accelerator. I'm not an Azure pro and I havn't set up the whole Azure Publishing enviroment.
Still i can publish my application with Visualstudio to Azure. Never the less when I try System.Configuration.ConfigurationManager.AppSettings["setting"] I get an empty value.
Local on the webapplication I get a value.
So I know that 'RoleEnvironment.IsAvailable' is true and localy isn't still that's the only lead I have. Any help is welcome
Thanks guys but I've fixed it. It's quite simple after all. The Azure Web Accelerator was configured at url service.test.com the site which couldn't read the web.config was a the same base url only a virtual application like service.test.com/shop.
When I changed the service.test.com/shop to run at testshop.shopname.com everything worked. So basicly you can't run both web app/sites on the same url.
If it's OK when using the local simulator? You could RDP to your windows azure virtual machine to have a look on the web.config directly. About how to use RDP on windows azure please have a look
http://msdn.microsoft.com/en-us/library/windowsazure/gg443832.aspx
http://geekswithblogs.net/shaunxu/archive/2010/12/03/remote-desktop-to-your-azure-virtual-machine.aspx

Moving Facebook C# SDK configuration settings to Azure ServiceConfiguration.cscfg

I'm using Facebook C# SDK for an ASP.NET MVC Facebook Canvas application that I'm hosting in Windows Azure.
I currently have the Facebook C# SDK specific configuration settings (appSecret, appId, etc.) in web.config, but I would like to move them to the service configuration file instead so that I can alter the settings when moving from Staging to Production in Azure.
(How) can this be done? Right now I'm using the CanvasAuthorize attribute that automatically reads from web.config.
[CanvasAuthorize(Permissions = FacebookPermissions.ReadStreamPermission)]
public ActionResult Login()
{
return RedirectToAction("Authenticate"); // Logged in, proceed with authentication
}
By default, Facebook C# SDK looks up at the configuration sections in web.config.
You will need to override the default Facebook application using code similar to this.
FacebookApplication.SetApplication(new DefaultFacebookApplication { AppId = "..", AppSecret = ".." });
The best place to set the application is at Application_Start.
You can checkout the sample at https://gist.github.com/820881
This means you are not tied to web.config. You can use database, azure service configuration or anything depending on your logic from where the settings can be retrieved.
I'm not sure about the reasoning of putting application specific configuration information in the Azure ServiceConfiguration.csfg file. Furthermore, I would say that this will be a problem rather than helpful to switch VIP's in the Azure control panel.
They way I do it is to have multiple web deployment configurations in my (ASP.NET MVC canvas page) Visual Studio project. One for Staging and one for Production.
I use the web.config transformation functionality in the Web Deployment to have different web.config settings for Staging/Production.
It works very well and smoothly, just right-click on the project, select Deploy and choose if you want to deploy to staging or production. You can also handle a specific testing AppID for Staging this way.
EDIT: I haven't looked in the source code for the Facebook C# SDK, but I would guess that the web.config read methods are, in fact, hard coded to use the web.config. That would also be a reason to keep it there.

Resources