Solved

If Recordset Null Response 404

Posted on 2012-03-15
5
415 Views
Last Modified: 2012-03-26
Hello,

I have a page that returns results from a recordset..

I want the page to respond with 404 when no records are returned.

I've tried this ---

<% If ISNULL(descript) Then %>
<%
   Response.Status = "404 Not Found"
%>
<%End if%>

But this is doing nothing??

I do have a web.config file with --

<httpErrors  errorMode="DetailedLocalOnly">
     <remove statusCode='500' subStatusCode='100'/>  
     <error statusCode='500' subStatusCode='100' prefixLanguageFilePath='' path='/error/500.asp' responseMode='ExecuteURL'/>  
     <remove statusCode='404' subStatusCode='-1'/>  
     <error statusCode='404' subStatusCode='-1' prefixLanguageFilePath='' path='/error/404.asp' responseMode='ExecuteURL'/>  
</httpErrors>      

So once the 404 is returned, the site should send the user to the custom 404 page...

Clearly I'm doing something wrong, please advise.

Many thanks
0
Comment
Question by:garethtnash
5 Comments
 
LVL 16

Expert Comment

by:brad2575
ID: 37726352
Could you just not do a redirect to your 404 page?

Response.Redirect(URL)
?
0
 
LVL 13

Assisted Solution

by:devlab2012
devlab2012 earned 250 total points
ID: 37732562
You have posted your question under "Active Server Pages". But in your question, you have also mentioned web.config.
In Active Server Pages, there is no web.config. Web.config is used in ASP.NET applications.

Anyway, In your code, replace the line:

   Response.Status = "404 Not Found"

with the following three lines:

Response.clear
Response.Status = "404 File Not Found"
Response.End
0
 
LVL 13

Expert Comment

by:devlab2012
ID: 37732566
Also, note that for the above code to work, the buffering must be on for the page.
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 250 total points
ID: 37738241
i would change

<% If ISNULL(descript) Then %>

to

<% If ISNULL(descript) or if decript = "" Then %>

this is assuming descript is a string variable, if you want to check the actual recordset, you would do

<% If rs.BOF and rs.EOF Then %>
0
 

Author Closing Comment

by:garethtnash
ID: 37764670
Thanks All
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question