how to get hosting URL path in global.asax

Posted by Santosh4u under ASP.NET MVC on 5/20/2015 | Points: 10 | Views : 4457 | Status : [Member] | Replies : 2
Hi i am trying to get 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();
}

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

Thanks
Santosh




Responses

Posted by: Nismeh on: 6/4/2015 [Member] Starter | Points: 25

Up
-1
Down
Hi,

May be one of below line may help you.

HttpContext.Current.Request.ApplicationPath;
HttpContext.Current.Request.CurrentExecutionFilePath;
HttpContext.Current.Request.FilePath
HttpContext.Current.Request.Path;
HttpContext.Current.Request.PhysicalApplicationPath;
HttpContext.Current.Request.PhysicalPath;


IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nismeh on: 6/4/2015 [Member] Starter | Points: 25

Up
-1
Down
Global.asax is always on the root directory, therefore Server.MapPath("Global.asax") should always return that path to that file. This can be another way.

IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response