how to solve this :The URI prefix is not recognized

42,044

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.)

Share:
42,044
hitarth
Author by

hitarth

student of comp engg in diploma

Updated on February 28, 2020

Comments

  • hitarth
    hitarth about 4 years

    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;
        }
    }
    
  • Sachin
    Sachin about 11 years
    @hitarth can u give me the any value of textBox that you checked for non-working example.?
  • Sachin
    Sachin about 11 years
    @hitarth which protocol nirmauni.ac.in supports? you need to add accordingly protocol. like this nirmauni.ac.in (in case of http protocol). your url parameter ultimately must have some protocol to create valid request.
  • hitarth
    hitarth about 11 years
    hey it is checking this url "javascript:go();" so it happens? and yes you are right i got you but how it can be done so "your url parameter ultimately must have some protocol to create valid request"
  • Sachin
    Sachin about 11 years
    it's all depends on you. either you can do is, "don't allow user to enter Url without http or any other protocol(by using Url validation) or you can just check the user input and accordingly add to user input and before passing it to WebRequest.Create(url) function
  • hitarth
    hitarth about 11 years
    yes i got you ,but here i have entered the url proper only but string checkes or webrequest is gone to "javascript:go();" is their any solution to passes this href
  • Sachin
    Sachin about 11 years
    I guess go() is your javascript function. So if you want to pass then just change the function like this go(url) and pass url value from wherever you are calling this method. Hopefully you got it and please mark my solution as answer.:)
  • coderpc
    coderpc over 6 years
    Saved !! Cheers !!