Add SignalR/WebSocket config and large upload support
Configured SignalR and WebSockets for improved reliability and large content handling. Added appsettings and web.config for production/IIS, including increased timeouts, message size limits, and security/compression settings. Added fallback to Long Polling if WebSockets fail.
This commit is contained in:
@@ -24,6 +24,15 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
notemarkTheme.init();
|
notemarkTheme.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Force Long Polling if WebSockets fail (temporary fix)
|
||||||
|
Blazor.start({
|
||||||
|
configureSignalR: function (builder) {
|
||||||
|
builder.withUrl("/_blazor", {
|
||||||
|
transport: 1 // LongPolling = 1, WebSockets = 4
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,16 @@ builder.Services.AddSingleton<IMarkdownService, MarkdownService>();
|
|||||||
builder.Services.AddScoped<ISessionService, SessionService>();
|
builder.Services.AddScoped<ISessionService, SessionService>();
|
||||||
builder.Services.AddScoped<IShareService, ShareService>();
|
builder.Services.AddScoped<IShareService, ShareService>();
|
||||||
|
|
||||||
|
// Configure SignalR for better WebSocket support
|
||||||
|
builder.Services.AddSignalR(options =>
|
||||||
|
{
|
||||||
|
// Increase timeouts for large content
|
||||||
|
options.ClientTimeoutInterval = TimeSpan.FromMinutes(2);
|
||||||
|
options.KeepAliveInterval = TimeSpan.FromSeconds(30);
|
||||||
|
options.HandshakeTimeout = TimeSpan.FromSeconds(30);
|
||||||
|
options.MaximumReceiveMessageSize = 1024 * 1024; // 1MB
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
@@ -27,6 +37,13 @@ if (!app.Environment.IsDevelopment())
|
|||||||
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
|
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
// Enable WebSockets
|
||||||
|
app.UseWebSockets(new WebSocketOptions
|
||||||
|
{
|
||||||
|
KeepAliveInterval = TimeSpan.FromMinutes(2),
|
||||||
|
ReceiveBufferSize = 4 * 1024
|
||||||
|
});
|
||||||
|
|
||||||
// Enable cookies for session management
|
// Enable cookies for session management
|
||||||
app.UseCookiePolicy(new CookiePolicyOptions
|
app.UseCookiePolicy(new CookiePolicyOptions
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Warning",
|
||||||
|
"Microsoft.AspNetCore": "Warning",
|
||||||
|
"Microsoft.AspNetCore.SignalR": "Warning",
|
||||||
|
"Microsoft.AspNetCore.Http.Connections": "Warning",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
|
||||||
|
"SignalR": {
|
||||||
|
"EnableDetailedErrors": false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning",
|
||||||
|
"Microsoft.AspNetCore.SignalR": "Information",
|
||||||
|
"Microsoft.AspNetCore.Http.Connections": "Information"
|
||||||
|
},
|
||||||
|
"Console": {
|
||||||
|
"IncludeScopes": false,
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
|
||||||
|
"Kestrel": {
|
||||||
|
"Limits": {
|
||||||
|
"MaxRequestBodySize": 104857600,
|
||||||
|
"RequestHeadersTimeout": "00:01:00",
|
||||||
|
"KeepAliveTimeout": "00:02:00",
|
||||||
|
"MaxRequestHeaderCount": 100,
|
||||||
|
"MaxRequestHeadersTotalSize": 65536,
|
||||||
|
"MaxRequestLineSize": 8192,
|
||||||
|
"MaxRequestBufferSize": 1048576,
|
||||||
|
"MaxResponseBufferSize": 1048576
|
||||||
|
},
|
||||||
|
"EndPoints": {
|
||||||
|
"Http": {
|
||||||
|
"Url": "http://localhost:5000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"SignalR": {
|
||||||
|
"SupportedProtocols": [ "WebSockets", "LongPolling" ],
|
||||||
|
"ClientTimeoutInterval": "00:02:00",
|
||||||
|
"KeepAliveInterval": "00:00:30",
|
||||||
|
"HandshakeTimeout": "00:00:30",
|
||||||
|
"MaximumReceiveMessageSize": 1048576,
|
||||||
|
"StreamBufferCapacity": 10,
|
||||||
|
"EnableDetailedErrors": false
|
||||||
|
},
|
||||||
|
|
||||||
|
"ConnectionStrings": {},
|
||||||
|
|
||||||
|
"AppSettings": {
|
||||||
|
"DataPath": "data",
|
||||||
|
"MaxFileSize": 104857600,
|
||||||
|
"SessionTimeout": "30.00:00:00",
|
||||||
|
"ShareTokenExpiry": "365.00:00:00"
|
||||||
|
}
|
||||||
|
}
|
||||||
+96
@@ -0,0 +1,96 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<location path="." inheritInChildApplications="false">
|
||||||
|
<system.webServer>
|
||||||
|
<handlers>
|
||||||
|
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
|
||||||
|
</handlers>
|
||||||
|
|
||||||
|
<aspNetCore processPath="dotnet"
|
||||||
|
arguments=".\Notemark.dll"
|
||||||
|
stdoutLogEnabled="false"
|
||||||
|
stdoutLogFile=".\logs\stdout"
|
||||||
|
hostingModel="inprocess"
|
||||||
|
requestTimeout="00:05:00">
|
||||||
|
<environmentVariables>
|
||||||
|
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
|
||||||
|
<environmentVariable name="ASPNETCORE_HTTP_TIMEOUT" value="300" />
|
||||||
|
</environmentVariables>
|
||||||
|
</aspNetCore>
|
||||||
|
|
||||||
|
<!-- WebSocket support for Blazor Server -->
|
||||||
|
<webSocket enabled="true"
|
||||||
|
receiveBufferLimit="4194304"
|
||||||
|
pingInterval="00:01:00" />
|
||||||
|
|
||||||
|
<!-- Configuration for larger files -->
|
||||||
|
<security>
|
||||||
|
<requestFiltering>
|
||||||
|
<requestLimits maxAllowedContentLength="104857600"
|
||||||
|
maxQueryString="8192"
|
||||||
|
maxUrl="8192" />
|
||||||
|
</requestFiltering>
|
||||||
|
</security>
|
||||||
|
|
||||||
|
<!-- HTTP protocol configuration -->
|
||||||
|
<httpProtocol>
|
||||||
|
<customHeaders>
|
||||||
|
<add name="Connection" value="Keep-Alive" />
|
||||||
|
<add name="X-Content-Type-Options" value="nosniff" />
|
||||||
|
<add name="X-Frame-Options" value="SAMEORIGIN" />
|
||||||
|
<add name="X-XSS-Protection" value="1; mode=block" />
|
||||||
|
</customHeaders>
|
||||||
|
</httpProtocol>
|
||||||
|
|
||||||
|
<!-- URL Rewrite for WebSockets and SPA routing -->
|
||||||
|
<rewrite>
|
||||||
|
<rules>
|
||||||
|
<rule name="WebSocket Support" enabled="true" stopProcessing="true">
|
||||||
|
<match url="(.*)" />
|
||||||
|
<conditions>
|
||||||
|
<add input="{HTTP_UPGRADE}" pattern="websocket" ignoreCase="true" />
|
||||||
|
<add input="{HTTP_CONNECTION}" pattern="upgrade" ignoreCase="true" />
|
||||||
|
</conditions>
|
||||||
|
<action type="None" />
|
||||||
|
</rule>
|
||||||
|
</rules>
|
||||||
|
</rewrite>
|
||||||
|
|
||||||
|
<!-- Compression for better performance -->
|
||||||
|
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
|
||||||
|
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
|
||||||
|
<dynamicTypes>
|
||||||
|
<add mimeType="text/*" enabled="true" />
|
||||||
|
<add mimeType="message/*" enabled="true" />
|
||||||
|
<add mimeType="application/javascript" enabled="true" />
|
||||||
|
<add mimeType="application/atom+xml" enabled="true" />
|
||||||
|
<add mimeType="application/xaml+xml" enabled="true" />
|
||||||
|
<add encoding="*" enabled="true" />
|
||||||
|
</dynamicTypes>
|
||||||
|
<staticTypes>
|
||||||
|
<add mimeType="text/*" enabled="true" />
|
||||||
|
<add mimeType="message/*" enabled="true" />
|
||||||
|
<add mimeType="application/javascript" enabled="true" />
|
||||||
|
<add mimeType="application/atom+xml" enabled="true" />
|
||||||
|
<add mimeType="application/xaml+xml" enabled="true" />
|
||||||
|
<add encoding="*" enabled="true" />
|
||||||
|
</staticTypes>
|
||||||
|
</httpCompression>
|
||||||
|
|
||||||
|
<!-- Caching for static files -->
|
||||||
|
<staticContent>
|
||||||
|
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
|
||||||
|
</staticContent>
|
||||||
|
|
||||||
|
</system.webServer>
|
||||||
|
</location>
|
||||||
|
|
||||||
|
<!-- Classic ASP.NET settings for compatibility -->
|
||||||
|
<system.web>
|
||||||
|
<httpRuntime maxRequestLength="102400"
|
||||||
|
executionTimeout="300"
|
||||||
|
enableVersionHeader="false" />
|
||||||
|
<compilation debug="false" />
|
||||||
|
</system.web>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
Reference in New Issue
Block a user