C
C#4w ago
Darkarevir

✅ 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
qqdev
qqdev4w ago
Hi! Can you tell us what does not work?
Darkarevir
DarkarevirOP4w ago
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
No description
No description
Sossenbinder
Sossenbinder4w ago
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
Sehra
Sehra4w ago
are you running it in IIS?
Darkarevir
DarkarevirOP4w ago
yes
Darkarevir
DarkarevirOP4w ago
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.
No description
No description
Sehra
Sehra4w ago
check if you have enabled websocket support for IIS under server roles
Darkarevir
DarkarevirOP4w ago
This is local
No description
Darkarevir
DarkarevirOP4w ago
I use somee and I can't find that section
Sehra
Sehra4w ago
add roles and feature wizard, server roles, web server, application development, websocket protocol
Darkarevir
DarkarevirOP4w ago
It is free since it is for testing at the moment, is that why?
Sossenbinder
Sossenbinder4w ago
I didn't get that part But yes, I'd also assume your IIS config might not have websocket support
Sossenbinder
Sossenbinder4w ago
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
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX4w ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?