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上運行,並在網絡服務下運行。RoleEnvironment.IsAvailable在應用程序啓動時設置爲false
任何想法我在這裏做錯了什麼。另外,當我遠程登錄並通過添加空間更改web.config位時,IIS RoleEnvironment.IsAvailable的計算結果爲true。
而且我使用Azure的2.5版
小編輯:RoleEnvironment.IsEmulated。將嘗試您提到的解決方案並更新線程 – StackOverflowVeryHelpful
獲取此錯誤: [InvalidOperationException:角色環境尚未初始化] Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsEmulated()+150 – StackOverflowVeryHelpful
此外,webrole已在運行Azure,不在我的本地機器上。我做的步驟是使用manage.windowsazure.com部署我的cspkg和csfg。我從瀏覽器調用網址。遠程登錄到機器並檢查跟蹤日誌並查看RoleEnvironment爲false。編輯Web.config一點,以確保再次調用Application_Start,然後將RoleEnvironment設置爲true。 – StackOverflowVeryHelpful