Windows Azure中创建虚拟目录到本地存储 [英] Windows Azure creating virtual directory to local storage

查看:167
本文介绍了Windows Azure中创建虚拟目录到本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Windows Azure中(生产环境)创建虚拟目录指向本地存储的帮助。我可以手动设置虚拟目录,但它正在被删除的Azure每次重新启动时。线索是,当我上传一个包我对Azure项目的创建通过配置文件中的虚拟目录。现在的问题是如何创建这样的目录,以便它指向本地存储。

I need a help with creating virtual directory pointing to local storage in Windows Azure (production environment). I can set up a virtual directory manually but it is being erased every time Azure is restarted. The clue is to create the virtual directory via config file when I upload a package of my project on Azure. The question is how to create such directory so that it is pointing to local storage.

THX事先的任何建议。

Thx in advance for any suggestions.

最好的问候,

Darek

推荐答案

我建议你通过在WebRole的OnStart方法与IIS交互创建虚拟目录:

I suggest you create the virtual directory by interacting with IIS in the WebRole's OnStart method:

public class WebRole : RoleEntryPoint
{
    public override bool OnStart()
    {
        // Connect to the IIS site.
        using (var manager = new Microsoft.Web.Administration.ServerManager())
        { 
                var localResourcePath = RoleEnvironment.GetLocalResource("MyResource").RootPath;

            // Add to the root application.
            var rootSite = manager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"];
            var rootApplication = rootSite.Applications["/"];
                rootApplication.VirtualDirectories.Add("/myVdir", localResourcePath);

                // Save
            manager.CommitChanges();
        }

        ...
    }
}

如果我是正确的,你需要将执行上下文设置为升高这个工作。您可以在ServiceDefintion.csdef做到这一点:

If I'm right you'll need to set the execution context to elevated for this to work. You can do this in the ServiceDefintion.csdef:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="MyProject" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2012-05.1.7">
  <WebRole name="MyRole" vmsize="Small" enableNativeCodeExecution="true">
    <Runtime executionContext="elevated" />
    ...
  </WebRole>
</ServiceDefinition>

注意:您将需要引用 Microsoft.Web.Administration.dll (C:\\ WINDOWS \\ SYSTEM32 \\ INETSRV)

Note: You'll need to reference Microsoft.Web.Administration.dll (C:\Windows\System32\inetsrv)

这篇关于Windows Azure中创建虚拟目录到本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆