Monday, 6 August 2012

How to check for url accessibility before providing a urlfield ?


Reffered To My Answer

These links
 bool exist = false;
 try
 {
      HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create("http://www.example.com/image.jpg");
      using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
      {
           exist = response.StatusCode == HttpStatusCode.OK;
      }
 }
 catch
 {
 }

And if In Internal Server in your Project you can use Login of File.Find (you can check before Redirecting..  that project file exist or not?)
Do a File.Exists on the page.
  if(File.Exists(Server.MapPath("~/SomePage.aspx")))
    Response.Redirect("~/SomePage.aspx");
You'll need to use the System.IO namespace.
Good Luck`

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More