获取网站的URL,而不HttpContext.Current(在后台线程中运行)

电脑杂谈  发布时间:2019-12-27 12:01:03  来源:网络整理

.net后台访问 url 获取数据_ajax 获取后台数据_.net后台访问 url 获取数据

百度翻译此文有道翻译此文

问 题

Bit of a long shot, but is there a way in ASP.NET to dynamically get the website's URL () when there is no HttpContext.Current available.

There is no HttpContext because the code is running in a background thread* (but under the ASP.NET AppDomain). I have a background process that sends emails out every evening, and needs to include the Web address, but I don't want to hard code it because of deployments and testing (it changes from :12345 to and then to for the live site).

*Please don't advise a Windows Service, I'm aware of these but hosting restrictions prevent me from doing this.

解决方案

Your app must construct and start the thread. At the point the thread is created, the HttpContext.Current should be available, store the relevant part of the web address that is important and either pass to the constructor of your object that wraps the threading functionality, or if you dont have a custom object, store it in a location where the thread can access it. You will need to enter a critcial section with lock() {} if you use the latter approach.

.net后台访问 url 获取数据_ajax 获取后台数据_.net后台访问 url 获取数据

本文地址:IT屋 ASP.NET - Get website's URL without HttpContext.Current (running in background thread)

问 题

一个长镜头位,但有在ASP.NET的方法来动态获得网页的网址()时,有没有HttpContext.Current可用。

有没有HttpContext的.net后台访问 url 获取数据,因为code在后台线程运行*(但按照ASP.NET应用程序域)。我有一个后台进程将每日早上邮件出去,需要包括网络地址,但我不想硬code,因为部署和测试(它的 HTTP://本地主机:12345 以的http://测试。 example.com 然后 ,在活动站点)。

*请不要劝Windows服务,我知道这些,但是从这种的托管限制prevent我。

解决方案

您的应用程序必须制定并开展线程。在建立线程来看,HttpContext.Current应该只用,存储是相当重要的,要么传递给你的对象封装了泛型功能,或者即使你没有一个自定义对象的构造Web地址的相关个别,将其储存程可以访问它的位置。您将必须输入critcial部分以锁(){}如果使用后一种方法。

.net后台访问 url 获取数据_.net后台访问 url 获取数据_ajax 获取后台数据

本文地址:IT屋 ASP.NET - 获取网站的URL,而不HttpContext.Current(在后台线程中运行)

官方微信

扫一扫关注IT屋

微信公众号搜索 “ IT屋 ” ,选择关注

与百万开发者在一起

官方交流群:IT屋-技术交流群③

Google Facebook Youtube 科学上网》戳这里《

.net后台访问 url 获取数据_ajax 获取后台数据_.net后台访问 url 获取数据

百度翻译此文有道翻译此文

问 题

一个长镜头位,但有在ASP.NET的方法来动态获得网页的网址()时,有没有HttpContext.Current可用。

有没有HttpContext的,因为code在后台线程运行*(但按照ASP.NET应用程序域)。我有一个后台进程将每日早上邮件出去,需要包括网络地址.net后台访问 url 获取数据,但我不想硬code,因为部署和测试(它的 HTTP://本地主机:12345 以的http://测试。 example.com 然后 ,在活动站点)。

*请不要劝Windows服务,我知道这些,但是从这种的托管限制prevent我。

解决方案

您的应用程序必须制定并开展线程。在建立线程来看,HttpContext.Current应该只用,存储是相当重要的,要么传递给你的对象封装了泛型功能,或者即使你没有一个自定义对象的构造Web地址的相关个别,将其储存程可以访问它的位置。您将必须输入critcial部分以锁(){}如果使用后一种方法。

.net后台访问 url 获取数据_ajax 获取后台数据_.net后台访问 url 获取数据

本文地址:IT屋 ASP.NET - 获取网站的URL,而不HttpContext.Current(在后台线程中运行)

问 题

Bit of a long shot, but is there a way in ASP.NET to dynamically get the website's URL () when there is no HttpContext.Current available.

There is no HttpContext because the code is running in a background thread* (but under the ASP.NET AppDomain). I have a background process that sends emails out every evening, and needs to include the Web address, but I don't want to hard code it because of deployments and testing (it changes from :12345 to and then to for the live site).

*Please don't advise a Windows Service, I'm aware of these but hosting restrictions prevent me from doing this.

解决方案

Your app must construct and start the thread. At the point the thread is created, the HttpContext.Current should be available, store the relevant part of the web address that is important and either pass to the constructor of your object that wraps the threading functionality, or if you dont have a custom object, store it in a location where the thread can access it. You will need to enter a critcial section with lock() {} if you use the latter approach.

本文地址:IT屋 ASP.NET - Get website's URL without HttpContext.Current (running in background thread)

官方微信

扫一扫关注IT屋

微信公众号搜索 “ IT屋 ” ,选择关注与百万开发者在一起


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-134840-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 谷云凤
        谷云凤

        具本人了解到国内大豆榨油

      • 黄九明
        黄九明

        你们都是中国人

      热点图片
      拼命载入中...