Currently i want my log files to be dropped in particular location. Is there a way that i can get the Environment variable for my IIS application in Global.asax.cs
private string GetLoggingPath()
{
string rootFolder = string.Empty;
var directoryInfo = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/")).Parent;
if (directoryInfo != null)
{
if (directoryInfo.Parent != null)
{
rootFolder = directoryInfo.Parent.FullName;
}
}
if (string.IsNullOrWhiteSpace(rootFolder))
{
return Path.GetTempPath();
}
return Path.Combine(rootFolder, @"approot\bin\Data");
}
I was looking into RoleRoot Environment variable but it is not available to me even when the application is running on Azure.
How can i set environment variables in azure so that i can use in my IIS application? What is the best way for me to get to the folder E:\\approot\\bin\\data
without hardcoding where E:\\
is the roleroot folder
Don't have a great way, it seems that environment variable is not set in the w3wp.exe process, but how about just using the following:
System.IO.Path.Combine(
System.IO.Path.GetPathRoot(
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath
),
@"approot\bin\Data"
);
(pretty much the same as you, but without creating an DirectoryInfo).
Looking at the processes using Process Explorer I can see that only IISConfigurator.exe has the RoleRoot environment variable, so one option is you could use AppCmd.exe to set it in some configuration file during a startup task into a web.config or applicationHost.config and then read it from there.
But honestly I would just use the code above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.