我建议你通过在WebRole的OnStart方法中与IIS交互来创建虚拟目录:
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();
}
...
}
}
Run Code Online (Sandbox Code Playgroud)
如果我是对的,你需要将执行上下文设置为提升以使其工作.您可以在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>
Run Code Online (Sandbox Code Playgroud)
注意:您需要引用Microsoft.Web.Administration.dll(C:\ Windows\System32\inetsrv)
| 归档时间: |
|
| 查看次数: |
1215 次 |
| 最近记录: |