The My.Request object represents the HTTP request for the current page in an ASP.NET application. Use this object to read the values sent by a client as part of a Web request. This includes information about the client's security certificate, the browser in use, cookies that were sent, and the query string variables (if any). Used along with My.Response (see below), the My.Request object is a central tool for many ASP.Net applications. See My.Response for an example of using My.Request.
ADVERTISEMENT
My.Resources
The My.Resources object provides read-only access to the application's resources. Resources are data, such as an image or an audio file, that are part of the application. For example, you may have added an image to your project's resources to serve as the splash screen image, and called it SplashScreenImage. Then, in the splash screen form, load the image like this:
The My.Response object is used by an ASP.NET application to send response data to a client. This sample code reads all cookies from the request and sends their names, expiration dates, and values back to the client.
Dim i, j As Integer
Dim ar1(), ar2() As String
Dim CookieColl As HttpCookieCollection
Dim Cookie As HttpCookie
CookieColl = Request.Cookies
' Put all cookie names into a string array.
ar1 = CookieColl.AllKeys
' Get individual cookies by name
for i = 0 To ar1.GetUpperBound(0)
Cookie = CookieColl(ar1(i))
Response.Write("Cookie: " & Cookie.Name & "<br>")
Response.Write("Expires: " & Cookie.Expires & "<br>")
' Get all values for each cookie into an array.
ar2 = Cookie.Values.AllKeys
' Loop through value collection and send each value.
for j = 0 To ar2.GetUpperBound(0)
Response.Write("Value " & CStr(j) + ": " & _
Server.HtmlEncode(ar2(j)) & "<br>")
Next j
Next i
My.User
The My.User object provides access to information about the current user, including their name, whether they have been authenticated, and the type of authentication in use (Windows authentication or custom authentication). This example shows how to retrieve the user name. If the default Windows authentication is in use, the My.User.Name property returns DOMAIN\USERNAME requiring the user name to be extracted.
Private Function GetUserName() As String
If TypeOf My.User.CurrentPrincipal Is _
Security.Principal.WindowsPrincipal Then
' Windows authentication.
Return My.User.Name.Substring(InStr(My.User.Name, "\"))
Else
' Custom authentication.
Return My.User.Name
End If
End Function
My.WebServices
The My.WebServices object provides an instance of each Web service that is referenced by the current project. My.WebServices object will have a property for each Web service, and the name of the property is the same as the name of the Web service. For example, suppose your project references a Web service named PrimeRate that provides the current prime interest rate. You might access it like this:
The My keyword provides the developer with access to a wide range of tools. By knowing that these tools are available you can increase your programming efficiency.