【问题标题】:RoleEnvironment.IsAvailable is set to false on application startRoleEnvironment.IsAvailable 在应用程序启动时设置为 false
【发布时间】:2015-09-13 04:23:05
【问题描述】:
protected void Application_Start()
{
                        AreaRegistration.RegisterAllAreas();
                        GlobalConfiguration.Configure(WebApiConfig.Register);
                        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                        RouteConfig.RegisterRoutes(RouteTable.Routes);
                        BundleConfig.RegisterBundles(BundleTable.Bundles);

                        string logsDir = this.GetLoggingPath();
}

private string GetLoggingPath()
{
                        var agentDataDirPath = Path.GetTempPath();

                        Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Role Environment is available : {0}", RoleEnvironment.IsAvailable));

                        // If running in Azure use default local storage  
                        if (RoleEnvironment.IsAvailable)
                        {
                            try
                            {
                                Trace.WriteLine("Getting the agentDataDir location");
                                agentDataDirPath = RoleEnvironment.GetLocalResource(agentDataDirStorage).RootPath;
                            }
                            catch (RoleEnvironmentException exp)
                            {
                                throw new InvalidOperationException(exp);
                            }
                        }

                        return agentDataDirPath;
}

即使我的云服务在 azure RoleEnvironment.IsAvailable 上运行也是错误的。我的服务在 IIS 8.5 上运行,并且在网络服务下运行。

知道我在这里做错了什么。此外,当我远程访问并通过添加空间稍微更改 web.config 时,IIS RoleEnvironment.IsAvailable 被评估为 true。

我也在使用 Azure 2.5 版

【问题讨论】:

    标签: c# azure azure-web-roles azure-cloud-services


    【解决方案1】:

    这是一个已知错误,导致RoleEnvironment.IsAvailable 在模拟器上总是返回false,有关详细信息,请参阅https://connect.microsoft.com/VisualStudio/feedback/details/695609/roleenvironment-isavailable-is-useless-returns-true-when-invoked-by-code-not-hosted-in-azure-emulator

    在修复错误之前,您可以执行以下操作:

    if ( RoleEnvironment.IsEmulator || RoleEnvironment.IsAvailable)
    {
    // Role is available
    }
    

    【讨论】:

    • 小编辑:RoleEnvironment.IsEmulated。将尝试您提到的解决方案并更新线程
    • 收到此错误:[InvalidOperationException:角色环境尚未初始化] Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsEmulated() +150
    • 另外,webrole 已经在 Azure 上运行,而不是在我的本地计算机上。我所做的步骤是使用 manage.windowsazure.com 部署我的 cspkg 和 csfg。我从浏览器调用 url。远程进入机器并检查跟踪日志并查看 RoleEnvironment 是否为 false。稍微编辑 Web.config 以确保再次调用 Application_Start,然后将 RoleEnvironment 设置为 true。
    • RoleEnvironment 可能在 Application_Start() 中不可用,因为它与 Azure 无关,您能否使用 WebRole.cs Onstart 事件?有关更多信息,请参阅此讨论stackoverflow.com/questions/16680007/…
    【解决方案2】:

    不应该吗

    if ( RoleEnvironment.IsAvailable && RoleEnvironment.IsEmulated)
    {
         // we are running the workerrole locally in debug 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多