none
System.Web.HttpException: 响应在此上下文中不可用。 RRS feed

  • 问题

  • 我在Global.asax中的Application_Start方法中加入如下:
              void Application_Start(object sender, EventArgs e)
            {
                WebRole1.WebRole wr = new WebRole1.WebRole();
                wr.OnStart();

                CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
                CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container = blobStorage.GetContainerReference("aabb");
                container.CreateIfNotExist();
            }

    当执行到CreateIfNotExist()时,出现“System.Web.HttpException: 响应在此上下文中不可用。”这个异常,如何解决?

    附上WebRole1.WebRole类中的代码:

    namespace WebRole1
    {
        public class WebRole : RoleEntryPoint
        {
            public override bool OnStart()
            {

                // For information on handling configuration changes
                // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
                RoleEnvironment.Changing += RoleEnvironmentChanging;

                Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
                {
                    configSetter(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(configName));
                });
             
                return base.OnStart();
            }

            private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
            {
                // If a configuration setting is changing
                if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
                {
                    // Set e.Cancel to true to restart this role instance
                    e.Cancel = true;
                }
            }
        }
    }

    2011年11月17日 2:13

答案

全部回复