在 WebRole 中调用时,Environment.GetEnvironmentVariable(“RoleRoot”) 返回 null
我有一个方法(在单独的类库中),由 WebRole 和 WorkerRole 调用。此方法包含文件的路径,使用 Environment.GetEnvironmentVariable("RoleRoot")
返回该路径,如下所示:
private string FooPath()
{
string appRoot = Environment.GetEnvironmentVariable("RoleRoot");
return Path.Combine(appRoot + @"\", @"approot\file.foo");
}
当我从 WorkerRole 调用此方法时,路径会正常返回。但是当我从 WebRole 调用它时,我得到 null
。
有什么想法吗?
编辑:我正在使用 APNS-Sharp 向 iOS 发送推送消息,它需要 .p12 证书才能工作。目前,我的类库的根目录中有 .p12(由 WebRole 和 WorkerRole 调用)。但重点是:为什么当我从 WebRole 调用时 RoleRoot
返回 null,而当我从 WorkerRole 调用时返回路径?
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");
}
When I call this method from a WorkerRole the path is returned normally. But when I call it from a WebRole I get null
.
Any ideas?
EDIT: 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
RoleRoot
对于 WebRole 返回 false,因为 WebRole 使用 IIS,就像普通网站一样。这就是为什么很难从 WebRole 获取环境变量。为了正确获取路径,我必须使用经典的 Server.MapPath 并引用
bin
文件夹,而不是approot
:对于 WorkerRole 没有任何更改:
此外,我发现Azure不导入p12证书。我必须将其转换为另一种格式,我认为这对我不起作用。因此,最好的选择是将它们放在应用程序的根目录中,并将其构建操作标记为内容。
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 ofapproot
:For the WorkerRole nothing has changed:
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.
我从 webrole 尝试过,它对我有用。我将其放置在 Web 角色的 OnStart() 代码中,该代码由 WaIISHost 调用
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
如果您想加载证书,您可以尝试 http://blogs.msdn.com/b/jnak/archive/2010/01/29/installing-certificates-in-windows-azure-vms.aspx
链接自 如何将公共证书导入到Windows Azure?
If you want to load a certificate, you could try the advice in http://blogs.msdn.com/b/jnak/archive/2010/01/29/installing-certificates-in-windows-azure-vms.aspx
Linked from How do I import a public certificate to Windows Azure?