发送Response.Status =“404未找到”,但让IIS保持在同一页
问题描述:
我有一个简单的问题上:发送Response.Status =“404未找到”,但让IIS保持在同一页
可以发送Response.Status =“404未找到”从.asp的页面,但继续渲染实际页面?
似乎当我发送Response.Status =“404未找到”IIS将移动到默认的404错误页面,而我想继续呈现我的页面。这是CMS的一种情况,出于某种原因,某人可以键入未提供的永久链接,并且希望显示“OPS未找到的内容页面”,而不是重定向到自定义或默认的404页面。
有一个特定的web.config设置?
我已经按照这里的讨论: Configuring custom ASP 404 page with redirect for IIS7 website
而且想到要用然后选择
<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"/>
我得到的500错误,如果我添加行与“DetailedLocalOnly”分开现在解决使用两个参数一行。
答
也许它只是你的web.config中的一个错字。如果上面是您的配置文件,则忘记输入system.webServer
标记级别。
我在IIS 8.5上测试了它,它按预期工作。因此,当页面返回404状态码时,会显示ASP生成的 内容。我真的只用以下配置:
<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。
嗨,是的,我忘了粘贴在web.config的顶部和底部: .... 系统。webserver> configuration> –
Hart
我已经添加了这条线,如你所说,但我得到错误500 :( – Hart
编辑:我检查,如果存在 anwith passThrogugh它给我500错误。 –
Hart