Solved

If Recordset Null Response 404

Posted on 2012-03-15
5
405 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 32

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now