How to define launchUrl in IIS Express config file - asp.net-core

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?

Related

IIS didn't send static file reqest to aspnetcore

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.

HTTP Error 500.30 (Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the file specified.)

I am trying to deploy the asp.net core Web API to the IIS. This application works perfectly fine on the Visual studio and also when I run the dll using the dotnet command. This application has the certificate for signing the JWT token. After deploying the application to IIS I am getting "HTTP Error 500.30 - ANCM In-Process Start Failure" and I checked the windows log and error message is
Host terminated unexpectedly.
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the file specified.at Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(Byte[] rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags)......
I checked the file path and file name everything is correct but some reason IIS is not able to load find the certificate file. Also, I checked the permission and it also looks good. Not sure why I am getting this error message
Also, I ran the same application dll file using the dotnet run command where IIS is pointing to but I am not getting any error. I am getting this error only after deployng to IIS.
On startup.cs file and configuration method I am getting error on this line.
var cert = new X509Certificate2("test_cert.pfx", pwdFrmVault);
I after searching for this error and googling, this solution worked for me. IIS Manager->application pool -> advanced settings ->Under Process model, Load User Profile to true. More detail on link

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

stdout message shows "Access to the path 'C:\Windows\system32\config\systemprofile' is denied" as log

I have hosted .net core application on IIS. When i am trying to browse the application, HTTP Error 502.5 - Process Failure error comes up on browser. On checking stdout logs of application, i found that error message is "Access to the path 'C:\Windows\system32\config\systemprofile' is denied"
I am trying to host this application on my local IIS.
This error comes because of required .net core version not installed on server. One has to be careful about version number (eg. 3.1) and then also about whether its hosting bundle or sdk or runtime. In my opinion, hosting bundle is needed when using IIS.

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!