commlinx
Posts: 2
|
Posted: 08/12/2008, 1:15 AM |
|
I'm new to CCS and .NET development not having done much web development for five years or so. I've created a page header and would like to display the name of the currently logged in user on the header. I've looked at the examples / help and came up with the following code in the AfterInitialize event for the header page:
protected void Page_AfterInitialize(object sender, EventArgs e) {
if (DBUtility.UserID != null)
UserLogin.SetValue(DBUtility.UserLogin);
}
However when trying to publish and run I get the following error / highlighted code line:
Compiler Error Message: CS0103: The name 'DBUtility' does not exist in the current context
if (DBUtility.UserID != null)
I looked at several examples and made sure that I was using all the same classes at the top of the ascx.cs file. Is there something different I should be doing to do this sort of thing in a page header?
|
|
|
tsgroman
Posts: 64
|
Posted: 08/12/2008, 6:47 PM |
|
The UserLogin is exposed through the Session("UserLogin") variable by default.
Drop a label on a page and add a 'Retrieve Value for Control' Action to the 'Before Show' server event.
Control Name = the name of the label
Source Type = Session
Source Name = UserLogin
The defaults can be changed via the Project -> Settings -> Security -> Advanced.
|
|
|
commlinx
Posts: 2
|
Posted: 08/12/2008, 8:34 PM |
|
Hi tsgroman, thanks very much for your reply. Originally I was keen to use my own code because I wanted to retrieve a few other pieces of information like a full name and access rights from the database, however realised I'm best to avoid this because among other things I was getting the designer in a state where it wouldn't keep the code up to date.
In this case what I can do is use some DLookup events for the other fields and just tried the following in the Criteria and it worked fine:
"[UserID] = " + ((Session["UserId"] == null) ? "-1" : Session["UserId"])
When I had a further look I also found a class called Utility under the InMotion security classes that provide some wrappers such as Utility.UserLogin, they also just retrieve the information from the session.
|
|
|
dragoon
Posts: 173
|
Posted: 08/25/2008, 1:44 PM |
|
commlinx, if you have too many fields that you want to retrieve you better make use of some custom code and grab all of them in one query, instead having a query for each 'property' of the logged user.
This in just an ideea ... on the other hand, having as much as possible bits of code in designer is easier...
Of course, it depends of the scale of the application you're trying to build...
|
|
|
|