azure - How can I get the WebRole site root path from RoleEntryPoint.OnStart()? -


as part of starting webrole on windows azure access files on website being started , in roleentrypoint.onstart(). instance enable me influence asp.net config before asp.net appdomain loaded.

when running locally azure sdk 1.3 , vs2010 sample code below trick, code has stench of hack around , not trick when deploying 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; 

how can webrole site root path roleentrypoint.onstart() in way work in both dev , on azure?

this seem work in both dev , on windows azure:

private ienumerable<string> websitedirectories {         {         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             siteelement in siteelements             siteelement.attribute("name") != null                     && siteelement.attribute("name").value == "web"                     && siteelement.attribute("physicaldirectory") != null             select path.combine(approotdir, siteelement.attribute("physicaldirectory").value);     } } 

if use manipulate files in asp.net app, should know files written roleentrypoint.onstart() have acl settings prevent asp.net application updating them.

if need write such files asp.net code show how can change file permissions possible:

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); 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -