Search code examples
c#asp.nethttpwebrequest

how to solve this :The URI prefix is not recognized


When I am going to add some website like http://www.nirmauni.ac.in/, then it says the above mentioned error. So, how to fix this problem? I have given my code. Just go through and say where the change should be made.

bool IsLinkWorking(string url)
{
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

    //You can set some parameters in the "request" object...
    request.AllowAutoRedirect = true;
    ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;

    try
    {
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        return true;
    }
    catch
    { 
        //TODO: Check for the right exception here
        return false;
    }
}

Solution

  • From Your Error It seems that you are creating a web request with wrong url.

    Please make sure that in (HttpWebRequest)HttpWebRequest.Create(url); url string must start with proper protocol like (http,https etc.)