Blazor - how to use brotli compression - web-config

Blazor WASM supports gzip/brotli compression. Official documentation shows example web.config
however this web.config is not using hosted model.
If I merge example web.config with root web.config
<?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=".\app.Server.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
Javascript files, css, images becomes unreachable. I also tried put example web.config into wwwroot/_framework folder, however no change at all.

Related

IIS 10 Default Document for Application Under Website

Running IIS 10 on a windows 2019 server I have 1 web site and under there I have 20+ applications running. I have been trying to create a default document for each of the sub applications however, ever time I edit one of the sub application it changes for all the applications, not just the specific one I want edited.
The IIS tree looks something like:
www.companysite.com (Site)
Company1 (Application)
Company2 (Application)
Company3 (Application)
etc. (Application)
I initially tried going to each sub application, opening up Default Document and selecting the Add... option which, as mentioned, would change for all applications.
In the applicationHost.config file at the bottom I tried to manually enter the following, making an entry for each and this also did not work. It seems to only read the first entry and use for all applications:
<location path="www.companysite.com/Company1">
<system.webServer>
<defaultDocument enabled="true">
<files>
<add value="Company1LandingPage.asp" />
</files>
</defaultDocument>
</system.webServer>
</location>
I even had a clear tag in there after the files entry and that did not help. Thoughts?
My web.config file has not been touched and has the following:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="default.aspx" />
</files>
</defaultDocument>
</system.webServer>
The problem seems to be with your configuration, how did you set the default document for each sub application? In my iis, each sub application has its own web.config file. Their file list names(<add value="" />) should be in separate web.config files, should be like below config, not your above setting.
Application1:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="Default.htm" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
Application2:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="Default.asp" />
</files>
</defaultDocument>
</system.webServer>
</configuration>

IIS 10 - web.config - how to enable default document without script access

We have a folder which contains only static html and images etc. No scripts should be allowed to execute from within this folder. However we would still like to be able to use html default documents.
What is the correct way to configure this?
This is the web.config file...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read"/>
<defaultDocument enabled="true">
<files>
<clear />
<add value="default.html" />
<add value="default.htm" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
If I attempt to access http://mysite/mystaticfolder/ it fails with the error...
HTTP Error 403.1 - Forbidden
However the URL http://mysite/mystaticfolder/default.html works fine.
Surely it shouldn't be nescessary to allow dynamic scripts, just to be able to serve static html default documents?
In case it helps anyone, I've been able to solve it with the following...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read">
<clear/>
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule" resourceType="Either" requireAccess="Read" />
</handlers>
<defaultDocument enabled="true">
<files>
<clear />
<add value="default.html" />
<add value="default.htm" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
I'm not entirely sure though why this doesn't work by default though.

In IIS can I change the default document per folder via web.config?

I have a certain PHP file on my windows server in a directory that requires you to add index.php in order to view it.
The below works:
http://example.org/placestorun/index
But the following does not work:
http://example.org/placestorun/
I added a web.config file to the places to run directory to make it work without the index.php using the below code in the folder's web.config file:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
The above is not working though.
I ended up just doing a rewrite in web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule placestoswim" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="index.php" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You need to add clear to remove all the inherited elements:
<configuration>
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
Also make sure your app is not running in classic mode but in integrated mode.

Azure webapp Web.config httpErrors not redirecting

I have an Azure-hosted website that is working great. The thing I'm stuck on is a desire to ignore anything after the base URL, and always have the user see the single page that is the whole site. (If they type the http://example.com site, anything after that will be ignored, and my map.html page will be shown.
I have made the following changes to the Web.config file, which help this along:
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="map.html" />
</files>
</defaultDocument>
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404 path="/map.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
If I enter a url of example.com/xxxx.yyyy the site displays fine (it ignores the "/xxxx.yyyy" and shows the map.html page - just what I want. But if I enter example.com/xxxx without the trailing ".yyyy") the following IIS or Azure message shows:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404 The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporally unavailable...
Requested URL: /xxxx
How can I get the same redirect to happen no matter what follows the site name in the url?
I've tried Windows Edge, Chrome, and Safari, and they all give the same results.
To achieve your requirement, you can add a rewrite rule instead:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to map">
<action type="Rewrite" url="/map.html"/>
</rule>
</rules>
</rewrite>
Update:
If you work in ASP.NET, you may also need to specify <customErrors> Element in Web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="~/map.html" />
</customErrors>
</system.web>
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="map.html" />
</files>
</defaultDocument>
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/map.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>

Orchard, WebForms and iFrames

I am trying to embed an iFrame into a Orchard CMS section (same domain - controls live in a subdirectory off the main Orchard installation). I found two threads on here that talk about the issue I'm having (see here and here), but I'm still running into issues. The pages I am trying to load in the iFrame are standard WebForms and require both WebResource.axd and ScriptResource.axd. I managed to get WebResource.axd working, but ScriptResource is returning a 500 Internal Server Error (according to Chrome), but I can't figure out what's causing the 500 or what the real error is. The relevant entry from my web.config is below - any suggestions?
<handlers accessPolicy="Script">
<!-- clear all handlers, prevents executing code file extensions, prevents returning any file contents -->
<clear />
<!-- Custom Controls -->
<add name="ASPX" path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode" requireAccess="Script"/>
<add name="WebResource" path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" preCondition="integratedMode" />
<add name="ScriptResource" path="ScriptResource.axd" verb="GET" type="System.Web.Handlers.ScriptResourceHandler" preCondition="integratedMode" />
<!-- Everything below added from Orchard -->
<!-- Return 404 for all requests via managed handler. The url routing handler will substitute the mvc request handler when routes match. -->
<!--<add name="NotFound" path="*" verb="*" type="System.Web.HttpNotFoundHandler" preCondition="integratedMode" requireAccess="Script" />-->
<!-- WebApi -->
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Combining Bertrand's suggestion and a lot of playing around, I ended up finding a solution to this.
First, the custom stuff will need to be in a subfolder and inside IIS you can switch that subfolder over to an application (not a virtual directory). For a little extra peace of mind, I also gave it a dedicated app pool so if something did get weird with it the main site wouldn't go down.
The next parts involve a couple of steps - mostly because of that <clear /> entry in system.webServer/handlers. Removing this in the parent app breaks Orchard, but having it in broke my child app since it inherits all the settings from the parent. To get around this, my child app had to have the following system.webServer configuration:
<system.webServer>
<handlers>
<remove name="NotFound" />
<add name="ASPX" path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode" requireAccess="Script"/>
<add name="WebResource" path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" preCondition="integratedMode" />
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
<modules>
<remove name="WarmupHttpModule" />
</modules>
</system.webServer>
I used the SO link referenced here to find the "real" ScriptResource.axd reference that was needed and it looks like everything is working.