Q:

Base Uri From Background Process

Is it possible to get the base uri of the current web application while running in a thread?
Keep in mind HttpContext.Current will be null so there is no Request object to play with.
Goal: be able to make web requests to different URLs within your web application from the thread to get the rendered output.

A:

There are a few ways of doing this: 

Assuming that you are okay with using localhost for the domain, use 
"http://localhost" + HttpRuntime.AppDomainAppVirtualPath
If you need the exact domain name and also determine if the application is using https and all that fancy stuff, you need access to HttpRequest itself. In that case, create the base url in the method that creates the thread itself and pass it as parameter to the thread. 

    string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority 
                      + Request.ApplicationPath.TrimEnd('/') + "/";
    ParameterizedThreadStart worker= new ParameterizedThreadStart(MyWorkerMethod);
    new Thread(worker).Start(baseUrl);

