Specifying multiple system.web in web.config - web-config

I need to alter the executiontimeout settings in web.config specific to my page.
I'm working on downloading large files. In order to do that I need to alter executiontimeout for download page alone. But if I specify the executiontimeout to some value, it will be applicable for all the pages and not just the download. But it shouldn't be.
I need executiontimeout settings specific to my download alone. Any suggestions if it's possible?
I found a solution this
Its something like this:
<configuration>
<location path="Download.aspx">
<system.web>
<httpRuntime requestValidationMode="2.0" maxRequestLength="2048000" executionTimeout="10240" />
<compilation debug="false" targetFramework="4.0"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
</location>
<system.web>
<!--httpRuntime maxRequestLength="512" useFullyQualifiedRedirectUrl="true" executionTimeout="45"/-->
<httpRuntime requestValidationMode="2.0" maxRequestLength="2048000"/>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" targetFramework="4.0"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
</configuration>

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.

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.

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>

Which areas of the web.config can i safely delete?

When beginning a new web project, i'm always a bit worried about removing pieces of the web.config. It seems there are more entries than ever with Net 3.5 SP1.
Which bits of the .config do you delete for the following scenarios:
WCF Web Service, no Javascript support
Simple MVC Website
EDIT
Can someone document a basic list of things left in and taken out of the web.config for a simple website?
I usually just delete items from the web.config until things break -- a process of trial and error.
It's astonishing how much of web.config you can remove without affecting anything. It's gotten quite crufty in .NET 3.5.
Largely agree with Jeff that it is a process of trial and error as to what you can remove from the file.
In terms of tweaking the runtime and the http pipeline, it can often be a process of adding things to the web.config, in order to turn things off.
The out of the box configuration adds a lot of modules to the pipeline, depending on what you are doing, you may not need half of them.
Have come across a few articles on this on MSDN, and also this one http://www.codeproject.com/KB/aspnet/10ASPNetPerformance.aspx, by Omar from PageFlakes, which was the only one I could find in my (poorly organised) bookmarks, which is a good starting point on optimising the runtime.
Here is a stripped down Web.config i use for a simple WCF service
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<authentication mode="Windows" />
<customErrors mode="RemoteOnly" defaultRedirect="error.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<system.serviceModel>
<services>
<service behaviorConfiguration="Service.ServiceBehavior" name="Service.Service">
<endpoint address="" binding="basicHttpBinding" contract="Service.IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Service.ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I removed a lot of extras especially the script modules which i won't require