RoleEnvironment.IsAvailable在应用程序启动时设置为false

本文关键字:设置 false 启动 IsAvailable 应用程序 RoleEnvironment | 更新日期: 2023-09-27 18:12:26

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为false。我的服务在IIS 8.5上运行,它在网络服务下运行。

知道我在这里做错了什么吗?当我远程进入并改变网络时也是如此。通过在IIS RoleEnvironment中添加空间来配置一点。IsAvailable被求值为true。

我也使用Azure 2.5版本

RoleEnvironment.IsAvailable在应用程序启动时设置为false

这是一个已知的错误,导致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
}

应该是

if ( RoleEnvironment.IsAvailable && RoleEnvironment.IsEmulated)
{
     // we are running the workerrole locally in debug 
}
相关文章: