?
Solved

If Recordset Null Response 404

Posted on 2012-03-15
5
Medium Priority
?
421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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 1000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 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