Environment.GetEnvironmentVariable(“RoleRoot”) returning null when called in a WebRole

ⅰ亾dé卋堺 提交于 2019-12-03 14:40:13

RoleRoot returns false for WebRole because the WebRole uses IIS, just like a normal website. That's why it's difficult to get Environment Variables from a WebRole.

In order to get the path properly I had to use the classic Server.MapPath and reference the bin folder, instead of approot:

private string FooPathWebRole()    
{
    string appRoot = HttpContext.Current.Server.MapPath(@"~\");
    return Path.Combine(appRoot + @"\", @"bin\file.foo");
}

For the WorkerRole nothing has changed:

private string FooPathWorkerRole()    
{
    string appRoot = Environment.GetEnvironmentVariable("RoleRoot");
    return Path.Combine(appRoot + @"\", @"approot\file.foo");
}

In addition, I found out that Azure doesn't import p12 certificates. I would have to transform it into another format, which I don't believe would work for me. So, the best option is to place them on the root of the application and mark its Build Action to Content.

I tried from webrole and it works for me. I place it at the OnStart() code of the web role, which is called by WaIISHost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!