2016-08-29 9 views
0

私はPHP開発者ですが、ASPサイトにいくつかの変更を加える必要があります。 404エラーをカスタム404ページにリダイレクトしようとしています。以下は、web.configファイルのページのコードです:私は、次のようなコードを追加しようとしたasp.net custom 404 page - not working

<?xml version="1.0" encoding="UTF-8"?> 
    <configuration> 
     <system.webServer> 
      <security> 
       <requestFiltering> 
        <filteringRules> 
         <!-- name the rule --> 
         <filteringRule name="user agent deny" scanUrl="false" scanQueryString="false"> 
          <scanHeaders> 
          <!-- apply rule to user-agent header --> 
           <add requestHeader="user-agent" /> 
          </scanHeaders> 
          <!-- apply rule to all files --> 
          <appliesTo /> 
          <denyStrings> 
           <clear /> 
      <!-- block the following bots --> 
    <add string="Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexBot/3.0; MirrorDetector; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexMedia/3.0; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexBlogs/0.99; robot; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexVideo/3.0; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexZakladki/3.0; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexAntivirus/2.0; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexFavicons/1.0; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexDirect/3.0; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexCatalog/3.0; +http://yandex.com/bots) " /> 
    <add string="Mozilla/5.0 (compatible; YandexImageResizer/2.0; +http://yandex.com/bots) " /> 
    <add string="Yandex/1.01.001 (compatible; Win16; I) " /> 
    <add string="Yandex/1.01.001 (compatible; Win16; H) " /> 
    <add string="Mozilla/5.0 (compatible; YandexWebmaster/2.0; +http://yandex.com/bots) " /> 
    <add string="Yandex/1.01.001 (compatible; Win16; P) " /> 
    <add string="Yandex/1.01.001 (compatible; Win16; m) " /> 
    <add string="YandexSomething/1.0 " /> 
    <add string="Baiduspider+(+http://www.baidu.com/search/spider.htm) " /> 
    <add string="BaiduImagespider+(+http://www.baidu.jp/search/s308.html) " /> 
    <add string="BaiDuSpider " /> 
    <add string="Baiduspider+(+http://help.baidu.jp/system/05.html) " /> 
    <add string="Baiduspider+(+http://www.baidu.com/search/spider_jp.html) " /> 
    <add string="Baiduspider+(+http://www.baidu.jp/spider/) " /> 
          </denyStrings> 
         </filteringRule> 
        </filteringRules> 
       </requestFiltering> 
      </security> 

      <staticContent> 
       <clientCache cacheControlMaxAge="365.00:00:00" cacheControlMode="UseMaxAge" /> 
      </staticContent> 

      <defaultDocument> 
       <files> 
        <clear /> 
      <add value="index.asp" /> 
      <add value="Default.asp" /> 
      <add value="Index.html" /> 
      <add value="Index.htm" /> 
      <add value="Index.cfm" /> 
      <add value="Index.shtml" /> 
      <add value="Index.shtm" /> 
      <add value="Index.stm" /> 
      <add value="Index.php" /> 
      <add value="Index.php3" /> 
      <add value="Index.aspx" /> 
      <add value="Default.htm" /> 
      <add value="Default.aspx" /> 
       </files> 
      </defaultDocument> 

      <rewrite> 
       <rules> 
        <rule name="Redirect to WWW" stopProcessing="true"> 
         <match url=".*" /> 
         <conditions> 
          <add input="{HTTP_HOST}" pattern="^thetoolstore.ca$" /> 
         </conditions> 
         <action type="Redirect" url="http://www.thetoolstore.ca/{R:0}" redirectType="Permanent" /> 
        </rule> 

        <rule name="Redirect to root" patternSyntax="Wildcard" stopProcessing="true"> 
        <match url="index.asp" /> 
         <action type="Redirect" url="/" appendQueryString="false" redirectType="Permanent" /> 
        </rule> 
        <rule name="Redirect to HTTPS" stopProcessing="true"> 
         <match url="(.*)" /> 
         <conditions> 
          <add input="{HTTPS}" pattern="^OFF$" /> 
         </conditions> 
         <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
        </rule> 
       </rules> 
      </rewrite> 
    <httpErrors errorMode="Detailed" /> 


</system.webServer> 
<system.net> 
    <mailSettings> 
     <smtp from="[email protected]"> 
      <network host="localhost" /> 
     </smtp> 
    </mailSettings> 
</system.net> 

<httpErrors errorMode="Custom" existingResponse="Replace"> 
    <remove statusCode="404" subStatusCode="-1" /> 
    <error statusCode="404" path="404.asp" responseMode="ExecuteURL"/> 
</httpErrors> 

しかし、それだけで500エラーが発生します。実際、私が試したものは500エラーでした。

また、MVCサイトではないと確信しています。

ありがとうございます!

答えて

0

web.configファイル自体の形式が正しくないため、500エラーが発生します。終了タグがありません</configuration>

また、既存のhttpErrorsノード<httpErrors errorMode="Detailed" />もあります。それはあなたのコード(どの作品)に置き換えられなければなりません。重複することはできません。

最後に、http://www.freeformatter.com/xml-formatter.htmlのようなものを使用して、web.configファイルを適切にフォーマットしてください。それは混乱です。

+0

ありがとうございます!私はそれを試みます。 – loridk