Check the page (URL)

  • Thread starter Thread starter Just D.
  • Start date Start date
J

Just D.

Does anybody know how can we check if the URL exists inside currently
running web application written in C#? For example I'm having the page name
like: "SomePage.aspx" and I need to know if this URL exists and I can safely
redirect to it or I should make some replacement for this url if it doesn't.
Can we control the method Response.Redirect(SomeURL) ?

Just D.
 
Just said:
Does anybody know how can we check if the URL exists inside currently
running web application written in C#? For example I'm having the page name
like: "SomePage.aspx" and I need to know if this URL exists and I can safely
redirect to it or I should make some replacement for this url if it doesn't.
Can we control the method Response.Redirect(SomeURL) ?

You probably want to do something like this:

if (File.Exists(Server.MapPth(your_url)))
{
...
}

And don't forget to use System.IO
 
You would need to use an HttpWebRequest and an HttpWebResponse object to do
this. Create the HttpWebRequest with the desired URL, using the
WebRequest.Create(url) method. Then use the GetResponse() method to get the
HttpWebResponse. The HttpWebResponse will have the status code returned from
the server. This will tell you if the URL exists or not. 404 indicates "Page
not Found." 200 indicates "Success." Etc.

For more detailed information, see:

http://msdn.microsoft.com/library/d...ml/frlrfsystemnethttpwebrequestclasstopic.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top