2010-07-25 2 views
1

이것은 IIS에서 가상 디렉터리를 만드는 내 코드 :이 코드는 그것을 제안 다른 사용자로부터 찍은ASP.NET C 번호는 "RPC 서버를 사용할 수 없습니다"

/// <summary> 
/// Creates the virtual directory. 
/// </summary> 
/// <param name="webSite">The web site.</param> 
/// <param name="appName">Name of the app.</param> 
/// <param name="path">The path.</param> 
/// <returns></returns> 
/// <exception cref="Exception"><c>Exception</c>.</exception> 
public static bool CreateVirtualDirectory(string webSite, string appName, string path) 
{ 
    var schema = new DirectoryEntry("IIS://" + webSite + "/Schema/AppIsolated"); 
    bool canCreate = !(schema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN"); 
    schema.Dispose(); 

    if (canCreate) 
    { 
     bool pathCreated = false; 
     try 
     { 
      var admin = new DirectoryEntry("IIS://" + webSite + "/W3SVC/1/Root"); 

      //make sure folder exists 
      if (!Directory.Exists(path)) 
      { 
       Directory.CreateDirectory(path); 
       pathCreated = true; 
      } 

      //If the virtual directory already exists then delete it 
      IEnumerable<DirectoryEntry> matchingEntries = admin.Children.Cast<DirectoryEntry>().Where(v => v.Name == appName); 
      foreach (DirectoryEntry vd in matchingEntries) 
      { 
       admin.Invoke("Delete", new[] { vd.SchemaClassName, appName }); 
       admin.CommitChanges(); 
       break; 
      } 

      //Create and setup new virtual directory 
      DirectoryEntry vdir = admin.Children.Add(appName, "IIsWebVirtualDir"); 

      vdir.Properties["Path"][0] = path; 
      vdir.Properties["AppFriendlyName"][0] = appName; 
      vdir.Properties["EnableDirBrowsing"][0] = false; 
      vdir.Properties["AccessRead"][0] = true; 
      vdir.Properties["AccessExecute"][0] = true; 
      vdir.Properties["AccessWrite"][0] = false; 
      vdir.Properties["AccessScript"][0] = true; 
      vdir.Properties["AuthNTLM"][0] = true; 
      vdir.Properties["EnableDefaultDoc"][0] = true; 
      vdir.Properties["DefaultDoc"][0] = 
       "default.aspx,default.asp,default.htm"; 
      vdir.Properties["AspEnableParentPaths"][0] = true; 
      vdir.CommitChanges(); 

      //the following are acceptable params 
      //INPROC = 0, OUTPROC = 1, POOLED = 2 
      vdir.Invoke("AppCreate", 1); 

      return true; 
     } 
     catch (Exception) 
     { 
      if (pathCreated) 
       Directory.Delete(path); 
      throw; 
     } 
    } 
    return false; 
} 

, 그리고 그것을 위해 잘 작동 그와 다른 사용자.

나는 기능을 실행할 때 내가 오류 : 나는 Windows Server 2008 R2를 사용하고

The RPC server is unavailable.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The RPC server is unavailable.

7.5

를 IIS

ASP.NET 4.0

미리 감사드립니다!

답변

0

이 코드를 어떤 사용자로 실행하고 있습니까? 메타베이스에 쓸 수있게하려면 관리자 여야합니다. 예를 들어 익명 사용자를 사용하여 IIS 내에서 실행하면 메타베이스에 쓸 수 없습니다.

0

IISAdmin 서비스가 실행 중인지 확인 했습니까?

시도 실행 :

net start iisadmin 
+0

안녕하세요 매튜와 답장을 보내 주셔서 감사합니다. 서비스가 이미 실행 중입니다. –

0

방화벽? 동일한 서버에서 응용 프로그램 외부로 액세스하여 확인할 수 있는지 확인하십시오.

관련 문제