i trying clear httpcontext.current.session after user logs out of sitefinity page.
i saw in link can check request.url i'm not sure implementation is.
this current attempt:
protected void application_authenticaterequest(object sender, eventargs e) { if (((system.web.httpapplication)(sender)).request.url.tostring() == httpcontext.current.server.mappath("~/sitefinity/login/dologout")) { if (httpcontext.current.session["cart"] != null) httpcontext.current.session.remove("cart"); httpcontext.current.session["cart"] = new list<iquoteresult>(); } } please let me know if have tips or suggestions, or if i'm wrong logic.
thanks in advance.
update:
protected void application_postacquirerequeststate(object sender, eventargs e) { if (((httpapplication)(sender)).request.url.tostring().contains("sign_out=true")) { if (httpcontext.current.session["cart"] != null) { httpcontext.current.session.remove("cart"); httpcontext.current.session["cart"] = new list<iquoteresult>(); } } } this next attempt @ completing same task keep receiving nullreferenceexception...
note: i've tried method in application_acquirerequeststate method.
here stack:
[nullreferenceexception: object reference not set instance of object.] sitefinitywebapp.global1.application_postacquirerequeststate(object sender, eventargs e) +137 system.web.synceventexecutionstep.system.web.httpapplication.iexecutionstep.execute() +91 system.web.httpapplication.executestep(iexecutionstep step, boolean& completedsynchronously) +164
that's pretty close how it. change make change url comparison logic like:
if (((system.web.httpapplication)(sender)).request.url.tostring().endswith("/sitefinity/login/dologout")) or potentially use .contains() instead of endswith() -- not sure if there query-string parameters or trailing slashes added on dologout action.
this because request.url returns url (ex. https://stackoverflow.com/whatever) whereas server.mappath() returns local path (ex. c:\inetpub\wwwroot\whatever), wouldn't comparing apples apples if you're comparing two.
edit: should work, adding check see if session null
protected void application_postacquirerequeststate(object sender, eventargs e) { if (((httpapplication)(sender)).request.url.tostring().contains("sign_out=true")) { if (httpcontext.current.session != null && httpcontext.current.session["cart"] != null) { httpcontext.current.session.remove("cart"); httpcontext.current.session["cart"] = new list<iquoteresult>(); } } }
Comments
Post a Comment