How to solve?

I am currently writing a C# dotnet backend server on a VPS. I tried to run the server and call it with Google Chrome. If I call it with http://localhost:5116, it runs, but if I call it with http://10.1.4.5:5116, I cannot call it. In other words, you can use localhost, but entering the IP address directly does not work. How to fix?
35 Replies
Pobiega
Pobiega5mo ago
Change the launchsettings - you'll need to bind to 0.0.0.0:portnumber
Angius
Angius5mo ago
Well, localhost is your computer
Pobiega
Pobiega5mo ago
HOWEVER... when running on a VPS (linux?) the most common way to host your api is to run it via a reverse proxy, like nginx
Pobiega
Pobiega5mo ago
Host ASP.NET Core on Linux with Nginx
Learn how to set up Nginx as a reverse proxy on Ubuntu, RHEL and SUSE to forward HTTP traffic to an ASP.NET Core web app running on Kestrel.
Daniel Matthew
Daniel Matthew5mo ago
I am using windows system
Pobiega
Pobiega5mo ago
Okay. Then you have more options - but a reverse proxy is still recommended. for production, that is if its just for testing, you can skip it and just bind to 0.0.0.0
Daniel Matthew
Daniel Matthew5mo ago
How to bind? Actually, I am rookie for dotnet This is program.cs
Daniel Matthew
Daniel Matthew5mo ago
var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); }); }); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseCors("AllowAllOrigins"); app.UseAuthorization(); app.MapControllers(); app.Run();
Get started with Swashbuckle and ASP.NET Core
Learn how to add Swashbuckle to your ASP.NET Core web API project to integrate the Swagger UI.
Daniel Matthew
Daniel Matthew5mo ago
How to bind?
Pobiega
Pobiega5mo ago
in your launchsettings not in the code
Daniel Matthew
Daniel Matthew5mo ago
I don't know how to bind. Could you help me via anydesk?
Daniel Matthew
Daniel Matthew5mo ago
in launchSettings.json file?
Pobiega
Pobiega5mo ago
check the top answer on that post it literally answers your question in the best possible way
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Daniel Matthew
Daniel Matthew5mo ago
As I said, I am rookie. So, plz help me via anydesk I will share my screen
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Daniel Matthew
Daniel Matthew5mo ago
Because, I don't know how to set So, plz help me
Daniel Matthew
Daniel Matthew5mo ago
I set like this
No description
No description
Daniel Matthew
Daniel Matthew5mo ago
But, I can't do
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Daniel Matthew
Daniel Matthew5mo ago
I ran on VPS using visual studio
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Daniel Matthew
Daniel Matthew5mo ago
Because, I am helping my friend. He use VPS
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Daniel Matthew
Daniel Matthew5mo ago
yep
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Daniel Matthew
Daniel Matthew5mo ago
I setted like this But it dosen't work yet
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Daniel Matthew
Daniel Matthew5mo ago
No description
No description
No description
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Daniel Matthew
Daniel Matthew5mo ago
No description
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Daniel Matthew
Daniel Matthew5mo ago
How to ? Plz help via anydesk
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts