簡體   English   中英

ASP.NET C#-“ RPC服務器不可用”

[英]ASP.NET C# - “The RPC server is unavailable”

這是我在IIS中創建虛擬目錄的代碼:

/// <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; 
} 

該代碼是從其他建議該代碼的用戶那里獲取的,對他和其他用戶來說很好用。

觸發函數時出現的錯誤:

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.

我正在使用Windows Server 2008 R2,

IIS 7.5

ASP.NET 4.0

提前致謝!

您是否檢查過以確保IISAdmin服務正在運行?

嘗試運行:

net start iisadmin

防火牆? 檢查您是否可以從同一服務器訪問應用程序外部以進行確認。

您以什么用戶身份運行此代碼? 您需要具有管理員身份才能寫入配置數據庫,因此,例如,如果您使用匿名用戶在IIS中運行此數據庫,則您將無法寫入配置數據庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM