【问题标题】:ASP.NET C# - "The RPC server is unavailable"ASP.NET C# - “RPC 服务器不可用”
【发布时间】:2011-03-20 16:45:39
【问题描述】:

这是我在 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

提前致谢!

【问题讨论】:

    标签: c# asp.net virtual-directory iis-7.5


    【解决方案1】:

    您以什么用户身份运行此代码?您需要成为管理员才能写入元数据库,例如,如果您在 IIS 中使用匿名用户运行它,您将无法写入元数据库。

    【讨论】:

      【解决方案2】:

      防火墙?检查您是否可以从应用程序外部的同一服务器访问以进行确认。

      【讨论】:

        【解决方案3】:

        您是否检查以确保 IISAdmin 服务正在运行?

        尝试运行:

        net start iisadmin
        

        【讨论】:

        • 您好,马修,感谢您的回复。该服务已在运行。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-07
        • 1970-01-01
        相关资源
        最近更新 更多