How to find out the host address of the caller of webmethod

by Andrew Jackson 13. October 2009 11:58
On the server inside the webservice method call, you have access to the HttpContext object. Using HttpContext.Current, you have access to a number of objects (including the request object).

From the request object you can find out information, including the host address from which the request comes from.

If you need to map this address to a hostname , you can use UserHostName property instead

' Example web method
<WebMethod()> _
Public Function TestMessage( ) as String

Trace.WriteLine("GetMessage called from : " + HttpContext.Current.Request.UserHostAddress + " " + HttpContext.Current.Request.UserHostName )

Return "Hello"

End Function

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.net | Development | VB.net

Enabling/Disabling a Windows Forms Close Button

by Andrew Jackson 13. October 2009 11:53
#Region " Enable\Disable a Form's Close Button "

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer

Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer

Private Const SC_CLOSE As Integer = &HF060

Private Const MF_BYCOMMAND As Integer = &H0

Private Const MF_GRAYED As Integer = &H1

Private Const MF_ENABLED As Integer = &H0

Public Sub DisableFormCloseButton(ByVal form As System.Windows.Forms.Form)

' The return value specifies the previous state of the menu item (it is either

' MF_ENABLED or MF_GRAYED). 0xFFFFFFFF indicates that the menu item does not exist.

Select Case EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)

Case MF_ENABLED

Case MF_GRAYED

Case &HFFFFFFFF

Throw New Exception("The Close menu item does not exist.")

Case Else

End Select

End Sub

Public Sub EnableFormCloseButton(ByVal form As System.Windows.Forms.Form)

EnableMenuItem(GetSystemMenu(form.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND)

End Sub

#End Region

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Development | VB.net

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen