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

后端 未结 11 1991
予麋鹿
予麋鹿 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 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("" + serverinfo + "");
            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html");
            return response;
        }
    

提交回复
热议问题