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

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.

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>

Blazor - how to use brotli compression

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.

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>

VSO Build not able to download packages

I have the following nuget.config file and bellow is the file content
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="Packages" />
</config>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<!-- Ditch all the Global NuGet package sources we only want a
single private NuGet repo for this project -->
<clear />
<add key="private="private" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<disabledPackageSources>
<add key="nuget.org" value="false" />
</disabledPackageSources>
</configuration>
All the packages which exist in the private feed are restored but the same is not happening with the ones in nuget.org:
From VSO build output
Feeds used:
C:\Users\buildguest\AppData\Local\NuGet\Cache
private
https://www.nuget.org/api/v2/
...
Restoring NuGet package AutoMapper.5.2.0.
WARNING: Unable to find version '5.2.0' of package 'AutoMapper'.
This is happening during the NuGet restore step in VSO.
Use NuGet.Protocol.Core.v3 feed protocol with
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
instead of
<add key="nuget.org" value="https://nuget.org/api/v2/" />
enter image description here
Inside Nuget.config put the bellow code.
<configuration>
<packageRestore>
<add key="enabled" value="True"/>
<add key="automatic" value="True"/>
</packageRestore>
</configuration>