-->

确定是否ASP.Net正确注册(Determining if ASP.Net is properly

2019-06-24 21:03发布

有没有人有一个防弹的方法(在C#中最好!)确定ASP.Net正确您的计算机上注册的?

我写的ASP.Net应用程序的安装程序,我需要知道我是否应该运行aspnet_regiis

目前,我们始终运行aspnet_regiis -我保证ASP.Net正确注册,但这种不可取的,因为它会提示所有的应用程序池重新启动。

有在网络上(例如,几个有用的网页http://www.codeproject.com/KB/cs/iisdetection.aspx ),但在展后的意见,这是很经常的注册报告,ASP的情况。网已注册但aspnet_regiis仍需要运行配置IIS。 用户“JonB”贴东西,看起来像它应该工作IIS6(和IIS7与IIS6兼容性能),但我仍然需要编写单独的检测码IIS 7禁用IIS6兼容性模式。

因此,有没有人破解这个螺母了吗? 如果是的话,请让我们知道,这将是一个节省时间。 否则,我会尝试和端口C ++解决方案到C#的IIS6和IIS7我会看检查<isapiCgiRestriction>部分applicationHosts.config

<add path="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" allowed="true" groupId="ASP.NET v2.0.50727" description="ASP.NET v2.0.50727" />

最后一个问题...

有谁知道,如果事情是在Windows 7中相同/不同?

Answer 1:

首先,我会尝试运行aspnet_regiis -lv 。 这应该给你喜欢的输出:

1.1.4322.0      Valid           C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll
2.0.50727.0     Valid           c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll

您可以轻松地分析,以验证您的目标版本已安装并有效。 如果不是,你就必须去aspnet_regiis -i路线。

此外,考虑到你能够做这种检查在C#中,你可以测试页添加到您的ASP.NET应用程序。 你通常会考虑安装成功后,做了HttpWebRequest是测试页上。 该页面本身可以作为一个空白页面的简单和复杂,因为在运行安装(文件/文件夹的权限,数据库配置等)的自我检查,如果一切正常,只会返回一个HTTP 200。 任何超时或错误表示不好安装。 然后,可选,删除测试页。



Answer 2:

这段代码适用于IIS7 +

using Microsoft.Web.Administration;   

private static string[] ARR_STR_SUPPORTED_APP_POOLS = 
                         { "ASP.NET v4.0", "ASP.NET v4.5", ".NET v4.5", ".NET v4.0" };

public static ApplicationPool GetFirstSupportedAppPoolInstalled(this ServerManager mgr, IEnumerable<string> supportedAppPools)
{
    ApplicationPool result = null;
    foreach (string appPoolName in supportedAppPools)
    {
        result = mgr.ApplicationPools[appPoolName];
        if (result != null)
            break;
    }
    return result;
}

...
using (var mgr = new ServerManager())
{
   if (!mgr.IISAccessCheck())
      throw new ApplicationException("Error trying to access IIS 7!");

   ApplicationPool appPool = mgr.GetFirstSupportedAppPoolInstalled(ARR_STR_SUPPORTED_APP_POOLS);
   if (appPool == null)
       throw new ApplicationException("No appropriate .NET application pool found!");

   // you can do something with the app pool, if needed
}
...

只要你想,你可以调整它。



文章来源: Determining if ASP.Net is properly registered