I have generated a project with radzen studio, the project that it generates uses http requests for security, everything works fine on local, the problem comes when I deploy to a docker in which I have a reverse proxy to redirect https to http , the baseUri that it detects is the external one. What is the most correct way to deal with this problem with the reverse proxy?
Not sure what security you are using however the default Microsoft Identity used in Radzen applications cannot be used without HTTPS when deployed:
Hi, thanks for the help. Finally I solved it by correctly redirecting the BaseUri of the Navigation, being published in a contained docker, due to firewall rules and with a domain certificate, the BaseUri detected the internal IP of docker.
Hello, since i have a similair problem i replied here.
I'm absolutely new to Blazor so i figured best is to ask here.
I have a Blazor Server Application. Created with Radzen.
I have no problem with running the server compiled for Linux.
The Application is reachable via the IP and port of the machine as configured in the appsettings.json.
When I use apache2 reverse proxy to assign a domain, everything works fine too.
At the moment when I install a SSL certificate with certbot and have the redirect to https in the vhost.conf active, the app throws errors and gets unresponsive on the browser (error 500)
the console gets flooded with error and access logs
This sounds as a HTTPS redirect issue. Make sure your server is configured to redirect all HTTP request s (GET and POST) to HTTPS. I have zero experience with Apache so you will have to search online how to do HTTPS redirects.
Well, the VS Template has no issues. the HTTPS is working just fine.
Its just the Radzen Template which has problems
I put a hardstop with logs at the function where the error occurs
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:5010
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /home/asro/Blazor
DEBUG: navigationManager.BaseUri is http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
DEBUG: navigationManager.BaseUri is http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
DEBUG: navigationManager.BaseUri is http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 185.2691ms - 200
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 102.2061ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 197.1675ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 107.4605ms - 200
DEBUG: navigationManager.BaseUri is http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
DEBUG: navigationManager.BaseUri is http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 100.0468ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 100.3335ms - 200
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 6.3733ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 6.5479ms - 200
DEBUG: navigationManager.BaseUri is http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
Error:
System.Exception: Unable to parse the response.
at Radzen.HttpResponseMessageExtensions.ReadAsync[T](HttpResponseMessage response)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in D:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 113
Error:
System.Exception: Unable to parse the response.
at Radzen.HttpResponseMessageExtensions.ReadAsync[T](HttpResponseMessage response)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in D:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 113
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 9.5884ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 10.0714ms - 200
Error:
System.Exception: Unable to parse the response.
at Radzen.HttpResponseMessageExtensions.ReadAsync[T](HttpResponseMessage response)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in D:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 113
Error:
System.Exception: Unable to parse the response.
at Radzen.HttpResponseMessageExtensions.ReadAsync[T](HttpResponseMessage response)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in D:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 113
Error:
System.Exception: Unable to parse the response.
at Radzen.HttpResponseMessageExtensions.ReadAsync[T](HttpResponseMessage response)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in D:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 113
public async Task<ApplicationAuthenticationState> GetAuthenticationStateAsync()
{
try
{
var uri = new Uri($"{navigationManager.BaseUri}Account/CurrentUser");
Console.WriteLine($"DEBUG: navigationManager.BaseUri is {navigationManager.BaseUri}");
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, uri));
if (response.IsSuccessStatusCode)
{
return await response.ReadAsync<ApplicationAuthenticationState>();
}
else
{
var responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error Response: {response.StatusCode}, Content: {responseContent}");zurückgeben.
throw new Exception($"HTTP Request failed with status code {response.StatusCode}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error:");
Console.WriteLine(ex);
Environment.Exit(1);
throw;
}
}
GNU nano 6.2 /etc/apache2/sites-available/Blazor.conf
<VirtualHost *:80>
ServerName solar.ugc-tools.de
ProxyPreserveHost On
ProxyRequests Off
ProxyVia Off
ProxyPass / http://127.0.0.1:5010/
ProxyPassReverse / http://127.0.0.1:5010/
ErrorLog ${APACHE_LOG_DIR}/Blazor_error.log
CustomLog ${APACHE_LOG_DIR}/Blazor_access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =solar.ugc-tools.de
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
You should use that if it works for you. HTTPS is obviously not working fine if it fails for some requests. You can try logging the response to see what the actual error is.
Well the Radzen looks better and has some "functions" i like to use
I know it does In this case you should see what the error - I see you have added some logging already. Try with it and share the message with us. I suspect it is indeed HTTPS redirect that doesn't work -
navigationManager.BaseUri
is using http
as this is what the container is running on.
yeah i edited the message, logs included ^^
btw the appsetting.json
{
"Urls": "http://*:5010",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"webtool_auth_dbConnection": "REDACTED"
},
"Databases": {
"webtool_auth_db": {
"NoPluralize": false,
"UseDatabaseNames": false
}
},
"Smtp": {
"Host": "REDACTED",
"Port": 465,
"Ssl": true,
"User": "REDACTED",
"Password": "REDACTED>
}
}
The logs don't show the response. It seems that the following line is failing:
return await response.ReadAsync<ApplicationAuthenticationState>();
You can try logging the response too. Also try forcing https here to see if it would make a difference:
var uri = new Uri($"{navigationManager.BaseUri.Replace("http", "https")}Account/CurrentUser");
public async Task<ApplicationAuthenticationState> GetAuthenticationStateAsync()
{
try
{
var uri = new Uri($"{navigationManager.BaseUri}Account/CurrentUser");
Console.WriteLine(navigationManager.BaseUri);
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Post, uri));
Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var ress = await response.ReadAsync<ApplicationAuthenticationState>(); //line 133
Console.WriteLine(ress);
return ress;
}
else
{
var responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error Response: {response.StatusCode}, Content: {responseContent}");
throw new Exception($"HTTP Request failed with status code {response.StatusCode}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error:");
Console.WriteLine(ex);
Environment.Exit(1);
throw;
}
}
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:5010
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /home/asro/Blazor
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST http://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 124.4108ms - 200
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 86.122ms - 200
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 219.348ms - 200
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 97.5863ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 129.3377ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 233.1589ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 103.0092ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 91.1381ms - 200
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Sun, 24 Sep 2023 09:07:14 GMT
Server: Kestrel
Cache-Control: no-cache, no-store, max-age=0
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
}
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Sun, 24 Sep 2023 09:07:14 GMT
Server: Kestrel
Cache-Control: no-cache, no-store, max-age=0
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
}
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Sun, 24 Sep 2023 09:07:14 GMT
Server: Kestrel
Cache-Control: no-cache, no-store, max-age=0
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
}
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Sun, 24 Sep 2023 09:07:14 GMT
Server: Kestrel
Cache-Control: no-cache, no-store, max-age=0
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
}
Error:
System.Exception: Unable to parse the response.
at Radzen.HttpResponseMessageExtensions.ReadAsync[T](HttpResponseMessage response)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in S:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 113
Error:
System.Exception: Unable to parse the response.
at Radzen.HttpResponseMessageExtensions.ReadAsync[T](HttpResponseMessage response)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in S:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 113
Error:
System.Exception: Unable to parse the response.
at Radzen.HttpResponseMessageExtensions.ReadAsync[T](HttpResponseMessage response)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in S:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 113
Error:
System.Exception: Unable to parse the response.
at Radzen.HttpResponseMessageExtensions.ReadAsync[T](HttpResponseMessage response)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in S:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 113
Hi @Asrothear,
If you want us to help you any further log the actual response of response.Content.ReadAsStringAsync();
before trying to parse it. Also did you try my suggestion with replacing http with https?
sended the wrong logs -.- message is edited
try the replacing the hhtps now, didnt do that to provide the logs before that
Funny, worrked for a short time and thenn added a second "s"
201
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='webtool_auth_db' AND TABLE_NAME='__EFMigrationsHistory';
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (19ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='webtool_auth_db' AND TABLE_NAME='__EFMigrationsHistory';
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT `MigrationId`, `ProductVersion`
FROM `__EFMigrationsHistory`
ORDER BY `MigrationId`;
info: Microsoft.EntityFrameworkCore.Migrations[20405]
No migrations were applied. The database is already up to date.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:5010
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /home/asro/Blazor
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
http://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST https://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST https://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[101]
Received HTTP response headers after 113.3911ms - 200
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[101]
End processing HTTP request after 124.0135ms - 200
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Date: Sun, 24 Sep 2023 09:15:57 GMT
Server: Kestrel
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
}
TitanSolar.Models.ApplicationAuthenticationState
https://solar.ugc-tools.de/
info: System.Net.Http.HttpClient.TitanSolar.LogicalHandler[100]
Start processing HTTP request POST httpss://solar.ugc-tools.de/Account/CurrentUser
info: System.Net.Http.HttpClient.TitanSolar.ClientHandler[100]
Sending HTTP request POST httpss://solar.ugc-tools.de/Account/CurrentUser
Error:
System.NotSupportedException: The 'httpss' scheme is not supported.
at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.<SendAsync>g__Core|5_0(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendAsync>g__Core|5_0(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at TitanSolar.SecurityService.GetAuthenticationStateAsync() in S:\Cloud\GitHub\TitanSolar WebTool_new bak\Services\SecurityService.cs:line 109
I write a short function and report back
Then try this
var uri = new Uri($"{navigationManager.BaseUri.Replace("http://", "https://")}Account/CurrentUser");
And if it worked it could mean your proxy may not be sending the required HTTP headers: Configure ASP.NET Core to work with proxy servers and load balancers | Microsoft Learn
Yeah figures the first part
internal string GetUrl(NavigationManager navigationManager)
{
#if DEBUG
return navigationManager.BaseUri;
#endif
var url = navigationManager.BaseUri;
if (url.Contains("http:")) url=url.Replace("http:", "https:");
Console.WriteLine(url);
return url;
}
Thank you very much, i will have a look at header thing.
Now its working as hoped