问题
Could custom error page be applied to to specific folder in IIS?
For example, my folder name is http://my.com/foobar, in IIS, I right clicked on the folder name >>> .Net Error Pages Icon >>> Add... >>> 404 >>>>> Absolute URL >>http://my.com/error.html
This did not work. I checked in web.config file. There is nothing modified by IIS either. Am I doing something wrong?
~~~~~~~~~~~~~~~~ I add to this:
I tried the configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors>
<error redirect="error.html" statusCode="403" />
</customErrors>
</system.web>
</configuration>
This is no Go.
So I tried
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<httpErrors errorMode="Custom" >
<remove statusCode="403" subStatusCode="-1" />
<error statusCode="403" path="http://my.com/err.html" responseMode="Redirect" />
</httpErrors>
</system.web>
</configuration>
This worked, but this was added to the web.config under root, is there any way to add for a directory web.config?
回答1:
I added this to directory web.config, and it worked.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" >
<remove statusCode="403" subStatusCode="-1" />
<error statusCode="403" path="`___REDIRECT URL HERE________`" responseMode="Redirect" />
</httpErrors>
</system.webServer>
</configuration>
My question remaining: how is this different from the default way of doing it from IIS directly? Like this -
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors>
<error redirect="error.html" statusCode="403" />
</customErrors>
</system.web>
</configuration>
I heard this is working in IIS6 but not 7/7.5?
来源:https://stackoverflow.com/questions/27487157/how-to-set-net-error-pages-for-a-specific-folder-in-iis-7