How to print similar information as phpinfo() but for ASP.NET?

后端 未结 11 1993
予麋鹿
予麋鹿 2020-12-08 11:27

I\'ve looped over the Request.ServerVariables collection in ASP.NET, but it\'s not as comprehensive as phpinfo().

How can I print all that

相关标签:
11条回答
  • 2020-12-08 11:56

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

    The project is a ASP.Net System Information Prober. It's a single page which trying to get as much as possible of useful hosting information. The concept is similar to PHP page which contains phpinfo()...

    0 讨论(0)
  • 2020-12-08 11:58

    The following might work?

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

    I'm not sure what info phpinfo() spits out.

    0 讨论(0)
  • 2020-12-08 11:59

    Quick google result:

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

    According to them, the answer is no.

    0 讨论(0)
  • 2020-12-08 12:00

    How about using the ASP.Net tracing subsystem? It allows you to get:

    Control Tree: Control tree presents an HTML representation of the ASP.NET Control Tree. Shows each control's ID, run time type, the number of bytes it took to be rendered, and the bytes it requires in View State and Control State.

    Session State: Lists all the keys for a particular user's session, their types and their values.

    Application State: Lists all the keys in the current application's Application object and their type and values.

    Request Cookies: Lists all the cookies passed in during the page is requested.

    Response Cookies: Lists all the cookies that were passed back during the page's response.

    Headers Collection: Shows all the headers that might be passed in during the request from the browser, including Accept-Encoding, indicating whether the browser supports the compressed HTTP responses and Accept languages.

    Form Collection: Displays a complete dump of the Form Collection and all its keys and values.

    QueryString Collection: Displays a dump of the Querystring collection and all its contained keys and values.

    Server Variables: A complete dump of name-value pairs of everything that the web server knows about the application.

    See here.

    0 讨论(0)
  • 2020-12-08 12:01

    ServerInfo.GetHtml() is basically the same as phpinfo(). Not only is the actual returned information extremely similar but also the html presentation. Here is a live demo!


    You can also use it even if you're only making a pure Web API app, but letting a controller return a HttpResponseMessage like so:

        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;
        }
    
    0 讨论(0)
提交回复
热议问题