大佬教程收集整理的这篇文章主要介绍了azure – 如何从RoleEntryPoint.OnStart()获取WebRole站点根路径?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当使用Azure SDK 1.3和VS2010进行本地运行时,下面的示例代码将会成为诀窍,但是代码中存在着恶作剧,并且在部署到Azure时不会做到这一点.
XNamespace srvDefNs = "http://scheR_137_11845@as.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;
如何从一个可以在开发人员和Azure上工作的方式获取来自RoleEntryPoint.onStart()的WebRole站点根路径?
private IEnumerable<String> WebSiteDirectories { get { String roleRootDir = Environment.GetEnvironmentVariable("RdRoleRoot"); String appRootDir = Path.GetDirectoryName(AppDomain.CurrentDomain.baseDirectory); XDocument roleModelDoc = XDocument.Load(Path.Combine(roleRootDir,"RoleModel.xml")); var siteElements = roleModelDoc.Root.Element(_roleModelNs + "Sites").Elements(_roleModelNs + "Site"); return from siteElement in siteElements where siteElement.Attribute("name") != null && siteElement.Attribute("name").Value == "Web" && siteElement.Attribute("physicalDirectory") != null SELEct Path.Combine(appRootDir,siteElement.Attribute("physicalDirectory").value); } }
如果任何人使用它来操纵ASP.NET应用程序中的文件,您应该知道由RoleEntryPoint.onStart()编写的文件将具有阻止ASP.NET应用程序更新的ACL设置.
如果您需要从ASP.NET写入这些文件,这段代码显示如何更改文件权限,这样就可以:
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid,null); IdentityReference act = sid.Translate(typeof(NTAccount)); FileSecurity sec = File.GetAccessControl(testFilePath); sec.AddAccessRule(new FileSystemAccessRule(act,FileSystemRights.FullControl,AccessControlType.Allow)); File.SetAccessControl(testFilePath,sec);
以上是大佬教程为你收集整理的azure – 如何从RoleEntryPoint.OnStart()获取WebRole站点根路径?全部内容,希望文章能够帮你解决azure – 如何从RoleEntryPoint.OnStart()获取WebRole站点根路径?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。