sysadmin2
asked on
How do I create a session variable in the global.asax file from the LoginName and then display it on my default.aspx page.
Thank you in advance for your help.
I am attempting to create a session variable "ULogon" in the Session_Start section of the global.asax file. The particular is that I would like to assign the LoginName to the ULogon session variable. I have attempted this many different ways, but I have not been successful. The second part is displaying this session variable on the default.aspx page. I just starting to learn ASP.NET and C# so please bear with me.
I am attempting to create a session variable "ULogon" in the Session_Start section of the global.asax file. The particular is that I would like to assign the LoginName to the ULogon session variable. I have attempted this many different ways, but I have not been successful. The second part is displaying this session variable on the default.aspx page. I just starting to learn ASP.NET and C# so please bear with me.
ASKER
Velio, thank you for your help. I think I need to make something clear about the words "LoginName" I used above. This is the LonginName control that is in the tool box in Visual Web Developer 2008 Express Edition. My site is on an intranet using Active Directory. When I add the LoginName control to a page it clearly shows domain\user. I want to get this value into the session variable "ULogon" so I can use it to display on a page. What I did not include in the earlier description is that I also want to use the session variable in a database query to filter the results. I knew if I could get it into the session variable I could do the database filter myself. If I misled you on the inital post, I do appologize. My main struggle is getting the LoginName control value into a session variable. With that said, your code above does display "myValue" on the default page. Does getting a session variable to display in asp.net require that much code? In the old asp, a simple <%=Session("myVariable")%> would display a session variable. Thanks again for your help.
ok, then the global.asax doesn't even come into play.
if you're using windows authentication, you don't even need a session variable,
use Page.User.Identity.Name to get the currently logged in user's name. every page in your website will have this, so it will be accessible everywhere on the site, and can be passed along to any database modules.
if you're using windows authentication, you don't even need a session variable,
use Page.User.Identity.Name to get the currently logged in user's name. every page in your website will have this, so it will be accessible everywhere on the site, and can be passed along to any database modules.
ASKER
I thought this should be simpler because of Active Directory and the intranet context. The reason I was using LoginName is that from what I have read, Page.User.Identity.Name is what LoginName gives you:
(http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.loginname.aspx).
My problem is getting this into a variable. I may be making this too hard or I am just completely ignorant of the syntax. To simplify, can you give me the code to put Page.User.Identity.Name or LoginName into a variable? I was thinking I would need a session variable in the global.asax file so it would be an option when I setup the filter as I build the SQLDataConnector in the wizard. If it can be done without the Session variable, I am all for it. Thanks again.
(http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.loginname.aspx).
My problem is getting this into a variable. I may be making this too hard or I am just completely ignorant of the syntax. To simplify, can you give me the code to put Page.User.Identity.Name or LoginName into a variable? I was thinking I would need a session variable in the global.asax file so it would be an option when I setup the filter as I build the SQLDataConnector in the wizard. If it can be done without the Session variable, I am all for it. Thanks again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
does it differ from your code and how?
if all you need is the username, you could use the System.Web.UI.Page.User property which all your pages will have.
Open in new window