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
Change the launchsettings - you'll need to bind to
0.0.0.0:portnumber
Well,
localhost
is your computerHOWEVER... when running on a VPS (linux?) the most common way to host your api is to run it via a reverse proxy, like nginx
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.
I am using windows system
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
How to bind?
Actually, I am rookie for dotnet
This is program.cs
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.
How to bind?
in your launchsettings
not in the code
I don't know how to bind.
Could you help me via anydesk?
in launchSettings.json file?
check the top answer on that post
it literally answers your question in the best possible way
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
As I said, I am rookie.
So, plz help me via anydesk
I will share my screen
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Because, I don't know how to set
So, plz help me
I set like this
But, I can't do
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I ran on VPS using visual studio
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Because, I am helping my friend.
He use VPS
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
yep
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
I setted like this
But it dosen't work yet
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
How to ?
Plz help via anydesk
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View