ClickOnce, Azure, and ASP.NET Core - asp.net-core

I have an ASP.NET Core application published to Azure. It contains companion application published using ClickOnce.
When I look at the web server's console, I see all of the necessary ClickOnce files. And I can launch the application using http://mysite.azurewebsites.net/tools/MyApp.application as expected.
But if I click on http://mysite.azurewebsites.net/tools/setup.exe it fails with a 404 error.
I'm assuming that the ASP.NET application is preventing "setup.exe" from being exposed, but I don't know how to alter that configuration.

Related

Can I run .Net 4.6 Application under .Net Core Site on IIS

I inherited a project that is a collection of WCF Services that target .Net Framework 4.6.1. I wrote a front end SPA application that targets .Net Core 2.2 not realizing that the hosting model was such that both the UI (.Net Core) and the API (.Net 4.6.1) need to run under one Site on IIS.
I'm trying to get this to work on my local machine. I created a new Site in IIS -- Site A. I published my .Net Core application to Site A and set it up with an application pool set to "No Manged Code".
I then added an Application to Site A called API and added all my WCF services in that folder. I configured API to use an application pool that targets ".NET CLR 4.0".
I updated the web.config in the root of Site A to include all the necessary bits for WCF.
I'm able to hit Site A and get my SPA UI, but when I do anything that attempts to hit the backend API (including trying to hit it directly -- http://localhost:464646/api/test.svc), I get the following error:
HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure
Is what I'm doing even possible? If so, what changes do I need to make in order to get this to work?

Get HTTP 500 error hosting ASP.Net Core MVC app in IIS

I am new to ASP.Net Core and trying to host my first simple MVC app in IIS. I have installed the IIS hosting bundle; published my MVC project to a folder using Visual Studio and then, created an IIS website with it's physical path set to the published folder. When I test it using url http://localhost:5008/home/CallApi, however, I am getting a 500 error that says "This page isn’t working. localhost is currently unable to handle this request.". I can run the MVC app from within VS (selfhost, not through IIS, on a different port), it works fine there. What am I doing wrong here?
If you want to deploy ASP.Net Core MVC applications to IIS, you need to install the .NET Core host bundle, otherwise "500 Error" will appear. If you successfully install the .NET Core host bundle, you can find AspNetCoreModuleV2 in Modules:
Download the installer using the following link:
https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.9-windows-hosting-bundle-installer
After adding the site, you need set the .NET CLR version to No Managed Code:
For more information about using IIS to host ASP.NET Core on Windows, you can refer to this link:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1
UPDATE:
I suggest you enable viewing of PII logs so that we can view more detailed information about the error:
public void ConfigureServices(IServiceCollection services)
{
IdentityModelEventSource.ShowPII = true;
....
You can refer to this link, which contains similar questions:
"InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]'"
For those with the same issue, I found that no setup guide I found mentions what was, for me, a required step:
Open IIS Manager
Navigate to [Server]\Sites[Your site]. A folder is listed for your .NET application, but the icon shows as an ordinary folder, as if in Windows Explorer.
Right-click the folder and select, "Convert to Application".

HttpContext is NULL when running web app in IIS

I have two application, both running on the same Windows machine. One application is IdentityServer4, and the other is my own web application (Server side Blazor app).
Both web apps are build with .NET Core 3.1.
When I navigate to my web app, I first get redirected to my IdentityServer4 app. I login, and after that I get redirected back to my web app.
The login was successful, because there are no errors in the logs of IdentitServer. Also, I see a certain claim value on my Blazor webpage. I display this claim through CascadingAuthenticationState in my Blazor page. Through that path everything works fine.
But, whenever I try to get the logged in user through HttpContext in my "code behind" files, I get a Null reference back. For example:
public UserService(IHttpContextAccessor httpContextAccessor)
{
// HttpClient is NULL...
var httpCtx = _httpContextAccessor.HttpClient;
}
The strange thing is, that it all works fine when I run my application locally in Visual Studio. When I debug in Visual Studio I see that the HttpContext is set with all my user data.
But, for some reason HttpContext is NULL when I run the app from IIS.
How can I solve this issue?
If the HttpContext null-reference exception happens after deployment to Azure App Services or IIS, you might have forgotten to enable WebSockets.
Here is the deal:
If the app runs on Windows with IIS: WebSockets must be enabled.
See the IIS/IIS Express support section.
It seems that this is a prerequisite that you have to follow. I only recently discovered this myself after dealing with the same issue and deciding to publish my app to Azure from within Visual Studio. After I did so, Visual Studio gave me a nice warning telling me to enable WebSockets protocol on the Azure App Service.
To enable websockets in azure app service. Open app service in azure portal -> configuration -> general settings -> websockets on or off. Described here

Why publishing to IIS is change for ASP.net core ?

When I publish under Visual Studio 2015 CTP 5 then I don't have to do setting for application pool CLR version.
Now for ASP.net core application and as per documentation (http://docs.asp.net/en/latest/publishing/iis.html) we have to do setting for application pool clr to No managed code.
Why it is like that ?
ASP.NET Core applications no longer run inside IIS but run out-of-process and IIS acts only as a reverse proxy. This functionality is provided by the AspNetCoreModule which is a native IIS module. Since no managed code runs in the IIS process it is recommended to set application pool as "No managed code".
I wrote a detailed blog post describing how ASP.NET Core applications are running with IIS. You can find it here.
This is because ASP.NET Core runs as a plain old command line application outside of the IIS. Therefore, IIS is merely a pass-through to Kestrel, which is the ASP.NET Core web server which runs in it's own separate process. This platform is what provides the cross-platform capabilities of .NET Core.

ASP.NET Core Application Initialization on Azure

I'm trying to implement Application Initialization (warm up) on an ASP.NET Core web app running on Azure, as described for IIS 8.
The way it's described is changing web.confg to enable and configure it.
But in asp.net core we (almost) don't have web.config.
So, how do we configure Application Initialization (or any other feature that require
changing web.config)?
I finally figured out, for this question and any other that requires IIS to be configured through web.config:
It's not true there isn't web.config anymore. It's true that it doesn't play any role in the asp.net core app, but you can find a small web.config file in wwwroot project folder, which is what tells IIS how to handle the asp.net core app.
So for implementing this, or for example urlrewrite, you just need to add IIS configuration to that web.config file as it's being deployed as part of the application.