Environment.GetEnvironmentVariable(QUOT; RoleRoot")在WebRole调用时返回null [英] Environment.GetEnvironmentVariable("RoleRoot") returning null when called in a WebRole

查看:217
本文介绍了Environment.GetEnvironmentVariable(QUOT; RoleRoot")在WebRole调用时返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是由一WebRole和WorkerRole称为方法(在分离的类库)。此方法包含一个文件,该文件是使用返回 Environment.GetEnvironmentVariable(RoleRoot)的路径,如下所示:

I have a method (in a separated class library) which is called by a WebRole and a WorkerRole. This method contains the path of a file, which is returned using Environment.GetEnvironmentVariable("RoleRoot"), as follows:

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

当我把这种方法从WorkerRole路径通常返回。但是,当我把它从WebRole我得到

When I call this method from a WorkerRole the path is returned normally. But when I call it from a WebRole I get null.

任何想法?

编辑:我使用APNS,夏普将消息传递给iOS和它需要的.p12证书才能工作。目前,我有我的类库的根(这是由两个WebRole和WorkerRole称呼)中.P12。但问题是:为什么? RoleRoot 返回null时,我把它从WebRole但返回的路径,当我从一个WorkerRole

I am using APNS-Sharp to send push messages to iOS and it requires a .p12 certificate in order to work. Currently I have the .p12 in the root of my class library (which is called by both WebRole and WorkerRole). But the point is: Why RoleRoot returns null when I call it from a WebRole but returns the path when I call from a WorkerRole?

推荐答案

RoleRoot 因为WebRole使用IIS,就像一个正常的网站返回WebRole假的。这就是为什么它是很难从WebRole获取环境变量。

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.

为了正确地获取路径,我不得不使用经典和使用Server.Mappath引用文件夹,而不是为approot

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

对于WorkerRole一切都没有改变:

For the WorkerRole nothing has changed:

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

另外,我发现Azure不导入P12证书。我将不得不把它改造成另一种格式,我不相信我会的工作。所以,最好的办法是将它们放置在应用程序的根,和纪念的生成操作内容

这篇关于Environment.GetEnvironmentVariable(QUOT; RoleRoot")在WebRole调用时返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆