Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Cookies to filter in ASP.Net 2.0

    Hi,

    I've spent the WE reading everything I can find on cookies and using them to filter a datalist in ASP.net 2.0. I'm using a sql server 2005 with this. I've set my IIS to forms authentication and have made sure that cookieless mode is set to "use cookies". The session state mode is inProc. The http cookie name is ".ASPXAUTH".

    When I add the datalist control and do not set the "where" statement it shows all records. When I go in to reset the where statement to "cookies' and set the cookie name to ".ASPXAUTH" nothing returns. I've tried setting the where statement on both the userid and username. The result is always nothing being returned.

    I've generated my web.config file using the wizard and this is what is returned

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <appSettings/>
    <connectionStrings>
    <add name="ConnectionString2" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory |ASPNETDB.MDF;Integrated Security=True;User Instance=True"
    providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
    <roleManager enabled="true" />
    <authentication mode="Forms" />
    </system.web>
    </configuration>

    I'm not even sure if I'm on the right track or if I am (one can only hope) what I'm missing.

    Thanks!
    Leesha

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Cookies to filter in ASP.Net 2.0

    Is the cookie supposed to contain the userid and/or username? Do you know whether the cookie actually contains the data you expect? You could add a statement on your page to display the value of the cookie. Or, according to the following article, you could temporarily turn on tracing to report all the cookie values, along with other information: http://www.asp101.com/articles/rober...ng/default.asp.

  3. #3
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Cookies to filter in ASP.Net 2.0

    Hi!

    I honestly don't know what the user contains. I'm "assuming" it's the userid as most of what I've read says that it "automatically" contains an encrypted version of the user name and is established when the authentication process is set up. I've spent days looking for something that would clearly explain the cookie process for a newbie like me and not start somewhere in the middle assuming I have a clue. I've got the tracing turned on but that has been of little help. I look forward to reading the post you referred to. I don't want the cookies to show on the page and I need to figure out how I am to gather them and then, then name then so I can refer to them in the filter. I feel like I'm so close and yet the answer has eluded me. As usual I've learned a lot in my search and reading, just not what I need to get past this latest wall.

    Thanks,
    Leesha

  4. #4
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Cookies to filter in ASP.Net 2.0

    Hi!

    I've never been so frustrated in my whole life! I'm learning alot but getting nowhere in my quest. I read the link you sent plus a bunch more and made some changes but still am lost.

    This is what I've done. I have a page that loads after the user has logged in has the following code:

    Private Sub AddCookie()

    Dim NameCookie As New HttpCookie("UserName")
    NameCookie.Expires = Now.AddYears(1)
    Response.Cookies.Add(NameCookie)

    End Sub

    Nothing shows on the page itself when it loads showing the UserName not only because I don't want it to but also because I don't have a clue as to how to make it show. The tutorials I've been doing work but only if I type in exactly what they have.

    There is a sqldatasource with a datalist control on the page. I configured the datasource to filter by the cookie - the attachment shows how I configured it. I was hoping someone might see what I'm doing wrong as I don't see it.

    tried putting a loginview control on the page with a loginName in it and the control works fine so I know the user is logged in succesfully.

    My books and sources on the internet all seem to start at step 3 or 4 figuring I know step 1and 2 and I don't!! Can anyone either see what I'm doing wrong here or send me to a link that starts with step one on how to code to use cookies in asp.net 2.0 and where to put the code. Is it on the load event, etc.? The user will have already entered their username and password on the login page so I don't want them to have to enter it a second time once logged onto a site and then push a button to make anyting happen which is the the tutorials have me do when explaining how cookies work.

    Finally, I have placed the follwing code on my web.config file:

    <sessionState mode="InProc"
    cookieless="AutoDetect"
    timeout="30"
    />

    Thanks,
    Leesha
    Attached Images Attached Images

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Cookies to filter in ASP.Net 2.0

    As noted, I don't know ASP.Net. However, based on my experience with Classic ASP, I probably would store the login username in a session variable rather than in an actual cookie. When you access a session variable, you know that the server has determined which user is requesting the page, and made available the correct information. This assumes that you are using sessions and the user is accepting session cookies. But I guess they need to be accepting cookies using either approach.

  6. #6
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Cookies to filter in ASP.Net 2.0

    Edited by HansV to correct tags - you can't use HTML in the Lounge! See <!help=19>Help 19<!/help>

    Hi!

    Well I ended up not using cookies at all. I ended up using "select parameters" which Rob Mills @ http://www.dotnetadvisor.com/ helped me with. He's a great reference for anyone new to asp.net 2.0.

    Thanks for the help!

    Leesha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •