Working with Session variables == null and response.redirect
Posted on 2013-01-02
I'm getting an error when trying to add code in my Site.Master page.
Error: The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept cookies.
When I use this code in the actual page (not the Site.Master) I don't get an error and it redirects. When I try to add this to my site.master, I get the above error in Firefox. I thought if I added it to the site master it would always check for the session ID and redirect if it was not found.
Code I am using in
if (Session["ID"] == null)
Response.Redirect("page.aspx"); //this page will have end user set the ID session variable before continuing.
//stay on page
Is there a better way to handle this? I was trying to avoid having to add the above code to every page that checks for a Session["ID"].