Cookie munging problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm trying to use the cookie munging session handling behaviour of asp.net
instead of cookies themselves as I'm finding quite a few people are barring
cookies (especially AOL users). If I change the setting in web.config
everything seems to work fine as long as I'm using relative paths. The
problem is I've got a menuing system that's generated from a site-wide
template - so I use a fixed path from the application root - (ie:
/application/sub-dir/page.aspx) because I don't actually know where the
user is at any given moment because it's a site-wide menu.

Whenever someone clicks on one of them, the Session ID gets wiped from the
URL and the user gets logged out. Am I missing something really stupid
here? How can I persist the SessionID in these URLs?

Cheers

Chris
 
I had the same problem and wound up changing the menu system so that my
navigation is in 4 different controls vs. one. Each control is located in a
position so that it can use relative paths with respect to the page. Instead
of making a change in one nav control I have to make it in 4 but it is still
worth it in order to use cookie munging. My users refuse to allow cookies.
Hope your post results in a better option , I'd love to get back to using
one nav control vs 4.
 
Well that looks interesting. All of my navigation links are generated using
the asp server side controls. Hadn't thought of using the code behind to set
up the urls though. Can you give me a bit of help in getting started on
this? For example if I have the following:

Root
default.aspx consisting of 1 nav user control nav.ascx

Root/subfolderA
PageA.aspx consisting of 1 nav user control nav.ascx

Root/subfolderA/subfolderB
PageAB.aspx consisting of 1 nav user control nav.ascx


Right now I would have to code each user control seperately based on their
relative position in the web even though each nav.ascx displays all the
files the user needs to get to. (of course the premise is that I wish to
continue to use cookie munging.) This is because each user control is
relative depending on the aspx page that calls it vs where it (the ascx)
actually exists.

If I understand your suggestion correctly you are saying that I could keep
one (my root for example) nav.ascx and use it from any aspx page within the
heirarchy by referencing the session.sessionid in the nav.ascx code behind?I
f that is true it would certainly solve the problem.

Can you give me a simple (I'm not very bright) example of the code for the
code behind and the ascx code for a couple of levels (maybe using the folder
structure I mentioned earlier)? Actually just one would probably do me. For
example how would I reference the session.sessionid in the code behind and
then retrieve that in the asp hyperlink?

Thanks in advance.
 
Sure, it's simple.

Basically, use only one nav.ascx.

When you set up the urls, do so server side using absolute links instead of
relative.

So for example, let's assume your application is called MyApp and it's in a
virtualdirectory called MyApp.

It's root directory looks like:

default.aspx
subfolderA/page1.aspx
subfolderB/page2.aspx

All 3 pages have the same nav.ascx control.

The URLs would have to be generated server side, so you'd have to do
something like (assuming nav.ascx code behind is a class called nav):

nav.HomeURL = "/MyApp/(" + session.sessionID + ")/Default.aspx"
nav.Page1URL = "/MyApp/(" + session.sessionID + ")/subfolderA/page1.aspx"
nav.Page2URL = "/MyApp/(" + session.sessionID + ")/subfolderB/page2.aspx"

This definately does work - as i've got it working on my site. Now the only
problem is if the user leaves the site (like to go to a credit card
processing page hosted elsewhere) and comes back - you need to persist the
sessionID somehow....

Hope that helps

Chris
 
Super! Thanks bunches!


Sure, it's simple.

Basically, use only one nav.ascx.

When you set up the urls, do so server side using absolute links instead of
relative.

So for example, let's assume your application is called MyApp and it's in a
virtualdirectory called MyApp.

It's root directory looks like:

default.aspx
subfolderA/page1.aspx
subfolderB/page2.aspx

All 3 pages have the same nav.ascx control.

The URLs would have to be generated server side, so you'd have to do
something like (assuming nav.ascx code behind is a class called nav):

nav.HomeURL = "/MyApp/(" + session.sessionID + ")/Default.aspx"
nav.Page1URL = "/MyApp/(" + session.sessionID + ")/subfolderA/page1.aspx"
nav.Page2URL = "/MyApp/(" + session.sessionID + ")/subfolderB/page2.aspx"

This definately does work - as i've got it working on my site. Now the only
problem is if the user leaves the site (like to go to a credit card
processing page hosted elsewhere) and comes back - you need to persist the
sessionID somehow....

Hope that helps

Chris
 
Ooops. I seem to be running into a problem. Perhaps I don't fully grasp the
technique although I appreciate the concept.
When you say
When you set up the urls, do so server side using absolute links instead of
relative.

You mean using a <asp:hyperlink runat: = "server"> tag.....correct?

If so then in the NavigateUrl="" attribute of the asp:hyperlink I would
place the variable which was referenced in the code behind for that
particular URL. For example <asp:hyperlink runat: = "server"
navigateurl=nav.HomeUrl >

Is that correct?

If so then I must not be setting the reference correctly in the code behind
of the nav.ascx. Where in the code behind and how are you placing that
reference? I tried dimming a variable as a string inside the code behind
class and then assigning the absolute path as you instructed but I suspect
that I didn't do it correctly because it couldn't find the page. I can't
figure out if I'm not setting the reference correctly or I'm not using the
reference correctly in the <asp:hyperlink> tag.


Thanks again.
 
Back
Top