Solved

How to check for 404 without throwing an exception?

Posted on 2006-07-18
4
706 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 200 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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