I'm quite new to Umbraco so please excuse my ignorance.
I'm trying to hook into the request pipeline at PublishedContentRequest.Prepared so that I can get the content id of the page that the user is requesting, and then store that ID in the user's session so that I can use it later, however the session does not seem to exist at this point.
If I hook into the PreRequestHandlerExecute event I can get the session (and determine whether it is new or not), however this seems to execute after the PublishedContentRequest.Prepared, and also I'm not sure how to get the content id at that point.
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
PublishedContentRequest.Prepared += PublishedContentRequest_Prepared;
}
private void PublishedContentRequest_Prepared(object sender, EventArgs e)
{
PublishedContentRequest request = sender as PublishedContentRequest;
if (request == null || !request.HasPublishedContent) return;
var contentId = request.PublishedContent.Id;
// No session seems to exist at this point?
// request.RoutingContext.UmbracoContext.HttpContext.Session is null
// HttpContext.Current.Session is null
}
Is there a way to use the session from within the PublishedContentRequest.Prepared event, or get the content id from within the PreRequestHandlerExecute event? My end goal is to store the content id of the current requested page in the user's session, if there's another way to go about that please let me know!
No session in PublishedContentRequest.Prepared?
I'm quite new to Umbraco so please excuse my ignorance.
I'm trying to hook into the request pipeline at PublishedContentRequest.Prepared so that I can get the content id of the page that the user is requesting, and then store that ID in the user's session so that I can use it later, however the session does not seem to exist at this point.
If I hook into the PreRequestHandlerExecute event I can get the session (and determine whether it is new or not), however this seems to execute after the PublishedContentRequest.Prepared, and also I'm not sure how to get the content id at that point.
Is there a way to use the session from within the PublishedContentRequest.Prepared event, or get the content id from within the PreRequestHandlerExecute event? My end goal is to store the content id of the current requested page in the user's session, if there's another way to go about that please let me know!
Hi Jason,
try this
Please refer below link:-
https://github.com/leekelleher/umbraco-https-redirect/blob/master/src/Our.Umbraco.HttpsRedirect/Events/ApplicationEventsHandler.cs
hope this help
Regards,
Samira
Thanks Samira, but no, at line 20 when the context is retrieved, the session appears to be null
Hi Jason, Did you find a solution to this? I'm trying to access the session here too. Many thanks, Will
is working on a reply...