Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grab values from header and assign them to variables 1

Status
Not open for further replies.

chilly442

Technical User
Jun 25, 2008
151
US
After a user logs in to my application, I need to grab some info from the header and assign those values to variables.
This is what I have right now:

Code:
UserName = Request.Headers("UserID")
RoleID = Request.Headers("RoleCode")

UserName and RoleID are strings that are passed through out the application.

1. Is the way to do this? If not please help!!!
2. Should this go into the Page_Load event?

Thanks,
Chilly442
---------------------------------------
If I lived anywhere else I'd be Sunny442
 
no, pull this from the request's identity instead.
I believe in a Page object there is a User or Identity property. this will contain the username and roles. You can also access the identity from HttpContext.Current.Identity.Principle

the Identity is a property of the page object, you can access it at any point in the page object, not just Page_Load.

Since you are using webforms to service your web requests I would recommend learning
1. the webforms page lifecycle
2. the asp.net pipeline
3. the properties/members of the webform's Page/UserControl objects.

this will help eliminate some confusion when determine when/how/what data you need access to.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
This is the solution that I came up with.
Code:
'--Get User's UserID-- 
            If Session("UserID") Is Nothing Then
                If Request.Headers("UserID") IsNot Nothing Then
                    Session("UserID") = Request.Headers("UserID")
                    UserName = Request.Headers("UserID")
                Else
                    Session("UserID") = String.Empty
                End If
            End If

            '--Get User's RoleCode--
            If Session("RoleCode") Is Nothing Then
                If Request.Headers("RoleCode") IsNot Nothing Then
                    Session("RoleCode") = Request.Headers("RoleCode")
                    RoleID = Request.Headers("RoleCode")
                Else
                    Session("RoleCode") = String.Empty
                End If
            End If

Thanks,
Chilly442
---------------------------------------
If I lived anywhere else I'd be Sunny442
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top