{"action":"created","issue":{"url":"https://api.github.com/repos/leekelleher/umbraco-mortar/issues/13","labels_url":"https://api.github.com/repos/leekelleher/umbraco-mortar/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/leekelleher/umbraco-mortar/issues/13/comments","events_url":"https://api.github.com/repos/leekelleher/umbraco-mortar/issues/13/events","html_url":"https://github.com/leekelleher/umbraco-mortar/issues/13","id":60597282,"number":13,"title":"Do not set HttpContext.Current!! This can cause so many issues","user":{"login":"Shazwazza","id":1742685,"avatar_url":"https://avatars.githubusercontent.com/u/1742685?v=3","gravatar_id":"","url":"https://api.github.com/users/Shazwazza","html_url":"https://github.com/Shazwazza","followers_url":"https://api.github.com/users/Shazwazza/followers","following_url":"https://api.github.com/users/Shazwazza/following{/other_user}","gists_url":"https://api.github.com/users/Shazwazza/gists{/gist_id}","starred_url":"https://api.github.com/users/Shazwazza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shazwazza/subscriptions","organizations_url":"https://api.github.com/users/Shazwazza/orgs","repos_url":"https://api.github.com/users/Shazwazza/repos","events_url":"https://api.github.com/users/Shazwazza/events{/privacy}","received_events_url":"https://api.github.com/users/Shazwazza/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-11T01:35:48Z","updated_at":"2015-03-11T10:05:08Z","closed_at":null,"body":"Currently you have this:\r\n\r\nhttps://github.com/leekelleher/umbraco-mortar/blob/master/Src/Our.Umbraco.Mortar.Courier/DataResolvers/MortarDataResolver.cs#L42\r\n\r\nWhich is entirely not necessary for ensuring an UmbracoContext. Setting the HttpContext.Current can cause so many issues:\r\n\r\n* You don't know what is relying on HttpContext.Current - if things are running on a background thread and do specific checks for this, behaviors will change\r\n* This is the specific reason for this courier issue: http://issues.umbraco.org/issue/UMB-187 \r\n     * The NH sessions are controlled by whether it's a web request or not, initial extraction runs on a background thread (no web request) but because your data resolver is created, suddenly HttpContext.Current is not null and therefore the NH transaction is no longer valid right in the middle of processing\r\n* Unless you are working between threads/background threads and know specifically that you are transfering an existing HttpContext to another thread (which is still not good practice in general), you should never set HttpContext.Current since there will be repercussions.\r\n* This would also cause issues for whenever there are request based lifetime objects, since they are stored in HttpContext, if suddenly one was available, any request based lifetime objects would check or store items there, even though originally they assumed they were application based (i.e. not possible to run web based).\r\n"},"comment":{"url":"https://api.github.com/repos/leekelleher/umbraco-mortar/issues/comments/78235225","html_url":"https://github.com/leekelleher/umbraco-mortar/issues/13#issuecomment-78235225","issue_url":"https://api.github.com/repos/leekelleher/umbraco-mortar/issues/13","id":78235225,"user":{"login":"Shazwazza","id":1742685,"avatar_url":"https://avatars.githubusercontent.com/u/1742685?v=3","gravatar_id":"","url":"https://api.github.com/users/Shazwazza","html_url":"https://github.com/Shazwazza","followers_url":"https://api.github.com/users/Shazwazza/followers","following_url":"https://api.github.com/users/Shazwazza/following{/other_user}","gists_url":"https://api.github.com/users/Shazwazza/gists{/gist_id}","starred_url":"https://api.github.com/users/Shazwazza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shazwazza/subscriptions","organizations_url":"https://api.github.com/users/Shazwazza/orgs","repos_url":"https://api.github.com/users/Shazwazza/repos","events_url":"https://api.github.com/users/Shazwazza/events{/privacy}","received_events_url":"https://api.github.com/users/Shazwazza/received_events","type":"User","site_admin":false},"created_at":"2015-03-11T10:05:08Z","updated_at":"2015-03-11T10:05:08Z","body":"You just create your own http ctx instance and pass it in, you don't need\nto use the http context Singleton and never set that Singleton :)\n\nSent from my phone\nOn 11/03/2015 9:00 pm, \"Lee Kelleher\" <notifications@github.com> wrote:\n\n> Thanks for raising this @Shazwazza <https://github.com/Shazwazza>!\n>\n> Yeah, I knew setting the HttpContext.Current was a nasty hack - at the\n> time I was stuck on how to deal with needing the UmbracoContext. (I added\n> comments above the code)\n>\n> re: #UMB-187 <http://issues.umbraco.org/issue/UMB-187> - I don't have\n> permission to view the ticket - but doesn't matter - I get the idea about\n> NH threads/context.\n>\n> So the question is... how do we deal with ensuring the UmbracoContext?\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/leekelleher/umbraco-mortar/issues/13#issuecomment-78234582>\n> .\n>\n"}}