4
votes

I have a simple question:

Is possible to send the Response.Status = "404 Not Found" from a .asp page, but continue to render the actual page?

Seems that when i send Response.Status = "404 Not Found" IIS moves to the default 404 error page, while i would like to continue to render my page. This is a case of a CMS where for some reason someone can type a unexistent permalink and want to display a "OPS not found content page" instead to redirect to a custom or default 404 asp page.

there is a specific web.config setup?

I've followed discussion here: Configuring custom ASP 404 page with redirect for IIS7 website

And thought to use then option

<httpErrors existingResponse="PassThrough" />

But for some reason it gave me error 500. The IIS version is 8.5 asp 3.0 / .NET 3.5

my actual web.config is:

<?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>  

Thank in advance for any solution :)

EDIT:

After many test i found the solution:

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

The 500 error i get if i add the line separate from the "DetailedLocalOnly" is now solved using a one line with both param.

1

1 Answers

1
votes

Maybe it is only a typo in your web.config. If above is your configuration file, you forgot to enter the system.webServer tag level.

I tested this on IIS 8.5 and it worked as expected. So the ASP generated content was shown while the page returned a 404 status code. I really only used following configuration:

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

Alternatively, but not recommended, it also worked with following configuration:

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

For the interested, here is the link to the documentation.