我有一个天蓝色的云服务,我正在尝试升级该服务以获得高可用性,并且我已订阅了已在预览门户中启用的Microsoft Azure文件服务预览。我创建了一个新的存储帐户,可以看到该存储帐户现在具有位于以下位置的“文件”端点:
https://<account-name>.file.core.windows.net/
在我的Web角色中,我有以下代码来查看是否创建了名为scorm的共享,如果没有创建,则创建它:
public static void CreateCloudShare()
{
CloudStorageAccount account = CloudStorageAccount.Parse(System.Configuration.ConfigurationManager.AppSettings["SecondaryStorageConnectionString"].ToString());
CloudFileClient client = account.CreateCloudFileClient();
CloudFileShare share = client.GetShareReference("scorm");
share.CreateIfNotExistsAsync().Wait();
}
这没有问题。我的问题是我不确定如何在Cloud Service中映射作为虚拟目录创建的CloudShare。在一个实例上,我能够做到这一点:
public static void CreateVirtualDirectory(string VDirName, string physicalPath)
{
try
{
if (VDirName[0] != '/')
VDirName = "/" + VDirName;
using (var serverManager = new ServerManager())
{
string siteName = RoleEnvironment.CurrentRoleInstance.Id + "_" + "Web";
//Site theSite = serverManager.Sites[siteName];
Site theSite = serverManager.Sites[0];
foreach (var app in theSite.Applications)
{
if (app.Path == VDirName)
{
// already exists
return;
}
}
Microsoft.Web.Administration.VirtualDirectory vDir = theSite.Applications[0].VirtualDirectories.Add(VDirName, physicalPath);
serverManager.CommitChanges();
}
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Application", ex.Message, System.Diagnostics.EventLogEntryType.Error);
//System.Diagnostics.EventLog.WriteEntry("Application", ex.InnerException.Message, System.Diagnostics.EventLogEntryType.Error);
}
}
我已经查看并看到可以通过powershell进行映射,但是我不确定如何在Web角色中调用代码。我添加了以下方法来运行powershell代码:
public static int ExecuteCommand(string exe, string arguments, out string error, int timeout)
{
Process p = new Process();
int exitCode;
p.StartInfo.FileName = exe;
p.StartInfo.Arguments = arguments;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.Start();
error = p.StandardError.ReadToEnd();
p.WaitForExit(timeout);
exitCode = p.ExitCode;
p.Close();
return exitCode;
}
我知道我必须运行的命令是:
net use z: \\<account-name>.file.core.windows.net\scorm /u:<account-name> <account-key>
如何在我的网络角色中使用它?我的网络角色代码如下,但似乎不起作用:
public override bool OnStart()
{
try
{
CreateCloudShare();
ExecuteCommand("net.exe", "user " + userName + " " + password + " /add", out error, 10000);
ExecuteCommand("netsh.exe", "firewall set service type=fileandprint mode=enable scope=all", out error, 10000);
ExecuteCommand("net.exe", " share " + shareName + "=" + path + " /Grant:" + userName + ",full", out error, 10000);
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Application", "CREATE CLOUD SHARE ERROR : " + ex.Message, System.Diagnostics.EventLogEntryType.Error);
}
return base.OnStart();
}
我们的博客文章“持久连接到Microsoft Azure文件”提供了一个示例,该示例从Web和辅助角色中引用Azure Files共享。请参阅“ Windows PaaS角色”部分,并查看“ Web角色和用户上下文”下的注释。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句