Windows Azure에서 WebRole을 시작하는 과정에서 시작되는 웹 사이트의 파일에 액세스하고 싶습니다.이 작업을 RoleEntryPoint.OnStart()에서하고 싶습니다. 이것은 예를 들어 ASP.NET AppDomain이로드되기 전에 ASP.NET 구성에 영향을 줄 수 있습니다.RoleEntryPoint.OnStart()에서 WebRole 사이트 루트 경로를 얻으려면 어떻게해야합니까?
Azure SDK 1.3 및 VS2010을 사용하여 로컬에서 실행하는 경우 아래 샘플 코드는 그 트릭을 수행하지만이 코드는 해킹의 악취를 가지고 있으며 Azure로 배포 할 때 트릭을 수행하지 않습니다.
XNamespace srvDefNs = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition";
DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
string roleRoot = di.Parent.Parent.FullName;
XDocument roleModel = XDocument.Load(Path.Combine(roleRoot, "RoleModel.xml"));
var propertyElements = roleModel.Descendants(srvDefNs + "Property");
XElement sitePhysicalPathPropertyElement = propertyElements.Attributes("name").Where(nameAttr => nameAttr.Value == "SitePhysicalPath").Single().Parent;
string pathToWebsite = sitePhysicalPathPropertyElement.Attribute("value").Value;
어떻게 모두 dev에와 푸른 작업 방식으로 RoleEntryPoint.OnStart()에서 WebRole 사이트 루트 경로를 얻을 수 있나요? 당신이 찾고있는 무엇을 줄
Environment.GetEnvironmentVariable("RoleRoot")
않습니다
권한을 변경하거나 배포 된 파일을 편집하는 것은이 를 ServiceDefinition.csdef의 WebRole에 추가하는 경우에만 가능합니다. –