How to set .NET Error Pages for a specific folder in IIS 7?

大兔子大兔子 提交于 2019-12-25 01:13:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!