Example Code
Start and Stop the Proxy
C#
/// <summary>
/// This method demonstrates how easy it is to start the
/// proxy control. Added to the this form (from the
/// toolbox) was the NetController (the proxy control's
/// main class is WyWare.Stronghold.NetController).
/// Enter your registration code and registration unlock
/// code and then call the Start method of the
/// NetController class. By default the proxy will
/// listen on the IP address 127.0.0.1 and port 999.
/// </summary>
private void btnStart_Click(object sender, EventArgs e)
{
try
{
netController.Start();
MessageBox.Show("The proxy has been started");
}
catch (Exception ex)
{
MessageBox.Show("Failed to start proxy. " + ex.Message);
}
}
/// <summary>
/// This method demonstrates how to stop the proxy.
/// Stopping the proxy is as easy as starting it.
/// To ensure that we don't get a messagebox each
/// time we press the stop button on the form, this
/// methods checks to ensure that it is running before
/// calling the Stop method of the NetController class.
/// </summary>
private void btnStop_Click(object sender, EventArgs e)
{
if (netController.IsRunning)
{
netController.Stop();
MessageBox.Show("The proxy has been stopped");
}
}
VB
''' <summary>
''' This method demonstrates how easy it is to start
''' the proxy control.Added to the this form (from
''' the toolbox) was the NetController (the proxy
''' control's main class is
''' WyWare.Stronghold.NetController). Enter your
''' registration code and registration unlock code and
''' then call the Start method of the NetController
''' class. By default the proxy will listen on the IP
''' address 127.0.0.1 and port 999.
''' </summary>
Private Sub btnStart_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnStart.Click
Try
netController.Start()
MsgBox("The proxy has been started")
Catch ex As Exception
MsgBox("Failed to start proxy. " & ex.Message)
End Try
End Sub
''' <summary>
''' This method demonstrates how to stop the proxy.
''' Stopping the proxy is as easy as starting it. To
''' ensure that we don't get a messagebox each time we
''' press the stop button on the form, this methods
''' checks to ensure that it is running before calling
''' the Stop method of the NetController class.
''' </summary>
Private Sub btnStop_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnStop.Click
If netController.IsRunning Then
netController.Stop()
MsgBox("The proxy has been stopped")
End If
End Sub
Restricting Access to Internet Sites
C#
/// <summary>
/// This method demonstrates how to use the Connect
/// event to control which users have access to browse
/// the Internet. Notice we have also included
/// instructions to block every user to any site that
/// contains microsoft.com in its url.
/// </summary>
private void netController_Connect(object sender,
ref WyWare.Stronghold.NetConnectEventArgs e)
{
if (e.username == "")
{
e.action =
WyWare.Stronghold.NetConnectAction.Authenticate;
return;
}
if (e.url.Contains("microsoft.com"))
{
e.action = WyWare.Stronghold.NetConnectAction.Deny;
return;
}
if (e.username == txtUsername.Text &&
e.password == txtPassword.Text)
{
e.action = WyWare.Stronghold.NetConnectAction.Allow;
lbSites.Items.Insert(0, e.url);
}
else
{
e.action =
WyWare.Stronghold.NetConnectAction.Authenticate;
}
}
VB
''' <summary>
''' This method demonstrates how to use the Connect event
''' to control which users have access to browse the
''' Internet. Notice we have also included instructions to
''' block every user to any site that contains microsoft.com
''' in its url.
''' </summary>
Private Sub netController_Connect(ByVal sender As System.Object, _
ByRef e As WyWare.Stronghold.NetConnectEventArgs) _
Handles netController.Connect
If e.username = "" Then
e.action = _
WyWare.Stronghold.NetConnectAction.Authenticate
Exit Sub
End If
If (e.url.Contains("microsoft.com")) Then
e.action = WyWare.Stronghold.NetConnectAction.Deny
Exit Sub
End If
If e.username = txtUsername.Text And _
e.password = txtPassword.Text Then
e.action = WyWare.Stronghold.NetConnectAction.Allow
lbSites.Items.Insert(0, e.url)
Else
e.action = _
WyWare.Stronghold.NetConnectAction.Authenticate
End If
End Sub
Modifying Response Data
private void netController_Response(object sender, ref NetResponseEventArgs e)
{
if (!e.encrypted)
{
string html = Encoding.ASCII.GetString(e.data);
html = html.Replace("</head>", "</head><h1>Modifying " +
"Response Data Example</h1>");
e.data = Encoding.ASCII.GetBytes(html);
}
}
|