{"action":"created","issue":{"url":"https://api.github.com/repos/brockallen/BrockAllen.MembershipReboot/issues/636","repository_url":"https://api.github.com/repos/brockallen/BrockAllen.MembershipReboot","labels_url":"https://api.github.com/repos/brockallen/BrockAllen.MembershipReboot/issues/636/labels{/name}","comments_url":"https://api.github.com/repos/brockallen/BrockAllen.MembershipReboot/issues/636/comments","events_url":"https://api.github.com/repos/brockallen/BrockAllen.MembershipReboot/issues/636/events","html_url":"https://github.com/brockallen/BrockAllen.MembershipReboot/issues/636","id":149672522,"number":636,"title":"How to set values from HttpContext when doing BulkUpload","user":{"login":"parkinsona","id":8508456,"avatar_url":"https://avatars.githubusercontent.com/u/8508456?v=3","gravatar_id":"","url":"https://api.github.com/users/parkinsona","html_url":"https://github.com/parkinsona","followers_url":"https://api.github.com/users/parkinsona/followers","following_url":"https://api.github.com/users/parkinsona/following{/other_user}","gists_url":"https://api.github.com/users/parkinsona/gists{/gist_id}","starred_url":"https://api.github.com/users/parkinsona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parkinsona/subscriptions","organizations_url":"https://api.github.com/users/parkinsona/orgs","repos_url":"https://api.github.com/users/parkinsona/repos","events_url":"https://api.github.com/users/parkinsona/events{/privacy}","received_events_url":"https://api.github.com/users/parkinsona/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-20T06:30:07Z","updated_at":"2016-04-20T22:29:40Z","closed_at":null,"body":"Hi,\r\n\r\nI have implemented some custom EventHandlers that log certain information to the DB using this function:\r\n``` c#\r\n public void AddAuditEntry(UserAccountEvent<CustomUser> evt, string additionalDetail = null)\r\n        {\r\n\r\n            using (var db = new CustomMembershipRebootDatabase())\r\n            {\r\n\r\n                var audit = new AuditTrail\r\n                {\r\n\r\n                    Date = DateTime.UtcNow,\r\n                    Activity = GetTypeNameWithoutGenericArity(evt),\r\n                    Detail = additionalDetail,\r\n                    ClientIP = HttpContext.Current.Request.UserHostAddress,\r\n                    Username = evt.Account.Username,\r\n                    Browser = HttpContext.Current.Request.Browser.Browser,\r\n                    UserAgent = HttpContext.Current.Request.UserAgent,\r\n                    Source = Constants.ApplicationName,                    \r\n                    UpdatedBy = GetUpdatedBy(evt)\r\n                };\r\n                db.Audits.Add(audit);\r\n                db.SaveChanges();\r\n            }\r\n        }\r\n```\r\nThis works great from all my synchronous calls in my site.\r\nHowever, when I introduced this new logging functionality, it breaks my BulkUserUpload. My bulkuser upload loads a file from the html file and processes it in its own Task so that it can return a result to the user right away. It then emails the user upon completion. \r\n\r\n``` c#\r\nTask.Run(() => bulkDS.ParseCSVFile(model.File.FileName, csvStreamReader, client, app, emails,  model.SendWelcomeEmail));\r\n```\r\n\r\nBecause the task runs in its own thread, it doesn't have access to the HttpContext because it is null.\r\nI know I could pass the values of UserHostAddress, Browser, UserAgent etc, through my Task.Run, but I don't know how I could get them to be used by my event handler.\r\n\r\nAll I am wanting to do, is have the user get a response back ASAP after they submit their file to let them know it has been received and is being processed. I don't want them to have to wait until its completed.\r\n\r\nDo you have any suggestions on how I could rework things to allow this to work?\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/brockallen/BrockAllen.MembershipReboot/issues/comments/212638635","html_url":"https://github.com/brockallen/BrockAllen.MembershipReboot/issues/636#issuecomment-212638635","issue_url":"https://api.github.com/repos/brockallen/BrockAllen.MembershipReboot/issues/636","id":212638635,"user":{"login":"parkinsona","id":8508456,"avatar_url":"https://avatars.githubusercontent.com/u/8508456?v=3","gravatar_id":"","url":"https://api.github.com/users/parkinsona","html_url":"https://github.com/parkinsona","followers_url":"https://api.github.com/users/parkinsona/followers","following_url":"https://api.github.com/users/parkinsona/following{/other_user}","gists_url":"https://api.github.com/users/parkinsona/gists{/gist_id}","starred_url":"https://api.github.com/users/parkinsona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parkinsona/subscriptions","organizations_url":"https://api.github.com/users/parkinsona/orgs","repos_url":"https://api.github.com/users/parkinsona/repos","events_url":"https://api.github.com/users/parkinsona/events{/privacy}","received_events_url":"https://api.github.com/users/parkinsona/received_events","type":"User","site_admin":false},"created_at":"2016-04-20T22:29:40Z","updated_at":"2016-04-20T22:29:40Z","body":"So I'm thinking the best way to pass these through would be updating the eventHandler and updating my config like so:\r\n\r\n``` c#\r\n  Config.AddEventHandler(new AuditEventHandler(HttpContext.Current.User as ClaimsPrincipal)); \r\n```\r\n\r\nThis would be ok, but I'm using a static MembershipRebootConfiguration as per the samples in the Customizations Sample. Does the MembershipRebootConfiguration have to be static? Will there be any odd effects if its non-static?\r\n\r\nMy other thought, is that I could remove the Task.Run from my controller action and make the call synchronous. Then in the View, I would call it using Ajax, instead of a full post back. This might give me the desired result. The only concern here, is if the user navigates away from the page, the ajax response won't be received. This is ok from a user perspective because they'll be sent an email on completion of the process."}}