SiempreSteve
03/04/2024, 4:00 PMMike Chambers
03/05/2024, 11:32 AMweb.Subscriber.config
with the environment name Subscriber
xml
<!-- Restrict access to Umbraco -->
<rule name="Restrict access" stopProcessing="true" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing">
<match url="umbraco$|umbraco/(?!surface\/)(?!api\/)(?!webservices\/)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^{publisher.url}" negate="true" />
</conditions>
<action type="Redirect" url="{publisher.url}" appendQueryString="false" />
</rule>
This is only IIS/IISExpress hosted solution.. won't show in Kestrel if using for Development. 🙂Mike Chambers
03/05/2024, 11:32 AMxml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<!-- this is injected during dotnet publish - leaving here incase issues arise.
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\www.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
or:
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
<handlers>-->
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\www.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
<security>
<requestFiltering removeServerHeader="true" />
</security>
<system.webServer>
</configuration>
Jason
03/05/2024, 12:22 PMUseBackOffice()
and UseBackOfficeEndpoints()
on "frontend-only" servers, this doesn't just prevent it being served but also stops the feature from starting at all - saving resources.
How you choose to selectively do that is really up to you - we have an appsetting that we check for at boot:
csharp
var backofficeEnabled = ... //your logic here
app.UseUmbraco()
.WithMiddleware(u =>
{
if (backofficeEnabled)
{
u.UseBackOffice();
}
u.UseWebsite();
})
.WithEndpoints(u =>
{
u.UseInstallerEndpoints();
if (backofficeEnabled)
{
u.UseBackOfficeEndpoints();
}
u.UseWebsiteEndpoints();
});
Mike Chambers
03/05/2024, 1:03 PMif (env.EnvironmentName != "{subscriberEnvironmentName}"){}
Curios as to what you are gaining by an appsetting?
Also almost begs the question as to why it's not core to disable the backoffice for the IServerRoleAccessor role of ServerRole.Subscriber
?Jason
03/05/2024, 2:29 PMSiempreSteve
03/05/2024, 2:35 PMMike Chambers
03/05/2024, 2:38 PMMike Chambers
03/05/2024, 2:41 PM/api/
(Forgive me if I'm wrong now.. but all that UmbracoApiController adds is that autorouting, which we don't want?)
csharp
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Lovel.Code.Models;
using Umbraco.Cms.Web.Common;
namespace Code.Controllers
{
[Route("api/devinfo")]
public class DevInfoController : Controller
{
private readonly ILogger _logger;
private readonly UmbracoHelper _umbracoHelper;
public DevInfoController(ILogger<DevInfoController> logger, UmbracoHelper umbracoHelper)
{
_logger = logger;
_umbracoHelper = umbracoHelper;
}
[HttpGet]
[Route("getdevbox/{id:int}")]
public IActionResult? GetDevBox(int id)
{
// return a partial view with the IPublishedContent
if (_umbracoHelper.Content(id) is DevelopmentPage node)
Jason
03/05/2024, 3:56 PMMike Chambers
03/05/2024, 4:00 PMA hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by