IIS didn't send static file reqest to aspnetcore - asp.net-core

I have a aspnetcore 3.1.10 website hosted on windows server 2019 and IIS v10.
It runs InProcess mode.
Static files (js or css) are processed by aspnetcore's StaticFileMiddleware.
Resently, IIS sometimes returned an empty content css or js with http status code 200, and there is no process log in StaticFileMiddleware.
Normally there is log "Sending file. Request path: '"/styles/css/main.css"'. Physical path: '"D:\IIS\XXXXX\wwwroot\styles\css\main.css"'"
I didn't find any errors in aspnetcore logs or event viewer.
Only I can do is restarting IIS to make this issue disappeared for a while, how do I find out what's wrong with my website.

Related

IIS sub application not handling requests after upgrading to .NET 6 - returning 307

After installing .NET 6 SDK + hosting bundle, our application stopped handling requests as before.
The IIS setup is the following :
A root application running on .NET 4.7
Several sub applications running on .NET core 3.1 (out of process)
Haproxy in front, sending unencrypted HTTP requests to the IIS (and signing requests).
The root app works fine, but the subapplication stopped handling requests as before.
After enabling the stdout logs on the sub application, I see the requests coming, but it seems the first URL segment is not handled as it should.
Here's the logs :
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://subdomain.domain.net/subapplication/ping 0
trce: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[2]
All hosts are allowed.
dbug: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[4]
The request path /ping does not match a supported file type
dbug: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[1]
Redirecting to 'https://subdomain.domain.net/subapplication/ping'.
dbug: Microsoft.AspNetCore.Server.Kestrel[9]
Connection id "0HMDA5V61D9BR" completed keep alive response.
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 1.2475ms 307
What seems happening is the request miss the controllers middleware, and go to the next one : the StaticFile middleware.
As if after installing .NET 6, the sub application wasn't aware of it's path name subapplication in the logs.
I tried uninstalling .NET 6 (+runtime+hosting bundle etc), with no luck.
I also tried to force install .NET 3.1, without luck again.
I'm out of ideas in order to restore the previous correct behavior..
What parameter could have such an impact of the sub app first URL segment handling ? and how to fix this ?
Workaround-ed by removing the app.UseHttpsRedirection(); middleware..
But we still don't understand how installing .NET 6 have changed the app behavior on some apps (but not all), and on some IIS servers (but not all).

Cannot run published website that using database

I started to code my new website using ASP.net core
Everything runs properly with development environment: Open VSCode and F5 to run.
But after i publish all of them to IIS, it runs with 404 error
This localhost page can’t be found No webpage was found for the web
address: https://localhost:1111/ HTTP ERROR 404
The error page is displayed when the page connects database to runs backend actions.
Any actions in published web that don't use database such as href to another link, run javascript validation, ... would run with no 404 error
Do I miss anything or make something wrong?
here're the steps that i did to publish my site
open terminal and run dotnet publish --configuration Release
copy publish folder in bin\Release\netcoreapp2.2\publish to the publish folder in IIS setting
open IIS and add application pool with .net CLR version is No managed code
add website with application pool above, bind type is https, hostname is localhost, and tick all 3 checkboxes (Require server name indication, Disable HTTP/2, disable OCSP Stapling), SSL certificate is IIS Express Development Certificate
I forgot the page that guided me those steps
I myself have found the cause. The reason that the web app return a 404 page when I post something to backend to process database is I used windows authentication in my database connection string. So it couldn't access the database when I publish to IIS. When i change connection using sql server authentication, it works properly

How to publish a asp.net web core application on own hosting windows

I have a taken a windows hosting that can run web core 2 applications. I have published first the application to a folder on my pc and then moved the files to a folder on the hosted web site. When I access the folder via http I get the following error message:
HTTP Error 502.5 - Process Failure
Common causes of this issue:
The application process failed to start
The application process started but then stopped
The application process started but failed to listen on the configured port
Troubleshooting steps:
Check the system event log for error messages
Enable logging the application process' stdout messages
Attach a debugger to the application process and inspect
This is a basic application without database, it's the "Hello World" empty Template of Visual Studio. I did this for a test.
The web provider says it does not depend from them. I have no way to know what is going wrong. Any idea?
You can read this blog http://dotnet4hosting.asphostportal.com/post/How-to-Publish-ASPNET-Core-2.aspx. It seems that you havent published your application properly.
Based on my experience, to resolve above error, you need to publish the website/project as a self-contained application. In order to publish it as a self-contained application, please add this to the csproj folder.
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<RuntimeIdentifiers>win7-x64;win7-x86;ubuntu.16.04-x64;</RuntimeIdentifiers>
<SuppressDockerTargets>True</SuppressDockerTargets>
</PropertyGroup>
Hope this help!

ASP.NET Core web app response with 502 error

I'm investigating an issue with the asp.net core 1.1 web app.
We had to install the latest VS 2017 on the build server. And straight after that, all the deployed builds return 502 responses. Nothing changed in the app code or the referenced packages, however, many binaries are different after VS 2017 install. The deployment is done via FTP.
I also noticed there is now a small difference in Http response headers. API Response Headers used to have Server: Kestrel. But now, after installing VS2017, the deployed builds return Server: Microsoft-IIS/10.0. This probably explains 502 error, but why would the Server now switch to IIS?
Managed to fix it. The error is caused because IIS server (proxy) can't access AspNetCoreModule, the process that hosts kestrel. Usually, the reason is because kestrel in some trouble.
The solution starts with checking Application logs in Event Viewer on the server.
In my case it was:
Application 'MACHINE/WEBROOT/APPHOST/MyApp.API' with physical root '\servername\c$\inetpub\wwwroot\MyApp.Api\' failed to start process with commandline '"dotnet" .\MyApp.Api.Web.dll', ErrorCode = '0x80004005 : 80008083.
So, by googling the error code I've realised that the server didn't have the right asp.net core version (for some reason).
Downloaded the installer, works fine now! :)

How to define launchUrl in IIS Express config file

I have created a basic .NET Core 3 API app with the default settings. It has only one controller called "WeatherForecastController". In the "launchSettings.json", the launchUrl setting was set to "weatherforecast" under "IIS Express" profile. By clicking on the run button in Visual Studio, I can easily run the project.
But I wanted to run the app via IIS commandline, so what I did was running the below in cmd.exe
iisexpress.exe /config:C:\Users\User\source\repos\SingleExecWebApp\.vs\SingleExecWebApp\config\applicationhost.config /site:SingleExecWebApp
The app runs, and I got the following error
HTTP Error 500.0 - ANCM In-Process Handler Load Failure
The IIS console emits the following info
Starting IIS Express ...
Successfully registered URL "http://localhost:61517/" for site "SingleExecWebApp" application "/"
Successfully registered URL "https://localhost:44325/" for site "SingleExecWebApp" application "/"
Registration completed for site "SingleExecWebApp"
IIS Express is running.
Enter 'Q' to stop IIS Express
I think what I am missing is the previously mentioned "launchUrl". Am I correct? if yes, how to set it in the above command I ran in cmd.exe. If no, what I am I missing?