All wodCrypt (12) wodSSH (10) wodSFTP (23) wodSSHServer (1) wodSSHTunnel (11) wodSSHpackage wodSFTPdll wodSSH.NET (10) wodSFTP.NET (24) wodFtpDLX.NET (22) wodWebServer.NET (10) wodAppUpdate (13) wodHttpDLX (8) wodFtpDLX (22) wodTelnetDLX wodFTPServer (3) wodWebServer (10) wodVPN wodXMPP (13) | All ** [Visual Basic] ** [C#] ** [VB.NET] ** HTTP Server With SSL
VB code
Option Explicit Dim WithEvents Http1 As wodWebServerCom Private Sub Form_Load() Set Http1 = New wodWebServerCom ' Load Server certificate. If there is no certificate, create new one On Error Resume Next Dim cert As New Certificate cert.Load App.Path & "\cert.pem" cert.LoadKey App.Path & "\cert.key" If Err Then cert.GenerateKey 0 cert.Generate cert.Save App.Path & "\cert.pem" cert.SaveKey App.Path & "\cert.key" End If ' Pass certificate reference to wodWebServer Set Http1.Certificate = cert ' Set Secure property to enable SSL, and Start server Http1.Secure = ProtSSL23 Http1.Start If Err Then MsgBox "There was an error: " & Err.Description, vbOKOnly, "Error" End If End Sub Private Sub Http1_RequestDone(ByVal User As WODWEBSERVERCOMLib.IWebUser) Dim resp As String resp = "<HTML><font face=Verdana size=2>Welcome visitor from " resp = resp & User.RemoteIP & ". This is <b>wodWebServer</b>, version " & Http1.Version resp = resp & "<BR>You requested resource " & User.Request.Path & User.Request.PageName resp = resp & "</font></HTML>" User.Response.Body = resp User.Response.StatusCode = OK End Sub VB.Net code
Dim WithEvents web1 As WeOnlyDo.Server.WebServer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load web1 = New WeOnlyDo.Server.WebServer ' Import the needed certificate Dim cert As New System.Security.Cryptography.X509Certificates.X509Certificate2 cert.Import(AppPath() & "\certificate.pfx", "weonlydo", Security.Cryptography.X509Certificates.X509KeyStorageFlags.Exportable) ' Pass Certificate reference to wodWebServer.Net web1.Certificate = cert web1.Secure = True ' Start the server web1.Start() End Sub Private Sub web1_RequestDoneEvent(ByVal Sender As Object, ByVal Args As WeOnlyDo.Server.WebRequestDoneArgs) Handles web1.RequestDoneEvent Dim resp As String resp = "<HTML><font face=Verdana size=2>Welcome visitor from " resp = resp & Args.User.RemoteIP & ". This is <b>wodWebServer.NET</b>, version " & web1.Version resp = resp & "<BR>You requested resource " & Args.User.Request.Path & Args.User.Request.PageName resp = resp & "</font></HTML>" Args.User.Response.Body = resp ' don't forget to set status code and content type Args.User.Response.Headers("Content-Type").Value = "text/html" Args.User.Response.StatusCode = WeOnlyDo.Server.StatusCodes.OK End Sub Public Function AppPath() As String AppPath = System.IO.Directory.GetParent(System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory).ToString).ToString End Function C# code
private WeOnlyDo.Server.WebServer web1; private void Form1_Load(object sender, EventArgs e) { web1 = new WeOnlyDo.Server.WebServer(); web1.RequestDoneEvent += new WeOnlyDo.Server.WebServer.RequestDoneDelegate(web1_RequestDoneEvent); System.Security.Cryptography.X509Certificates.X509Certificate2 cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(); // Import the needed certificate cert.Import(AppPath() + "\\certificate.pfx", "weonlydo", System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.Exportable); // Pass Certificate reference to wodWebServer.Net web1.Certificate = cert; web1.Secure = true; // Start the server web1.Start(); } void web1_RequestDoneEvent(object Sender, WeOnlyDo.Server.WebRequestDoneArgs Args) { String resp = String.Empty; resp = "<HTML><font face=Verdana size=2>Welcome visitor from "; resp += Args.User.RemoteIP + ". This is <b>wodWebServer.NET</b>, version " + web1.Version; resp += "<BR>You requested resource " + Args.User.Request.Path + Args.User.Request.PageName; resp += "</font></HTML>"; Args.User.Response.Body = resp; // don't forget to set status code and content type Args.User.Response.Headers["Content-Type"].Value = "text/html"; Args.User.Response.StatusCode = WeOnlyDo.Server.StatusCodes._OK; } private String AppPath() { return System.IO.Directory.GetParent(System.IO.Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).ToString()).ToString(); } |