我正在尝试打电话RoleEnvironment.GetConfigurationSetting("SOMEKEY")
像这样:
public partial class AzureBasePage : System.Web.UI.Page
{
protected ChargifyConnect Chargify
{
get {
if (this._chargify == null) {
this._chargify = new ChargifyConnect();
this._chargify.apiKey = RoleEnvironment.GetConfigurationSettingValue("CHARGIFY_API_KEY");
}
return this._chargify;
}
}
private ChargifyConnect _chargify = null;
}
我的 ServiceConfiguration.cscfg 密钥如下所示:
<Setting name="CHARGIFY_API_KEY" value="AbCdEfGhIjKlMnOp" />
我收到此错误:
异常详细信息:System.Runtime.InteropServices.SEHException:外部组件引发了异常。
[SEHException (0x80004005):外部组件引发异常。]
RoleEnvironmentGetConfigurationSettingValueW(UInt16* , UInt16* , UInt32 , UInt32* ) +0
Microsoft.WindowsAzure.ServiceRuntime.Internal.InteropRoleManager.GetConfigurationSetting(字符串名称,字符串& ret)+92
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(字符串配置设置名称)+67
C:\NetProjects\ChargifyDotNET\Source\Chargify.NET\ChargifyAzurePage.cs 中的 ChargifyNET.ChargifyAzurePage.get_Chargify():26
C:\NetProjects\ChargifyDotNET\Source\Chargify.Azure\Default.aspx.vb:8 中的 Chargify.Azure._Default.Page_Load(对象发送者,EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint)+627
如果您未在开发结构或 Azure 结构中运行,则尝试访问 RoleEnvironment 时,您将收到 SEHException。我相信您无意中在 asp.net 开发服务器下运行您的网站,这意味着您不在开发结构中(我已经确认这会抛出 SEHException)。换句话说,您要么将网站项目设置为启动项目,要么右键单击它并让它运行。
您必须将云项目本身设置为启动项目,然后该项目将默认显示您的网站在端口 81 上运行。云项目是拥有您的所有角色定义作为其成员的项目。您可以查看浏览器的 URL 栏,轻松判断您是否在 asp.net 开发服务器中运行,因为您将使用某个随机端口号而不是端口 81。
您应该通过检查来确保您正在开发结构或Azure结构中运行RoleEnvironment.IsAvailable
。如果这是真的,您就可以安全地调用 RoleEnvironment 中的任何内容。如果它是假的,那么你就没有在结构中运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)