?
Solved

Keeping session variables using a datalist and asp:hyperlink

Posted on 2006-04-03
12
Medium Priority
?
389 Views
Last Modified: 2008-02-01
I am having a problem keeping my session variables when i used a datalist and a hyperlink,
here is my code:
<asp:HyperLink Runat="server" Text="Create" ID=hyperlink Target="_self"  NavigateUrl='<%# "/C.aspx?a=" + DataBinder.Eval(Container, "DataItem.id") %>'></asp:HyperLink>
0
Comment
Question by:jasondole
  • 5
  • 5
  • 2
12 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 16368335
If you are bindign them dynamicly, you'll need to bind them again after every postback.
0
 
LVL 1

Author Comment

by:jasondole
ID: 16371224
my program worked when i used the asp:hyperlinkcolumn, but when i switched to a datalist and used the  asp:hyperlink, it does not, i am using a session variable as a means to tell if the user is logged in or not, is there a way around this?
0
 
LVL 14

Expert Comment

by:existenz2
ID: 16373779
I need more code to see what is causing the problem. Any chance you could post that?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jasondole
ID: 16376776
What part of code do you need so i can post it because i am unsure what you are asking for since i thought what i put would be able to answer what is needed, the rest does not deal with what i need to do, what i meant by my last comment was that when i used a datagrid, and used the asp:hyperlinkcolumn my session variables were kept but when i went to a datalist and used the asp:hyperlink, my session variables are lost.  My session variables are set by a control that sets the variable once a person logs in... please let me know so i can provide the correct information....thanks for your help.....
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 16391547
How is it that you know your session variables are lost? I assume your datagrid is in one page (perhaps B.aspx) and you are transferring to C.aspx?<anIdNumber>. Then in the Page_Load of C.aspx you are trying to access the session variables and they are coming back as null?

Andy
0
 
LVL 1

Author Comment

by:jasondole
ID: 16393026
yes, you are correct, i am using my session variables as a way to know if my user is logged on, and every time i access the asp:hyperlink it directs me to my page that i am not logged in, this led me to believe my session variables were not being kept when i went to the new page
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 16393904
I would guess that, if your session variables really are disappearing, then you are having problems with the session cookie for your users. Are you using Visual Studio? Could you debug the application and check the session at each point during the login, getting to the datagrid page, redirecting to C.aspx? You could, for instance, put a line in the global.asax Application_AuthenticateRequest method, set a breakpoint on it and check the session contents each time as this will fire at the start of every request.

I would also recommend using Fiddler, which is free (http://www.fiddlertool.com/Fiddler/help/hookup.asp) to examine your requests and check your session cookie is being set , and is staying the same between your requests - especially for the requests where you think the session is being lost.

Is there a reason that you are using Session variables to track your login and not Forms authentication? Forms authentication is very easy to set up, and means that you don't have to worry about maintaining your own authentication, just actually verifying the username/password.

Andy
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 16429940
Did you get anywhere with this?

Andy
0
 
LVL 1

Author Comment

by:jasondole
ID: 16448698
I am using session variable so when somebody uses the login control, we set a session variable to see they are logged in, then every page we check to see if this session variable is set and if it is not set, we redirect them to a page that tells them to log in.  I am not sure how we would accomplish with form authentication??   I haev not been able to find a solution to this problem and the time it is taking i am open to any new ideas on how i could accomplish the same functionality.
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 16450324
Forms authentication will do _exactly_ what you say you want to do. All you need to do is specify a line in your application's web.config that states you are using form's authentication, and the login page for the authentication. It will handle the rest, protecting all resources handled by ASP.NET underneath that application directory. On the login page itself, you need to set the forms cookie, and that's it.

An example of the web.config lines are:
            <forms name="appNameAuth" path="/" loginUrl="login.aspx" protection="All" timeout="30"/>

And the C# code to login a user reads:
    // get username and password, check them against the database, if succesful then do:
    FormsAuthentication.SetAuthCookie(strUserName, false);

Andy
0
 
LVL 1

Author Comment

by:jasondole
ID: 16489235
we are trying to not use cookies to do our authentication, we wanted to make our site cookieless....
0
 
LVL 12

Accepted Solution

by:
AGBrown earned 1500 total points
ID: 16494390
So you are using cookieless sessionstate, sorry, I didn't realise. If you are using cookieless sessionstate, you have to be _very_ careful when you put url links into a href tags on a page; if you change the case of the text in the link it can fail:
http://support.microsoft.com/?kbid=828330

Does your code look like it might be struggling with case sensitivity in the links?

Andy
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses

850 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