Limiting records returned by sqldatasource using session variable in where clause

I have a web application with a Sql Server database on the server. Since the site will be deployed to different clients (or different virtual directories in IIS), each client derived site will use the same backend.

There is an admin page where the text on the site can be changed (enter text in the list and select a page to choose where this text will be displayed, and you can also see company-specific details in other lists. Since this is a general base data, this means that the client can see each other's data.

What I am trying to do is store the accountId (the manual returned from the database from login_authenticate) and bind it to the session. Then I retrieve this from the admin page and I want to use that value (but always 0000-0000, etc.) to restrict the entries returned in the list.

Is there an example of this? Also, how can I set the default (this is in the where clause of the SqlDataSource) to programmatically specify the account id (so I can give me all the records = what the current account is, or perhaps what is the login - this is stored in the account table).

thank

+1


source to share


2 answers


This is what I have tried.

What I'm confused, however, is whether the where clause when using the session object gets the object I wrote, the code to retrieve from the session, or the object I just added but didn't get. I get the account id when I log in (validated with stepping - obviously - or login fails).



I'll try again with persisting the object in the @ session on the login page, when I just returned the accountid variable and then fetch it to another page.

For some reason I keep getting 0, so I will look at this in my application.

+1


source


It looks like your method should work. I would follow the debug process:

  • Make sure you get the accountID value from the database. Print it on the screen immediately after getting the value for the first time.
  • If that works, store the value in the session and get it right away, and make sure you return the value.
  • Create 2 test pages where you set a session variable and another where you retrieve it.


I know this seems to be really basic, but the failure is being implemented somewhere in the above three places. If you find which step failed, you can fix it.

0


source







All Articles