确定 ASP.Net 是否正确注册

发布于 2024-07-26 05:40:09 字数 1010 浏览 2 评论 0原文

有没有人有一种万无一失的方法(最好是 C#!)来确定 ASP.Net 是否在您的计算机上正确注册?

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

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

网络上有几个有用的页面(例如 http://www.codeproject.com/ KB/cs/iisdetection.aspx),但正如该帖子中的评论所示,经常出现这样的情况:注册表报告 ASP.Net 已注册,但 aspnet_regiis 仍需要注册运行以配置 IIS。 用户“JonB”发布的内容看起来应该适用于 IIS6(以及启用了 IIS6 兼容性的 IIS7),但我仍然需要为禁用 IIS6 兼容性模式的 IIS 7 编写单独的检测代码。

那么有人已经破解了这个坚果吗? 如果是这样,请告诉我们,因为这会节省时间。 否则,我将尝试将 C++ 解决方案移植到 IIS6 的 C# 中,而对于 IIS7,我将检查 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 中的情况是否相同/不同?

Does anyone have a bulletproof method (in C# ideally!) of determining if ASP.Net is properly registered on your computer ?

I am writing an installation program for an ASP.Net application and I need to know whether I should run aspnet_regiis.

At the moment we always run aspnet_regiis - I to ensure that ASP.Net is registered properly but this undesirable because it prompts a restart of all the application pools.

There are several useful pages on the web (e.g. http://www.codeproject.com/KB/cs/iisdetection.aspx) but as the comments in that post show, it is quite often the case that the registry reports that ASP.Net is registered but aspnet_regiis still needs to be run to configure IIS. The user 'JonB' posted something that looks like it should work for IIS6 (and IIS7 with IIS6 compatibility enabled) but I would still need to write separate detection code for IIS 7 with IIS6 compatibility mode disabled.

So has anyone cracked this nut already? If so please let us know as it will be a time saver. Otherwise I will try and port the C++ solution into C# for IIS6 and for IIS7 I will look examine the <isapiCgiRestriction> section of applicationHosts.config for

<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" />

Last question...

Does anyone know if things are the same/different in Windows 7?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷迭香的记忆 2024-08-02 05:40:09

首先,我会尝试运行 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。 任何超时或错误都表明安装错误。 然后,可以选择删除测试页。

First I would try running aspnet_regiis -lv. This should give you an output like:

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

that you can easily parse to verify that your target version is installed and valid. If it is not, you'll have to go the aspnet_regiis -i route.

Also, given that you can do this check in C#, you could add a test page to your ASP.NET application. After what you would normally consider a successful installation, do a HttpWebRequest on that test page. The page itself can be as simple as an empty page and as complicated as running a self-check of the installation (file/folder permissions, DB configuration, etc.) and would only return a HTTP 200 if everything is ok. Any timeout or error indicates a bad install. Then,optionally, delete the test page.

寂寞花火° 2024-08-02 05:40:09

此代码片段适用于 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
}
...

您可以根据需要进行调整。

This snippet works for 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
}
...

You can adjust it as you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文