天蓝色阅读安装的VHD

发布于 2024-10-08 22:08:31 字数 1938 浏览 3 评论 0原文

我正在开发“天蓝色网络应用程序”。

我在 WebRole 中创建了drive和drivePath静态成员,如下所示:

public static CloudDrive drive = null;
public static string drivePath = "";

我在WebRole.OnStart中创建了开发存储驱动器,如下所示:

LocalResource azureDriveCache = RoleEnvironment.GetLocalResource("cache");
        CloudDrive.InitializeCache(azureDriveCache.RootPath, azureDriveCache.MaximumSizeInMegabytes);

        CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
        {
            // for a console app, reading from App.config
            //configSetter(ConfigurationManager.AppSettings[configName]);
            // OR, if running in the Windows Azure environment
            configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
        });

CloudStorageAccount account = CloudStorageAccount.DevelopmentStorageAccount;
            CloudBlobClient blobClient = account.CreateCloudBlobClient();
            blobClient.GetContainerReference("drives").CreateIfNotExist();
            drive = account.CreateCloudDrive(
                blobClient
                .GetContainerReference("drives")
                .GetPageBlobReference("mysupercooldrive.vhd")
                .Uri.ToString()
            );
            try
            {
                drive.Create(64);
            }
            catch (CloudDriveException ex)
            {
                // handle exception here
                // exception is also thrown if all is well but the drive already exists
            }

string path = drive.Mount(azureDriveCache.MaximumSizeInMegabytes, DriveMountOptions.None);
            IDictionary<String, Uri> listDrives = Microsoft.WindowsAzure.StorageClient.CloudDrive.GetMountedDrives(); 
            drivePath = path;

驱动器保持可见和可访问,直到执行范围保留在WebRole.OnStart中,一旦执行范围离开WebRole.OnStart ,驱动器从应用程序中变得不可用,并且静态成员被重置(例如drivePath设置为“”)

我是否缺少某些配置或其他错误?

I am developing "azure web application".

I have created drive and drivePath static members in WebRole as follows:

public static CloudDrive drive = null;
public static string drivePath = "";

I have created development storage drive in WebRole.OnStart as follows:

LocalResource azureDriveCache = RoleEnvironment.GetLocalResource("cache");
        CloudDrive.InitializeCache(azureDriveCache.RootPath, azureDriveCache.MaximumSizeInMegabytes);

        CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
        {
            // for a console app, reading from App.config
            //configSetter(ConfigurationManager.AppSettings[configName]);
            // OR, if running in the Windows Azure environment
            configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
        });

CloudStorageAccount account = CloudStorageAccount.DevelopmentStorageAccount;
            CloudBlobClient blobClient = account.CreateCloudBlobClient();
            blobClient.GetContainerReference("drives").CreateIfNotExist();
            drive = account.CreateCloudDrive(
                blobClient
                .GetContainerReference("drives")
                .GetPageBlobReference("mysupercooldrive.vhd")
                .Uri.ToString()
            );
            try
            {
                drive.Create(64);
            }
            catch (CloudDriveException ex)
            {
                // handle exception here
                // exception is also thrown if all is well but the drive already exists
            }

string path = drive.Mount(azureDriveCache.MaximumSizeInMegabytes, DriveMountOptions.None);
            IDictionary<String, Uri> listDrives = Microsoft.WindowsAzure.StorageClient.CloudDrive.GetMountedDrives(); 
            drivePath = path;

The drive keeps visible and accessible till execution scope remain in WebRole.OnStart, as soon as execution scope leave WebRole.OnStart, drive become unavailable from application and static members get reset (such as drivePath get set to "")

Am I missing some configuration or some other error ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

装迷糊 2024-10-15 22:08:31

您希望使用drivePath 的其他代码在哪里?是在网络应用程序中吗?

如果是的话,您使用的是 SDK 1.3 吗?在 SDK 1.3 中,Web 应用程序的默认模式是在完整的 IIS 下运行,这意味着在与 RoleEntryPoint 代码(如 OnStart)不同的应用程序域中运行,因此您无法在两者之间共享静态变量。如果这是问题所在,您可以考虑将此初始化代码移至 Global.asax.cs 中的 Application_Begin(位于 Web 应用程序的应用程序域中)。

Where's the other code where you're expecting to use drivePath? Is it in a web application?

If so, are you using SDK 1.3? In SDK 1.3, the default mode for a web application is to run under full IIS, which means running in a separate app domain from your RoleEntryPoint code (like OnStart), so you can't share static variables across the two. If this is the problem, you might consider moving this initialization code to Application_Begin in Global.asax.cs instead (which is in the web application's app domain).

软糯酥胸 2024-10-15 22:08:31

我找到了解决方案:

在开发机器中,请求源自本地主机,这导致系统崩溃。
在 ServiceDefinition.csdef 中注释“Sites”标记可以解决该问题。

I found the solution:

In development machine, request originate for localhost, which was making the system to crash.
Commenting "Sites" tag in ServiceDefinition.csdef, resolves the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文