题
我正在开发“ Azure Web应用程序”。
我在Webrole中创建了Drive和Drive Path的静态成员,如下所示:
public static CloudDrive drive = null;
public static string drivePath = "";
我已经在Webrole中创建了开发存储驱动器。一开始如下:
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中。
我是否缺少一些配置或其他错误?
解决方案 2
我找到了解决方案:
在开发机器中,请求起源于Localhost,这使系统崩溃。在ServiceDefinition.csdef中评论“站点”标签,解决了问题。
其他提示
您期望使用DrivePath的其他代码在哪里?是在Web应用程序中吗?
如果是这样,您是否使用SDK 1.3?在SDK 1.3中,Web应用程序的默认模式是在完整的IIS下运行,这意味着从您的roalentrypoint代码(例如ONSTART)中运行在单独的应用程序域中运行,因此您无法在两者中共享静态变量。如果这是问题,您可以考虑将此初始化代码转移到Global.asax.cs中的Application_Begin(在Web应用程序的应用程序域中)。
不隶属于 StackOverflow