Thursday, December 22, 2011

Check If URL Exists in ASP.Net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;

namespace MyHttpHandler
{
public class URLChecker
{
protected bool DoseUrlExits(String UrlToCheck)
{
WebRequest req = WebRequest.Create(UrlToCheck);
WebResponse res;

bool IfUrlExitsFlag = false;
try
{
res = req.GetResponse();
IfUrlExitsFlag = true;
}
catch (Exception)
{
IfUrlExitsFlag = false;
}

return IfUrlExitsFlag;
}
}
}

No comments:

Post a Comment