【问题标题】:How to print similar information as phpinfo() but for ASP.NET?如何打印与 phpinfo() 类似的信息,但用于 ASP.NET?
【发布时间】:2010-10-07 08:24:34
【问题描述】:

我在 ASP.NET 中遍历了 Request.ServerVariables 集合,但它不如 phpinfo() 全面。

如何为 ASP.NET 打印所有这些信息,包括服务器软件、驱动程序等?

【问题讨论】:

    标签: asp.net configuration webserver phpinfo


    【解决方案1】:

    带有此标题的空白页面应该可以解决问题:

    <%@ Page Trace="true"  Language="C#" 
        ContentType="text/html" ResponseEncoding="utf-8" %>
    

    【讨论】:

      【解决方案2】:

      http://code.google.com/p/aspnetsysinfo/

      该项目是一个 ASP.Net 系统信息探测器。这是一个试图获取尽可能多的有用托管信息的页面。这个概念类似于包含phpinfo()...的PHP页面...

      【讨论】:

      【解决方案3】:

      ServerInfo.GetHtml()与phpinfo()基本相同。不仅实际返回的信息非常相似,而且 html 演示文稿也非常相似。 Here is a live demo!


      即使您只是制作纯 Web API 应用程序,但让控制器返回 HttpResponseMessage,您也可以使用它,如下所示:

          public System.Net.Http.HttpResponseMessage Get()
          {
              var serverinfo = System.Web.Helpers.ServerInfo.GetHtml().ToHtmlString();
              var response = new System.Net.Http.HttpResponseMessage();
              response.Content = new System.Net.Http.StringContent("<html><body>" + serverinfo + "</body></html>");
              response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html");
              return response;
          }
      

      【讨论】:

        【解决方案4】:

        如何使用 ASP.Net 跟踪子系统?它可以让您获得:

        控制树:控制树呈现一个 ASP.NET 的 HTML 表示 控制树。显示每个控件的 ID, 运行时类型,它的字节数 被渲染,它的字节数 需要在视图状态和控制中 状态。

        会话状态:列出所有密钥 特定用户的会话,他们的 类型及其值。

        应用程序状态:列出所有键 在当前应用程序的 应用对象及其类型和 价值观。

        Request Cookies:列出所有的cookies 页面期间传入的是 请求。

        响应 Cookie:列出所有 期间传回的 cookie 页面的响应。

        Headers 集合:显示所有 期间可能传入的标头 来自浏览器的请求, 包括Accept-Encoding,表示 浏览器是否支持 压缩 HTTP 响应并接受 语言。

        表单集合:显示一个完整的 表单集合的转储和所有 它的键和值。

        QueryString 集合:显示一个 查询字符串集合的转储和 它包含的所有键和值。

        服务器变量:完整转储 一切的名称-值对 Web 服务器知道 应用。

        见here。

        【讨论】:

          【解决方案5】:

          看看glimpse。

          glimpse: 客户端一瞥你的服务器

          Firebug 用于客户端,Glimpse 用于服务器...换句话说,客户端 Glimpse 了解服务器中发生的情况。

          这是request tab as shown in the browser。
          (来源:getglimpse.com)

          有other tabs with information,可以write plugins。

          【讨论】:

            【解决方案6】:

            以下可能有效?

            foreach (string Key in Request.ServerVariables.AllKeys) 
               Response.Write(Key + ": " + Request.ServerVariables[Key] + "<br>");
            

            我不确定 phpinfo() 会吐出什么信息。

            【讨论】:

              【解决方案7】:

              这是我找到的一个答案,乍一看,它似乎涵盖了它: http://www.actionscript.org/forums/showthread.php3?p=133347 有人把它写出来

              【讨论】:

              • 谢谢,但这是针对 Classic ASP,而不是 ASP.NET。
              • actionscript URL 已失效。请参阅下面的经典 ASP 解决方案我的答案。
              【解决方案8】:

              快速谷歌搜索结果:

              http://forums.asp.net/p/901862/2087653.aspx

              在他们看来,答案是否定的。

              【讨论】:

                【解决方案9】:

                对于带有 VBScript 的 ASP 经典(不是 ASP.net - 请参阅下面的免责声明),Planet Source Code 上有一个 Sub aspinfo(),我对其进行了非常小的更改(将调用移至aspinfo() 并移动最高作者/评论块)。

                这里是我修改版Dennis Pallett's aspinfo()的来源,可以在相关的网络服务器上保存为aspinfo.asp。

                <%@ Language="VBSCRIPT" %>
                <%
                
                    '**************************************
                    ' Name: aspinfo()
                    ' Description:aspinfo() is the equivalent of phpinfo(). It displays all kinds of
                    '     information about the server, asp, cookies, sessions and several other things in
                    '     a neat table, properly formatted.
                    ' By: Dennis Pallett (from psc cd)
                    '
                    '
                    ' Inputs:None
                    '
                    ' Returns:None
                    '
                    'Assumes:You can include my code in any of your pages and call aspinfo() to show
                    '     the information of your server and asp. 
                    '
                    '**************************************
                
                Sub aspinfo()
                    Dim strVariable, strASPVersion
                    Dim strCookie, strKey, strSession
                    'Retrieve the version of ASP
                    strASPVersion = ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion
                %>
                    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                    <html>
                    <head>
                    <style type="text/css"><!--
                    a { text-decoration: none; }
                    a:hover { text-decoration: underline; }
                    h1 { font-family: arial, helvetica, sans-serif; font-size: 18pt; font-weight: bold;}
                    h2 { font-family: arial, helvetica, sans-serif; font-size: 14pt; font-weight: bold;}
                    body, td { font-family: arial, helvetica, sans-serif; font-size: 10pt; }
                    th { font-family: arial, helvetica, sans-serif; font-size: 10pt; font-weight: bold; }
                    //--></style>
                    <title>aspinfo()</title></head>
                    <body>
                    <div align="center">
                    <table width="80%" border="0" bgcolor="#000000" cellspacing="1" cellpadding="3">
                    <tr>
                        <td align="center" valign="top" bgcolor="#FFFFAE" align="left" colspan="2">
                            <h3>ASP (<%= strASPVersion %>)</h3>
                        </td>
                    </tr>
                    </table>
                    <br>
                    <hr>
                    <br>
                    <h3>Server Variables</h3>
                    <table width="80%" border="0" bgcolor="#000000" cellspacing="1" cellpadding="3">
                <%
                    For Each strVariable In Request.ServerVariables
                      Response.write("<tr>")
                      Response.write("<th width=""30%"" bgcolor=""#FFFFAE"" align=""left"">" & strVariable & "</th>")
                      Response.write("<td bgcolor=""#FFFFD9"" align=""left"">" & Request.ServerVariables(strVariable) & "&nbsp;</td>")
                      Response.write("</tr>")
                    Next 'strVariable
                %>
                    </table>
                    <br>
                    <hr>
                    <br>
                    <h3>Cookies</h3>
                    <table width="80%" border="0" bgcolor="#000000" cellspacing="1" cellpadding="3">
                <%
                    For Each strCookie In Request.Cookies
                        If Not Request.Cookies(strCookie).HasKeys Then
                            Response.write("<tr>")
                            Response.write("<th width=""30%"" bgcolor=""#FFFFAE"" align=""left"">" & strCookie & "</th>")
                            Response.write("<td bgcolor=""#FFFFD9"" align=""left"">" & Request.Cookies(strCookie) & "&nbsp;</td>")
                            Response.write("</tr>")
                        Else
                            For Each strKey In Request.Cookies(strCookie)
                                Response.write("<tr>")
                                Response.write("<th width=""30%"" bgcolor=""#FFFFAE"" align=""left"">" & strCookie & "(" & strKey & ")</th>")
                                Response.write("<td bgcolor=""#FFFFD9"" align=""left"">" & Request.Cookies(strCookie)(strKey) & "&nbsp;</td>")
                                Response.write("</tr>")
                            Next
                        End If
                    Next
                %>
                    </table>
                    <br>
                    <hr>
                    <br>
                    <h3>Session Cookies</h3>
                    <table width="80%" border="0" bgcolor="#000000" cellspacing="1" cellpadding="3">
                <%
                    For Each strSession In Session.Contents
                            Response.write("<tr>")
                            Response.write("<th width=""30%"" bgcolor=""#FFFFAE"" align=""left"">" & strSession & "</th>")
                            Response.write("<td bgcolor=""#FFFFD9"" align=""left"">" & Session(strSession) & "&nbsp;</td>")
                            Response.write("</tr>")
                    Next
                %>
                    </table>
                    <br>
                    <hr>
                    <br>
                    <h3>Other variables</h3>
                    <table width="80%" border="0" bgcolor="#000000" cellspacing="1" cellpadding="3">
                    <tr><th width="30%" bgcolor="#FFFFAE" align="left">Session.sessionid</th><td bgcolor="#FFFFD9"><%= Session.sessionid %></td></tr>
                    <tr><th width="30%" bgcolor="#FFFFAE" align="left">Server.MapPath</th><td bgcolor="#FFFFD9"><%= Server.MapPath ("/") %></td></tr>
                    </table>
                    </div>
                    </body>
                    </html>
                <%
                End Sub
                aspinfo()
                %>
                

                免责声明:请注意,这最初是作为 edit 提交给 Rob's answer,但建议将其作为全新的答案响应。另请注意,正如frankadelic points out 在对 Rob 答案的评论中一样,此回复并未解决 OP 的问题,因为该问题针对 ASP.net,而不是 ASP Classic。

                【讨论】:

                  【解决方案10】:

                  我实现了一个包含在名为InfoPage 的项目中的简单库。该库向您显示系统信息、应用程序中包含的程序集、内部版本号和更改日志。

                  您可以通过 nuget 将其简单地包含在您的项目中,它可以快速集成和自定义。

                  【讨论】:

                    【解决方案11】:

                    我有一个gist available 在.net core 中添加一个带有phpinfo 类型信息的剃须刀页面...

                    【讨论】:

                      猜你喜欢
                      • 2012-10-16
                      • 2011-09-27
                      • 2010-10-21
                      • 1970-01-01
                      • 1970-01-01
                      • 2010-10-02
                      • 1970-01-01
                      • 2018-04-26
                      • 1970-01-01
                      相关资源
                      最近更新 更多