✅ SignalR
Hello, I am doing some practices for the backend part but I have a problem when trying to use the websocket locally it works perfectly but when uploading it to the server it does not work. Here is the code
var builder = WebApplication.CreateBuilder(args);
var env = builder.Environment;
Env.Load();
builder.WebHost.ConfigureKestrel(options =>
{
int proxyPort = Env.GetInt("PROXY_PORT", 5000);
options.ListenAnyIP(proxyPort);
options.ListenAnyIP(proxyPort + 1, listenOptions =>
{
listenOptions.UseHttps();
});
});
builder.Services.AddControllers();
builder.Services.AddSignalR();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigins", policyBuilder =>
{
policyBuilder
.WithOrigins("mi-domain")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
options.AddPolicy("AllowAll", policyBuilder =>
{
policyBuilder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
var app = builder.Build();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseCors("AllowSpecificOrigins");
app.MapHub<UserHub>("/userhub");
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
app.UseHsts();
app.UseHttpsRedirection();
}
app.UseAuthentication();
app.UseAuthorization();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "pictures")),
RequestPath = "/pictures"
});
15 Replies
Hi! Can you tell us what does not work?
It does not connect to the server although it is a test at the moment it does not work on the client which is flutter or postman, it always gives me the error 400


Can you showcase the user hub as well for completeness?
Also, what is the intended transport?
Since your server url is https and not wss
are you running it in IIS?
yes
this? https and not wss, In Postman, if I make the request with https, it duplicates it, that's why I do it with wss and if I do it without https, I get the same error.


check if you have enabled websocket support for IIS under server roles
This is local

I use somee and I can't find that section
add roles and feature wizard, server roles, web server, application development, websocket protocol
It is free since it is for testing at the moment, is that why?
I didn't get that part
But yes, I'd also assume your IIS config might not have websocket support
WebSocket
Overview The element specifies the use of the WebSocketModule module with ASP.NET 4.5 to support writing server applications that communica...
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
If you have no further questions, please use /close to mark the forum thread as answered