ASP.NET - get the URL of a site without HttpContext.Current (works in the background thread)

A bit long shot, but is there a way in ASP.NET to dynamically retrieve a website URL ( http://www.example.com ) when there is no HttpContext.Current available.

There is no HttpContext, because the code runs in the background thread * (but under ASP.NET AppDomain). I have a background process that sends emails every night and should include a web address, but I don’t want to hardcode it due to deployments and testing (it changes from http: // localhost: 12345 to http: // testing. example.com and then http://www.example.com for a live site).

* Please do not advise the Windows service, I know about it, but placement restrictions do not allow me to do this.

+1
source share
2 answers

Your application should create and start a thread. At the time the stream is created, HttpContext.Current should be accessible, save the important part of the important web address and either go to the constructor of your object that wraps the streaming functions, or if you do not have a custom object, save it in a place where the stream can receive access to it. You will need to enter a critical section with a lock () {} if you use the latter approach.

+5
source

(, , ), ASP.NET. URL-, .

+1

All Articles