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

时间:2015-09-13 04:23:06

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

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上运行,它在网络服务下运行。

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

我也在使用Azure 2.5版

2 个答案:

答案 0 :(得分:0)

这是一个已知的错误导致function summation() { var arr = [], sum = 0, v; while (true) { v = prompt("Number Only (Press [Cancel] for end input)", ""); if (!v) { break; } v = parseInt(v, 10); if (isFinite(v)) { arr.push(v); sum += v; } } document.write('Array: ' + arr + '<br>'); document.write('Sum: ' + sum + '<br>'); } summation();始终在模拟器上返回RoleEnvironment.IsAvailable,有关详细信息,请参阅https://connect.microsoft.com/VisualStudio/feedback/details/695609/roleenvironment-isavailable-is-useless-returns-true-when-invoked-by-code-not-hosted-in-azure-emulator

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

false

答案 1 :(得分:0)

不应该是

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