How can i get the Session Value


I need to get the value of a session here:-

                <a href='<%# "view-photo.aspx?PhotoID="+Eval("album_id")+"&AlbumID="+ Eval("album_id")+"&~UID="+ Eval("user_id") %>'> 

I need Eval(“MEM_ID”) to be equal to the person who is logged in. How can i get the session from here?

This is how i bind, see i am trying to add Session Parameters but it ddoes not pick this up…

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="Data;User ID=wbsd;Password=*******" 
            SelectCommand="SELECT [photo_id], [photo], [photo_name], [album_id] FROM [hussaini_photo_album] WHERE ([album_id] = @album_id) ORDER By [photo_id] ASC" 
                    <asp:QueryStringParameter DefaultValue="1" Name="album_id" 
                        QueryStringField="album_id" Type="Int32" />
                        <asp:SessionParameter DefaultValue="1" Name="user_id" SessionField="MEM_ID" Type="Int32"/>


Do you set a session when the user logs in? As that should work. Just remember. That sometimes the session expires before the Auth cookie. You could also use User.Identity.Name to get the auth cookie login name.

Not sure how you would use that like that tho. As I never use a SqlDataSource on the front end. I usually only bind to generic lists from my business layer.


Im actually using a session not cookies so i cant use User.Identity.Name,

When i run the code i have, i get an error as it does not recognize user_id…

I dont know why it does this…

Well, like I said. I do not use that method, so I cannot say why its not working. Looks right to me.

Just a question? Y do you not use auth cookies? It is a lot more reliable than sessions. As sometimes sessions get lost if the worker process needs to be reset or something.

Anywayz, maybe some1 can give u advice on y that is not working.

Like this:

the code just the same as the ‘.cs’ file

ok thanks

What does that mean? What code is the same as the .cs?

I have enough posts,so i cannot get you the complete answer?
but <%# session[“id”].toString()%>,you can get the session value;
is this what you want?

sorry!i mean i hava no enough posts(i droped a word)

Except the sytnax is wrong. Case wise. It should be:

<%= Session[“id”].ToString() %>

Although you can omit the .ToString() part as it is no longer needed.


<a href=“index.aspx?id=<%=Session[“user”] %>”>dfsdfsf</a>
i have checked it out