tags:

views:

85

answers:

2

Designing a Windows Forms application using C#, i am facing a problem. The application performs its functions smoothly when connected to the Internet but the real problem starts when we try the application in our College.

Our College connects to the Net using proxy gateways. The Proxy server is "192.168.120.5" and Proxy Port "8080".Every Student is given an unique user name and password.

How can i get ahead through this obstacle ?? Will using

WebRequest request = WebRequest.Create("http://www.mysite.com");  
request.Proxy = new WebProxy("192.168.120.5", 8080); 

help me in any way ?? . If yes, where do I enter the Username and Password Credentials

Thanks for helping out

A: 

yes you can use that... though it may be simpler use the WebRequest.DefaultWebProxy

WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
proxyObject.Credientials = new NetworkCredential(UserName, "bla");
WebRequest req = WebRequest.Create("http://www.contoso.com");
req.Proxy = proxyObject;

though as a side note you may be able to use the local default credentials by setting

proxyObject.UseDefaultCredentials = true;

If you do try to use that you have to make sure that proxyObject.Credintials = null.
The msdn site on all of this is here MSDN WebProxy

Eric Fode
A: 

@Eric Fode

Thanks for the reply :)

Apparently I also added the below code in app.config file

<system.net>
<defaultProxy>
  <proxy autoDetect="True"/>

 </defaultProxy>

Using the code you gave in a button click event did not work at all!!! What do you think can be the problem. The Credentials are the same as it works for the Browser but not for the application.

One More Query that arises in my mind is that using proxyobject.UseDefaultCredentials="true"; which default credentials will be used !!

Thanks for the help

Karthik