发送Response.Status =“404 Not Found”但让IIS保持在同一页面上

时间:2016-11-11 20:11:44

标签: iis asp-classic web-config http-status-code-404 iis-8.5

我有一个简单的问题:

是否可以从.asp页面发送Response.Status =“404 Not Found”,但是继续呈现实际页面?

当我发送Response.Status =“404 Not Found”时,IIS会移动到默认的404错误页面,而我想继续渲染我的页面。这是一个CMS的情况,由于某种原因,某人可以键入一个不存在的永久链接,并希望显示“OPS未找到的内容页面”,而不是重定向到自定义或默认的404 asp页面。

有一个特定的web.config设置吗?

我在这里进行了讨论: Configuring custom ASP 404 page with redirect for IIS7 website

并考虑使用then选项

<httpErrors existingResponse="PassThrough" />

但由于某种原因,它给了我500错误。 IIS版本是8.5 asp 3.0 / .NET 3.5

我的实际web.config是:

<?xml version="1.0" encoding="UTF-8"?>

  

<httpErrors errorMode="DetailedLocalOnly"/>  

<urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true" />      
<caching enabled="true">
    <profiles>              
      <add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
      <add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
      <add extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
      <add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
      <add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
      <add extension=".jpeg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
    </profiles>
</caching>  

<staticContent>
    <remove fileExtension=".js" />
    <mimeMap fileExtension=".js" mimeType="text/javascript" />
    <remove fileExtension=".eot" />
    <remove fileExtension=".ttf" />
    <remove fileExtension=".otf"/>
    <remove fileExtension=".woff"/>
    <remove fileExtension=".woff2"/>
    <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
    <mimeMap fileExtension=".ttf" mimeType="font/ttf" />
    <mimeMap fileExtension=".otf" mimeType="font/otf" />
    <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
    <mimeMap fileExtension=".woff2" mimeType="font/x-woff2" />      
    <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>        

<rewrite>
      <rules>
        <rule name="Rewrite to friendly URL">
              <match url="^site/([_0-9a-z-]+)" />
              <action type="Rewrite" url="/default.asp?pl={R:1}" />
        </rule>
      </rules>
</rewrite>  

提前感谢任何解决方案:)

修改

经过多次测试后我找到了解决方案:

<httpErrors errorMode="DetailedLocalOnly" existingResponse="PassThrough"/>  

如果我添加与“DetailedLocalOnly”分开的行,我得到的500错误现在使用包含两个参数的一行来解决。

1 个答案:

答案 0 :(得分:1)

也许这只是你web.config中的一个错字。如果以上是您的配置文件,则忘记输入system.webServer标记级别。

我在IIS 8.5上测试了它,它按预期工作。所以ASP产生了 页面返回404状态代码时显示内容。我真的只使用了以下配置:

<configuration>
  <system.webServer>
    <httpErrors existingResponse="PassThrough" />
  </system.webServer>
</configuration>

或者,但不推荐,它也适用于以下配置:

<configuration>
  <system.web>
    <customErrors mode="Off" />
  </system.web>
  <system.webServer>
    <httpErrors errorMode="Detailed" />
  </system.webServer>
</configuration>

对于感兴趣的人,这里是documentation的链接。