[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Public Property in ASP.net using VB.net

Posted on 2006-04-16
2
Medium Priority
?
353 Views
Last Modified: 2008-02-01
Hello,

I am using session.item("username") in many places in my ASP.net application. if I declare a Public property, can I just use the propertyname instead of using session.item("username") in many places??

if yes.

How do I create a public property which can store username and how do I retreive the property and use it in all my other pages.
0
Comment
Question by:sureshraina
  • 2
2 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16466189
You could create a class with a shared method and have that return the username...if thats what you mean.


Public Shared Property Username As String
    Get
        Return Session("username")
    End Get
    Set (ByVal value As String)
        Session("username") = value
    End Set
End Sub

Essentially this creates a wrapper around the session variable.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 16466191
To use it, you wrap it in a class, like:

Public Class UserDetails
    Public Shared Property Username As String
        Get
            Return Session("username")
        End Get
        Set (ByVal value As String)
            Session("username") = value
        End Set
    End Sub
End Class

Then in your code you access it with something like:

   Response.Write(UserDetails.Username)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month18 days, 7 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question