Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem with external URL

Problem with external URL

Scheduled Pinned Locked Moved ASP.NET
tutorialcsharpasp-netcomhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aymen hassine
    wrote on last edited by
    #1

    Hello, In my application, I have the need to test (only test) if a given web address (www.microsoft.com for example) that is provided by my application’s user is a valid url or not. So I tried to reach that external web page from my asp.net web page and I implemented this method: public static bool HttpTestUrl(string url) { bool bResult = true; if(url.StartsWith("/")) url = "http://" + getCurrentHost() + url; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); } catch(System.Net.WebException) { bResult = false; } return bResult; } And here is the result I got: For web address that are in my localhost, it works fine, but with external web address (url like www.microsoft.com for example) it generates an exception. I think I must provide my proxy parameters to the webrequest (I am using a proxy for internet connection) so please tell how to do that and what to add. I am using v1 of the framework. Thanks in advance.

    D 1 Reply Last reply
    0
    • A aymen hassine

      Hello, In my application, I have the need to test (only test) if a given web address (www.microsoft.com for example) that is provided by my application’s user is a valid url or not. So I tried to reach that external web page from my asp.net web page and I implemented this method: public static bool HttpTestUrl(string url) { bool bResult = true; if(url.StartsWith("/")) url = "http://" + getCurrentHost() + url; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); } catch(System.Net.WebException) { bResult = false; } return bResult; } And here is the result I got: For web address that are in my localhost, it works fine, but with external web address (url like www.microsoft.com for example) it generates an exception. I think I must provide my proxy parameters to the webrequest (I am using a proxy for internet connection) so please tell how to do that and what to add. I am using v1 of the framework. Thanks in advance.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You might want to look at this[^] about a probloem while using HttpWebRequest in an ASP.NET page. As for the proxy, did you see, in Intellisense, that HttpWebRequest has a .Proxy property? You can learn more about that here[^]. By default, a WebRequest is created using the default browser proxy settings. If IE (on your IIS server!) doesn't have a proxy configuration, you'll have to specify one in your code.

      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
      Uri newUri = new Uri(@"proxyAddressAsString");
      WebProxy myProxy = new WebProxy();
      myProxy.Address = newUri;
      myProxy.Credentials = new NetworkCredential(@"username",@"password");
      request.Proxy = myProxy;

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups