i have the same issue here is the details:
Problem : Swagger UI Not Accessible
Description: Swagger UI documentation page is not loading after deployment to MonsterASP hosting. It works correctly on local development environment.
Current Implementation
Program.cs (Middleware Configuration):
if (app.Environment.IsDevelopment() || app.Environment.IsProduction())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseCors("AllowAllOrigins");
app.UseAuthentication();
app.UseAuthorization();
// SignalR Hub - configured for Long Polling (works on shared hosting without WebSocket support)
app.MapHub<NotificationHub>("/notificationHub", options =>
{
options.Transports =
Microsoft.AspNetCore.Http.Connections.HttpTransportType.WebSockets |
Microsoft.AspNetCore.Http.Connections.HttpTransportType.LongPolling;
});
app.MapControllers();
app.Run();
CORS Configuration (ApiServiceCollectionExtensions.cs):
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins", builder =>
{
builder
.SetIsOriginAllowed(_ => true)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
The Hub Implementaion
[Authorize]
public class NotificationHub : Hub
{
public override async Task OnConnectedAsync()
{
var userId = Context.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
if (!string.IsNullOrEmpty(userId))
{
await Groups.AddToGroupAsync(Context.ConnectionId, userId);
}
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception? exception)
{
var userId = Context.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
if (!string.IsNullOrEmpty(userId))
{
await Groups.RemoveFromGroupAsync(Context.ConnectionId, userId);
}
await base.OnDisconnectedAsync(exception);
}
}
The Notification Service :
public class NotificationService : INotificationService
{
private readonly IHubContext<NotificationHub> _hubContext;
public NotificationService(IHubContext<NotificationHub> hubContext)
{
_hubContext = hubContext;
}
public async Task SendNotificationToUser(string userId, string message)
{
await _hubContext.Clients.User(userId).SendAsync("ReceiveNotification", new { message });
}
}
Application Details
• Framework: ASP.NET Core 9.0
• Hosting Model: In-Process
• SignalR Transports: WebSockets + LongPolling (fallback)