https - ASP.NET app is not listening on port 5001 after deployment - Stack Overflow
I'm developing an ASP.NET Core project recently upgraded from .NET 6 to .NET 9, in VS 2022.
For the past few days for unknown (to me) reasons, I can't run the app on localhost 5001 port, after deployment (to a local folder).
When I use details below in appsettings.json
, the deployed application runs on port 5001 properly:
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://127.0.0.1: 5000"
},
"Https": {
"Url": "https://localhost: 5001"
}}}
But then I can't launch it from VS. I didn't make any manual changes to launchsettings.json
or program.cs
, I use app.UseHttpsRedirection()
Is there any possibility to set default settings for development and deployment? I experienced no troubles in .NET 6, and had nothing to do with ports at all.
I'm developing an ASP.NET Core project recently upgraded from .NET 6 to .NET 9, in VS 2022.
For the past few days for unknown (to me) reasons, I can't run the app on localhost 5001 port, after deployment (to a local folder).
When I use details below in appsettings.json
, the deployed application runs on port 5001 properly:
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://127.0.0.1: 5000"
},
"Https": {
"Url": "https://localhost: 5001"
}}}
But then I can't launch it from VS. I didn't make any manual changes to launchsettings.json
or program.cs
, I use app.UseHttpsRedirection()
Is there any possibility to set default settings for development and deployment? I experienced no troubles in .NET 6, and had nothing to do with ports at all.
Share Improve this question edited 21 hours ago kkkristo asked yesterday kkkristokkkristo 588 bronze badges2 Answers
Reset to default 0Ok, I managed to find an answer by myself, although I didn't find the reason of such behavior of VS, that deploys an app only with listening on port 5000. What I did - initially, following tips from Andrew Lock's article here, I added this code to program.cs
:
builder.WebHost.UseUrls("http://localhost:5000", "https://localhost:5001");
It helped and set up ports properly for deploy, but also same ports for debugging. I prefered to have different ports for deployed instance and different for the one being under development. At the end I removed above code, and set a pair of ports in launchsettings.json
for development, and in program.cs
I added this:
if (!app.Environment.IsDevelopment())
{
app.Urls.Add("http://localhost:8000");
app.Urls.Add("https://localhost:8001");
}
Now it works as needed. Hope it helps anyone too.
There is at least one breaking change which could have affected this behaviour - see the Kestrel: Default HTTPS binding removed from .NET 7 breaking changes:
Version introduced
ASP.NET Core 7.0
Previous behavior
Previously, if no values for the address and port were specified explicitly but a local development certificate was available, Kestrel defaulted to binding to both
http://localhost:5000
andhttps://localhost:5001
.New behavior
Users must now manually bind to HTTPS and specify the address and port explicitly, through one of the following means:
- The launchSettings.json file
- The
ASPNETCORE_URLS
environment variable- The
--urls
command-line argument- The
urls
host configuration key- The
HostingAbstractionsWebHostBuilderExtensions.UseUrls
extension methodHTTP binding is unchanged.
Without seeing the full actual setup it is a bit hard to tell what the best course of action would be, but if you add the Kestrel
setup to the application.json
then you should modify launchSettings.json
accordingly (so it uses the same ports as configured for Kestrel). Alternatives would be moving the Kestrel
setup to application.Environment_Used_For_Local_File_Deploy_Here.json
(if it is not
Development), or something along the options stated above (so you have correct setup).
- 拍照比“剪刀手”注意了!专家:会泄露指纹信息
- java - Difficulty Embedding ICC Profile into PDF Using PDFBox, iText, and Ghostscrip - Stack Overflow
- browser cache - window.fetch not using cached data from <img src= - Stack Overflow
- typescript - Not able to make firstValueFromasync work with Angular - Stack Overflow
- reveal.js - Why do the divs have odd formating and non-matching colors in revealjs Quarto presentation? - Stack Overflow
- java - mac update sequoia 15.1 or 15.2 not work UniversalJavaApplicationStub - Stack Overflow
- Formulas in Looker Studio with Hubspot data not working - Stack Overflow
- frontend - Rescript and Fetch with Post Request - Stack Overflow
- Vercel hosted SvelteKit app keeps 404ing on form submit? - Stack Overflow
- stata - Fill in missing values by group for all the variables in the dataset - Stack Overflow
- batch file - Command segment in .omp.json Oh-my-posh theme - Stack Overflow
- macos - Restriction of media fetched with API in browser in iOS and Mac systems - Stack Overflow
- Keeping Data In Denormalized NoSql Databases (CassandraScyllaDb) Tables In Sync? - Stack Overflow
- javascript - error in getting data from firebase "user": "[object Object]"} in firebase - St
- connecting Shopify to external Stripe checkout script - Stack Overflow
- java - Getting FATAL: password authentication failed for user "postgres" in spring-boot project - Stack Overfl
- swift - Codable class does not conform to protocol Decodable because of TimeStamp, new Error wasn't there before - Stack