smithmrk
asked on
ASP.net Cookies (VS2005)
OK, this seems so simple...but I'm not having much luck with this!
Here is what I'm trying to do...I have a RadioButtonList that displays a list of reports.
These reports all have different types of Paramaters that need to be passed in to the SQL Statement to produce the correct report.
As the user selects a report I want to update the Cookie with ALL the paramater information so that when the click the Run Report Button I can grab those parameters from the cookie and produce the report.
Here is the code for the RadioButtonList:
Dim MyReportDataView As DataView
MyReportDataView = CType(SQL_WebReports.Selec t(DataSour ceSelectAr guments.Em pty), DataView)
'Get the Report ID and the Parameters for that Selected Report:
Dim myCookie As HttpCookie = New HttpCookie("ReportParamete rs")
For Each MyRow As DataRowView In MyReportDataView
myCookie.Values("Report_St oredProced ure") = Trim(MyRow("StoredProcedur e"))
myCookie.Values("Report_Fi leName") = Trim(MyRow("ReportName"))
myCookie.Values("Report_Pa rameters") = Trim(MyRow("Parameters"))
myCookie.Values("Report_Lo cation") = "Reports\" & Trim(MyRow("ReportName"))
myCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(myCoo kie)
Next
Here is the Code for the Run Report Button:
If Not Request.Cookies("ReportPar ameters") Is Nothing = True Then
Dim sTest As String = Request.Cookies("ReportPar ameters")( "Report_Fi leName")
End If
When I look at my sTest String I get NOTHING???
Why?
Thanks,
Mark
Here is what I'm trying to do...I have a RadioButtonList that displays a list of reports.
These reports all have different types of Paramaters that need to be passed in to the SQL Statement to produce the correct report.
As the user selects a report I want to update the Cookie with ALL the paramater information so that when the click the Run Report Button I can grab those parameters from the cookie and produce the report.
Here is the code for the RadioButtonList:
Dim MyReportDataView As DataView
MyReportDataView = CType(SQL_WebReports.Selec
'Get the Report ID and the Parameters for that Selected Report:
Dim myCookie As HttpCookie = New HttpCookie("ReportParamete
For Each MyRow As DataRowView In MyReportDataView
myCookie.Values("Report_St
myCookie.Values("Report_Fi
myCookie.Values("Report_Pa
myCookie.Values("Report_Lo
myCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(myCoo
Next
Here is the Code for the Run Report Button:
If Not Request.Cookies("ReportPar
Dim sTest As String = Request.Cookies("ReportPar
End If
When I look at my sTest String I get NOTHING???
Why?
Thanks,
Mark
ASKER
Thanks guru_sami!
First I agree with your security risk...but this is my first time experimenting with cookies and so this isn't really going to be deployed I just to a section of a web site I was working on to play around with.
I wanted to show you something I just tested and see the attached PDF screen shot and see if you can find out what is going on because nothing stands out to me!
I added a sTest String variable at the END of my loop to see the cookie right after it has been created and it still shows nothing???
Thanks,
Mark
Cookies.pdf
First I agree with your security risk...but this is my first time experimenting with cookies and so this isn't really going to be deployed I just to a section of a web site I was working on to play around with.
I wanted to show you something I just tested and see the attached PDF screen shot and see if you can find out what is going on because nothing stands out to me!
I added a sTest String variable at the END of my loop to see the cookie right after it has been created and it still shows nothing???
Thanks,
Mark
Cookies.pdf
That myCookie you added in the foreach won't show up until the next request.
So what you are seeing is correct.
So what you are seeing is correct.
ASKER
OK, but isn't the Next Request in my screen shot the sTest Varaible?
Why is it nothing?
Mark
Why is it nothing?
Mark
How about trying it with a simple test and very simple cookie:
Dim testCookie As HttpCookie = New HttpCookie("testcookie","M yvalue")
Response.Cookies.Add(testC ookie)
Then read it in your button click.
Response.Write(Request.Coo kies("test cookie"))
Dim testCookie As HttpCookie = New HttpCookie("testcookie","M
Response.Cookies.Add(testC
Then read it in your button click.
Response.Write(Request.Coo
ASKER
Yes that works fine!
Why won't it work with a Collection of Values?
Thanks,
Mark
Why won't it work with a Collection of Values?
Thanks,
Mark
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
OK, I think I just found my problem!!!!
Some of my Stored Procedures have a ";1" for example Report;1
I think the Semi-Colon is throwing off the Cookie!
Because it seems to work fine when I select the reports without the semi-colon.
Mark
Some of my Stored Procedures have a ";1" for example Report;1
I think the Semi-Colon is throwing off the Cookie!
Because it seems to work fine when I select the reports without the semi-colon.
Mark
ASKER
Thank You for helping me debug my problem!
It also appears that some of my StoredProcedure Names were also too long because once I removed the semi-colons I got everything I was looking for except one report which turned out to be too long because once I shortened the StoreProcedure name it worked.
Thanks again...I had been pulling my hair out for the past two days thinking it had to do with my code when really it had to do with my values.
Mark
It also appears that some of my StoredProcedure Names were also too long because once I removed the semi-colons I got everything I was looking for except one report which turned out to be too long because once I shortened the StoreProcedure name it worked.
Thanks again...I had been pulling my hair out for the past two days thinking it had to do with my code when really it had to do with my values.
Mark
To troubleshoot your cookie issue:
1: Set a break on this line: Response.Cookies.Add(myCoo
2: You can use browser tools like IE's web developer tool to check if the cookie it self is set.
3: Since you are setting cookie in the loop, it could be a problem as you are using the same cookie name over and over. So only the last item in the loop will be saved in the cookie and rest of the others will be lost.