相关疑难解决方法(0)

如何从RoleEntryPoint.OnStart()获取WebRole站点根路径?

作为在Windows Azure上启动WebRole的一部分,我想访问正在启动的网站上的文件,我想在RoleEntryPoint.OnStart()中执行此操作.例如,这将使我能够在加载ASP.NET AppDomain之前影响ASP.NET配置.

当使用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;
Run Code Online (Sandbox Code Playgroud)

如何以在开发和Azure上工作的方式从RoleEntryPoint.OnStart()获取WebRole站点根路径?

azure azure-web-roles

9
推荐指数
1
解决办法
5594
查看次数

标签 统计

azure ×1

azure-web-roles ×1