Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to check for 404 without throwing an exception?

Posted on 2006-07-18
4
Medium Priority
?
710 Views
Last Modified: 2008-01-09
I want to check for the availability of a file on a web server, using the .net framework. I can easily use a WebClient or WebRequest to attempt to get data from the URL, then catch the exception that is thrown if the requested file doesn't exist.

But I want to perform this check without exceptions - I don't like using exceptions to control program flow. Is there a way to get the headers back from the web server and check them myself, or to tell some framework class to just get me the data and ignore the 404 indication in the header?
0
Comment
Question by:jgr4
[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
4 Comments
 
LVL 1

Accepted Solution

by:
winsoftech earned 600 total points
ID: 17143803
u can use xmlhttp method to call the page
using xmlhttp.open(url,'','')
this will rerutn status (xmlhttp.status)
if page is not present then it will return 404

u can use this to check for 404 without throwing an exception

it's not complete code u have to find on xmlhttp
0
 
LVL 3

Expert Comment

by:HouseMusic
ID: 17150181
You can use the custom errors section of your web.config to redirect them to a specific error page for that error (i.e. errorpage.aspx) and handle it in that "errorpage.aspx"

0
 
LVL 2

Author Comment

by:jgr4
ID: 17151167
winsoftech - that's a good hint and I'll give you the points if nothing better comes along, but I'm really looking for a way to do this from inside the .NET framework. I'm doing this from what will be a freeware app and I don't want to deal with versioning issues.

HouseMusic - I'm the client, not the server. This is a windows app looking for files on other people's webservers.
0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

730 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