Fix #3068 - support microsites in .NET MAUI
This commit is contained in:
@ -6,6 +6,7 @@ using Oqtane.Shared;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Linq;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
@ -14,11 +15,13 @@ namespace Oqtane.Services
|
||||
{
|
||||
private readonly NavigationManager _navigationManager;
|
||||
private readonly SiteState _siteState;
|
||||
private readonly HttpClient _http;
|
||||
|
||||
public InstallationService(HttpClient http, SiteState siteState, NavigationManager navigationManager) : base(http, siteState)
|
||||
{
|
||||
_navigationManager = navigationManager;
|
||||
_siteState = siteState;
|
||||
_http = http;
|
||||
}
|
||||
|
||||
private string ApiUrl => (_siteState.Alias == null)
|
||||
@ -27,7 +30,15 @@ namespace Oqtane.Services
|
||||
|
||||
public async Task<Installation> IsInstalled()
|
||||
{
|
||||
var path = new Uri(_navigationManager.Uri).LocalPath.Substring(1);
|
||||
var path = "";
|
||||
if (_http.DefaultRequestHeaders.UserAgent.ToString().Contains(Constants.MauiUserAgent))
|
||||
{
|
||||
path = _http.DefaultRequestHeaders.GetValues(Constants.MauiAliasPath).First();
|
||||
}
|
||||
else
|
||||
{
|
||||
path = new Uri(_navigationManager.Uri).LocalPath.Substring(1);
|
||||
}
|
||||
return await GetJsonAsync<Installation>($"{ApiUrl}/installed/?path={WebUtility.UrlEncode(path)}");
|
||||
}
|
||||
|
||||
|
@ -202,17 +202,27 @@ namespace Oqtane.Services
|
||||
|
||||
private async Task<bool> CheckResponse(HttpResponseMessage response, string uri)
|
||||
{
|
||||
//if (response.IsSuccessStatusCode && uri.Contains("/api/") && !response.RequestMessage.RequestUri.AbsolutePath.Contains("/api/"))
|
||||
//{
|
||||
// await Log(uri, response.RequestMessage.Method.ToString(), response.StatusCode.ToString(), "Request {Uri} Not Mapped To An API Controller Method", uri);
|
||||
// return false;
|
||||
//}
|
||||
if (response.IsSuccessStatusCode) return true;
|
||||
if (response.StatusCode != HttpStatusCode.NoContent && response.StatusCode != HttpStatusCode.NotFound)
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
await Log(uri, response.RequestMessage.Method.ToString(), response.StatusCode.ToString(), "Request {Uri} Failed With Status {StatusCode} - {ReasonPhrase}", uri, response.StatusCode, response.ReasonPhrase);
|
||||
// if response from api call is not from an api url then the route was not mapped correctly
|
||||
if (uri.Contains("/api/") && !response.RequestMessage.RequestUri.AbsolutePath.Contains("/api/"))
|
||||
{
|
||||
await Log(uri, response.RequestMessage.Method.ToString(), response.StatusCode.ToString(), "Request {Uri} Not Mapped To An API Controller Method", uri);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (response.StatusCode != HttpStatusCode.NoContent && response.StatusCode != HttpStatusCode.NotFound)
|
||||
{
|
||||
await Log(uri, response.RequestMessage.Method.ToString(), response.StatusCode.ToString(), "Request {Uri} Failed With Status {StatusCode} - {ReasonPhrase}", uri, response.StatusCode, response.ReasonPhrase);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool ValidateJsonContent(HttpContent content)
|
||||
|
Reference in New Issue
Block a user