如何在global.asax中获取Curring运行URL路径 [英] How to get the Curring Running URL path in global.asax

查看:100
本文介绍了如何在global.asax中获取Curring运行URL路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试在grobal.asax文件的application_start中获取IIS主机路径/ Localhost路径但是它的抛出错误。

这里是我写的代码来获取这个。

Hi i am trying to get IIS hosting path/Localhost path in application_start of grobal.asax file but its throwing error.
here is my code i have written to get this.

protected void Application_Start() 
{ 
URL = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority).ToString(); 
} 





错误:请求在Application_Start中的此上下文异常中不可用



谢谢

Santosh



Error : Request is not available in this context exception in Application_Start

Thanks
Santosh

推荐答案

application_start事件触发器由于服务启动和应用程序加载到内存中,它不会因浏览器请求而触发,因此没有正在运行的URL。要访问请求(即URL),您需要使用通过页面请求触发的事件,例如Session_Start,各种页面请求事件等。
The application_start event triggers due to the service starting and the app loading into memory, it isn't fired as the result of a browser request, so there is no "running url". To get access to the "Request" (ie the url) you need to use an event that is triggered via a page request such as Session_Start, the various page request events etc.


但是我需要它在应用程序启动因为我正在运行一个应该运行的电子邮件功能always.if我添加其他功能,如Session_Start然后一旦会话清除然后将无法工作。如果你有任何其他方式将帮助我知道如何帮助我我即使申请关闭也要运行我的电子邮件功能。



谢谢

Santosh
but i need it in application start becaz i am running a email function which should be running always.if i am adding in other function such as Session_Start then once session cleared then will not work.so let me know if you have any other ways which will help me to run my email function even if application close.

Thanks
Santosh


这篇关于如何在global.asax中获取Curring运行URL路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆