created sample project using "dotnet new webapi" command, then removed Properties/launchSettings.json(to understand what happens if this file is not present). On running the project using "dotnet run" command, the project runs, but on accessing the url - https://localhost:5001/swagger/index.html, i get HTTP ERROR 404. But if i run the same project in debug mode(hit f5), i get the swagger page. No change in code or settings was done, while running through "dotnet run" or f5, no error received while "dotnet run". Not able to understand the following:
why 2 different behaviors when running the code using above steps
the reason i removed launchsettings.json was to identify, which other setting forces the use of port 5000/5001 and protocol http/https.
Thanks in advance
I'm not getting the behavior you're observing. An ASP.NET Core project created from scratch listens to 5000 and 5001 ports by default even without launchSettings.json.
That said, you have a couple of options to set which addresses an ASP.NET Core app will listen to:
From Andrew Lock's article. Also from docs
UseUrls() Set the URLs to use statically in Program.cs
Environment variables - Set the URLs using DOTNET_URLS or ASPNETCORE_URLS.
Command line arguments - Set the URLs with the --urls parameter when running from the command line.
Using launchSettings.json - Set the URLs using the applicationUrl property.
KestrelServerOptions.Listen() - Configure addresses for Kestrel server manually using Listen().
dotnet run command checks launchSettings.json for configuration, if it doesn't find anything, it tries a couple more things before letting Kestrel use its default ports :5000 and :5001 for http and https respectively.
Related
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
When I publish my .NET core app to a development IIS server, I make a call to the API and the method works fine locally. This method makes a Db call using a connection string stored in
appSettings.json as well as appSettings.Development.json
Observations:
- Yes, I have ASPNETCORE_ENVIRONMENT = Development and I have both an appSettings.json file AND appSettings.Development.json file
- So I started looking at the published files and I had BOTH of these json files in the published folder, even though appSettings.Development.json properties is set to "Build Action" = content and Copy to Output Directory = Do Not Copy
- If I comment out the code that his the Db, and return dummy data, and republish the api, i get the results fine with no complaints about "development mode"
Error I get when calling the API trying to hit the Db
Error.
An error occurred while processing your request.
Request ID:
0HLL1GOCEHH73:00000001
Development Mode
Swapping to the
Development environment displays detailed information about the error that occurred.
The Development environment shouldn't be enabled for deployed applications.
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the
Development environment by setting the
ASPNETCORE_ENVIRONMENT environment variable to
Development
and restarting the app.
Questions:
- The Db connection strings are in both
[ update ]
Brain-fart! The db connection strings were using 'trusted', so no wonder they worked locally! Once I put in the credentials, and re-published, things worked like I expected. However, the error message threw me off.
Im still not sure why I have both of those appSettings files published? Which one will it use?
I am assuming your appsetting files are named as following:
appSettings.json
appSettings.dev.json
typically, you have to explicitly set the environment to dev. if you use Visual Studio for development, it sets an environment variable that tells the application to put it in dev mode.
Without seeing the initializing logic, I would say in prod it will use the appSettings.json.
Take a look at this article, it explains configuration in more details.
I'm trying to test running .net core on a different port when using the service.
However, I keep on getting an error with a status code 140.
This occurs in my two attempts :
1) adding --server.urls=http://0.0.0.0:555 in the service file
ExecStart=/usr/bin/dotnet /dotnetcore/published/TestingWebApi.dll
2) adding UseUrls("http://0.0.0.0:555") in the Program.cs
When I run it manually using the code
dotnet run --server.urls=http:0.0.0.0:555 it works.
Anybody has managed to get it using the service?
use the following
ExecStart=/usr/bin/dotnet /dotnetcore/published/TestingWebApi.dll --urls http://localhost:5002
I am attempting to run the default ASP.NET Core Web Application (Web Application Template in VS 2015) via IIS.
I have followed the instructions from the docs here eg setting up a 'No Managed Code' application pool and pointing the Physical Path at the location of the web.config file.
When I attempt to browse to the website root, http://localhost I am getting this error:
HTTP Error 502.3 - Bad Gateway There was a connection error while trying to route the request.
Most likely causes: The CGI application did not return a valid set of
HTTP errors. A server acting as a proxy or gateway was unable to
process the request due to an error in a parent gateway.
The event viewer states:
Failed to start process with commandline 'dotnet ./bin/Debug/netcoreapp1.0/WebApplication2.dll', Error Code = '0x80004005'.
This error shows I have replaced the placeholders
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%"
in web.config with the required values
<aspNetCore processPath="dotnet" arguments="./bin/Debug/netcoreapp1.0/WebApplication2.dll"
(update: these placeholders are replaced when you publish)
As per the troubleshooting instructions I have installed .NET Core Windows Server Hosting Bundle and restarted the server.
Running from the command line via dotnet works
Wondering what to try now.
Ok I figured my issue out. I am pointing the physical path in IIS to the unpublished Visual Studio project root directory. This works in previous versions of .net (ie non dotnet core aspnet projects) but doesnt now.
If you really want this to work then you have to publish your app to a temporary folder and copy the Microsoft.AspNetCore.* binaries back into the bin\Debug\ folder along with the refs and runtimes folders
This is a generic error for when IIS can't find the specified .NET Core components ,and doesn't know where to forward requests. In addition to following the official IIS publishing guide, make sure you have:
Installed the correct versions from the download page for latest .NET Core releases
Specified the correct library versions (explicitly or with wildcards) in your project.json
Included a web.config file (preferably using the publish-iis tool), and that the <aspNetCore> key values have been replaced with local values (source, with examples)
I ran into this while setting up a Core 1.0.0 (final) website on a new Windows 2008 Server. Turns out I had mixed up some of the installers from my dev machine with newer versions, and had mismatched library versions (RC2 vs final). Reinstalling the Server Hosting package fixed the problem.
The key to troubleshooting was to get into the console and use the dotnet commands (and resulting error messages) to iterate until I had my site running from the console, since the IIS error page in the browser was useless. I also found some benefit in a few entries in the system Error logs, but not much.
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?