C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to find out if proxy is enabled in the local computer


Posted Date: 19 Apr 2005    Resource Type: Articles    Category: .NET Framework

Posted By: Tony John       Member Level: Gold
Rating:     Points: 10



How to find out if proxy is enabled in the local computer

There are couple of ways we can retrieve the proxy settings in C# or VB.NET.

Method 1 : Read the settings directly from the registry.

When we change the proxy settings thorugh Internet Explorer, the settings is stored in the registry. We can read the registry values to check if the proxy is enabled and find the proxy server.

Microsoft.Win32.RegistryKey key =
Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings");

string proxyEnabled = key.GetValue( "ProxyEnable" ).ToString();

The following code will return the proxy server address specified in the IE settings, even if it is not enabled.

string proxyServer = key.GetValue("ProxyServer") == null ? string.Empty : key.GetValue("ProxyServer").ToString();


Method 2 : We can use the Webproxy class to get details about the current proxy settings.

System.Net.WebProxy webProxy = System.Net.WebProxy.GetDefaultProxy();

bool bypassProxyForLocal = webProxy.BypassProxyOnLocal;

Uri address = webProxy.Address;
if ( address != null )
{
string host = address.Host;
string port = address.Port.ToString();
}

Using the WebProxy class is a better solution. It exposes various properties using which we can retrieve information related to the proxy settings including port number, host address etc. Reading from registry directly returns a single string, which we may need to parse to extract the host address and port number.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Embedding HTML into ASP.Net Form
Previous Resource: Subscribing and un subscribing event handlers
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing services

Contact Us    Privacy Policy    Terms Of Use