0

I am using a backhround worker class in my generic handler code.

Here is my handler :

public void ProcessRequest(HttpContext context)
{
    BackgroundWorker.Run(() =>
            {

                // Do work here 
                //If I call the static method I get an excpetion
                var applicationpath =Helper.GetApplicationPath(context)


            });
}

I have this method to get the current domain ?

        public static string GetApplicationPath(HttpContext context)
        {
            var request = context.Request;
            return request.Url.Scheme + System.Uri.SchemeDelimiter + request.Url.Host + (request.Url.IsDefaultPort ? "" : ":" + request.Url.Port) +
                (request.ApplicationPath == "/" ? "" : request.ApplicationPath);
        }

Here is the exception log

   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
   at System.Web.HttpRequest.BuildUrl(Func`1 pathAccessor)
   at System.Web.HttpRequest.get_Url()
   at Helpers.Helper.GetApplicationPath(HttpContext context)

Is the context object lose data in background worker class ?

user123456
  • 2,524
  • 7
  • 30
  • 57
  • can you send individual values to `GetApplicationPath` as params rather than sending whole `HTTPContext.Current` object? That way, it will decouple `GetApplicationPath` from HTTPContext. There seems to be problem with values crossing process boundries from IIS worker thread – rt2800 Mar 29 '16 at 13:22
  • `HttpContext.Current` is always null when running in a background thread. – Lex Li Mar 29 '16 at 14:17

0 Answers0