如何在ASP.NET站点是在本地运行,在蔚蓝的Web角色,或蔚蓝网站检测? [英] How to detect if ASP.NET site is running locally, in azure web role, or azure web site?

查看:106
本文介绍了如何在ASP.NET站点是在本地运行,在蔚蓝的Web角色,或蔚蓝网站检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这是从检测与在Azure角色本地运行的问题,我的理解已经被回答了不同的

我有一个APS.NET MVC应用程序,我部署到Azure上。我运行在Azure工具的V2.5。我想能够检测其中code为在运行下列三种方案:

I've got an APS.NET MVC app which I deploy to Azure. I'm running V2.5 of the Azure tooling. I'd like to be able to detect which of the following three scenarios the code is running in:

本地(IIS上调试),天青网站或Azure的Web角色

我在其他帖子看到使用以下的建议:

I've seen in other posts the suggestion to use the following:

RoleEnvironment.IsAvailable

不过,这似乎是我需要一个不完整的解决方案。看来如果code是在本地或没有问题的Web角色运行检测。然而,它的似乎并没有覆盖检查运行作为一个蓝色的网站的场景。

型System.IO.FileLoadException的第一个机会异常出现在mscorlib.dll

A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll

Additional information: Could not load file or assembly
'Microsoft.WindowsAzure.ServiceRuntime, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

那么,谁能告诉我怎么这三个方案之间检测?

So, can anyone tell me how to detect between these three scenarios?

推荐答案

我遇到来确定,如果你在一个Azure的网站上运行的最好方法是检查环境变量具体的presence天青网站如 WEBSITE_SITE_NAME 。你可以先检查,如果变量不存在,请继续执行 RoleEnvironment.IsAvailable 支票。

The best way I've come across to determine if you're running on an Azure Website is to check for the presence of an environment variable specific to Azure Websites like WEBSITE_SITE_NAME. You could check this first, and if the variable does not exist, proceed with the RoleEnvironment.IsAvailable check.

请参阅这个答案获取更多的细节。

See this answer for more specifics.

这篇关于如何在ASP.NET站点是在本地运行,在蔚蓝的Web角色,或蔚蓝网站检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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