When I run the application it runs on two ports - c#

I'm developing a web app with C#. Whenever I run the application using Visual Studio, two browser tabs open and the application runs on two ports: one of them is the correct one - the one with a portnumber that I specified. The other is unwanted and its portnumber is different every time I run it (I think VS looks at the next available port).
Does anyone know where the latter can be configured? I only want the application to run on the specified portnumber.
This is part of launchSettings.json where I've specified the sslPort:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:44646",
"sslPort": 44368
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Cassys.App": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
The port 44368 works and is correct. But somehow another browser-tab is opened with a different portnumber every time.
Edit: as requested by #Zhi Lv in comment section, here's the launch.json:
{
linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/WebApi.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "localhost:44368"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

Related

Debugging the remote connection was closed when use Blazor

I use Visual Studio Enterprise 2022 (64-bit) version 17.4, .Net 7, and BlazorWebAssembly.
When I use BlazorWebAssembly and try to debug a Blazor client-side app, I keep getting the error
Debugging connection was closed. Reason : WebSocket disconnected
This is my code launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:33139",
"sslPort": 0
}
},
"profiles": {
"BlazorApp": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5149",
"dotnetRunMessages": true
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
},
"WSL": {
"commandName": "WSL2",
"launchBrowser": true,
"launchUrl": "http://localhost:5149",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5149"
},
"distributionName": ""
}
}
}
I try this Debug ASP.NET Core Blazor WebAssembly
but it doesn't work.
Add app.UseBlazorDebugging(); inside the if (env.IsDevelopment()) block in Startup.cs will resolved your issue.

Web-app hot-reload when running by IIS Express with SSL

Created project by Micosoft Visual Studio "ASP.NET with React+Redux" template. In that case app running by IIS Express. But hot-reload for react-app doesn't work and shows error in console: "WebSocket connection to 'wss://localhost:54691/ws' failed:"
After some research, I found a solution: disable SSL in IIS settings. But how can I achieve using hot reload when SSL is enabled?
package.json dependencies:
"dependencies": {
"#emotion/react": "^11.8.2",
"#emotion/styled": "^11.8.1",
"#mui/material": "^5.5.2",
"#reduxjs/toolkit": "^1.8.1",
"history": "4.10.1",
"node-sass": "^6.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "5.0.0",
"react-redux": "~7.2.6",
"react-router-dom": "6.2.1",
"redux": "4.1.2",
"redux-thunk": "2.4.1",
"typescript": "4.4.4"
},
launchSettings.json generated by template (SSL enabled)
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:48763",
"sslPort": 44373
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyProject": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
error message:
WebSocketClient.js:16 WebSocket connection to 'wss://localhost:54691/ws' failed:
WebSocketClient # WebSocketClient.js:16
initSocket # socket.js:24
./node_modules/webpack-dev-server/client/index.js?protocol=ws%3A&hostname=0.0.0.0&port=54691&pathname=%2Fws&logging=none&reconnect=10 # index.js:273
options.factory # react refresh:6
__webpack_require__

HTTP Error 500.30 - ANCM In-Process Start Failure - Production Environment

I was configuring my application for deployment. The first step I did was changing the environment from Development to Production and stumbled in this error. I noticed that I can launch my application only in the Development Environment. When I change them to Staging, Production I get the mentioned error. Also, I tried the solutions from this post, and still no success.
Here are the related configurations:
launchSettings.json
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64845",
"sslPort": 44375
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
},
"BingoAPI": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
}
}
xx.csproj
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

.Net Core Project won't open browser by default

When debugging in VS 2019 the api url automatically opens which is different from the angular live url.
The angular live url is my actual complete application. Is there a way to open that url automatically when debugging?
I think you need to modify your json config a little bit. So when you use VS to run your code or using dotnet run command you will use port 59709 to run your app
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59709/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"ancmHostingModel": "InProcess"
},
"KaddaTechnologies": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:59709/"
}
}
}

Why is host.run() just opening localhost

In the kestrel part of my BuildWebHost, I can verify that the url is set to https://localhost/5000. However, when host.run() is called, only https://localhost is launched for some reason.
`
.UseKestrel(options =>
{
X509Certificate2 certificate = null;
if (!string.IsNullOrEmpty(certFileName) && !string.IsNullOrEmpty(certPassword))
{
certificate = new X509Certificate2(certFileName, certPassword);
url = "https://localhost:5000";
}
options.Listen(IPAddress.Loopback, 5000, listenOptions =>
{
if (certificate != null)
{
listenOptions.UseHttps(certificate);
}
});
})
`
Additional Information:
It's launched when I run Visual Studio Code. My configurations files all say localhost:5000 This used to work. I changed my program property in launch.json to point at net2.0 path and that's when it stopped.
launch.json contents:
`
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
// "program": "${workspaceFolder}/bin/Debug/netcoreapp1.1/TennisFolderAPI.dll",
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/TennisFolderAPI.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
},
"requireExactSource": false,
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
`
For Visual Studio in launchSettings.json use "launchUrl": "http://localhost:5000".
Launch.json is for Visual Studio Code.
https://www.google.com/amp/s/andrewlock.net/how-to-set-the-hosting-environment-in-asp-net-core/amp/

Categories