. NET get server information, such as Server version, IIS, etc.

Source: Internet
Author: User
Tags servervariables

. NET get server information, such as Server version, IIS, etc.

. NET get server information, such as Server version, IIS version, database size, site system footprint, site deployment path, and so on

. NET Get system Environment information

#region returns the operating system information. NET version database size program size and other methods
<summary>
Get Server System Information
</summary>
public string getosversion ()
{
OperatingSystem os = environment.osversion;
return OS. ToString ();
}
<summary>
Get the server. NET version
</summary>
<returns></returns>
public string getnetversion ()
{
return Environment.Version.ToString ();
}
<summary>
Get database size
</summary>
<returns></returns>
public string Getdatabaselength ()
{
String filefullpath = HttpContext.Current.Server.MapPath ("~/app_data/xxx.mdf");
FileInfo file = new FileInfo (Filefullpath);
Return (convert.todouble (file. Length)/1024/1024). ToString ("N") + "M";
}
<summary>
Recursive file directory, return all file size under directory
</summary>
<param name= "D" > Incoming path </param>
<returns></returns>
public static long Dirsize (DirectoryInfo D)
{
Long Size = 0;
All file sizes.
fileinfo[] fis = d.getfiles ();
foreach (FileInfo fi in FIS)
{
Size + = fi. Length;
}
Iterates through all the folders of the current directory.
directoryinfo[] dis = d.getdirectories ();
foreach (DirectoryInfo di in dis)
{
Size + = Dirsize (DI); This is recursive, call the parent method, note that this is not a direct return value, but instead call the parent returned
}
return (Size);
}
<summary>
Calling the Dirsize method
</summary>
<returns></returns>
public string Getdirsize ()
{
String fullPath = HttpContext.Current.Server.MapPath ("~/");
DirectoryInfo d = new DirectoryInfo (FullPath);
Return (Convert.todouble (Dirsize (d))/1024/1024). ToString ("N") + "M";
}
#endregion
#region Server-related properties
<summary>
Server name
</summary>
public string MachineName
{
get {return HttpContext.Current.Server.MachineName;}
}
<summary>
Server operating System
</summary>
public string Servivesystem
{
get {return getosversion ();}
}
<summary>
Server IP Address
</summary>
public string Serviceip
{
get {return httpcontext.current.request.servervariables["local_addr"];}
}
<summary>
Website Port number
</summary>
public string Serviceport
{
get {return httpcontext.current.request.servervariables["Server_port"];}
}
<summary>
Server IIS version
</summary>
public string Serviceiis
{
get {return httpcontext.current.request.servervariables["Server_software"];}
}
<summary>
Server. NET Interpretation engine version
</summary>
public string Servicenetversion
{
get {return getnetversion ();}
}
<summary>
Server time
</summary>
public string ServiceTime
{
get {return DateTime.Now.ToString ();}
}
<summary>
Site Absolute Path
</summary>
public string ServicePath
{
get {return httpcontext.current.request.servervariables["path_translated"]. ToString (); }
}
<summary>
Database size
</summary>
public string Databaselength
{
get {return getdatabaselength ();}
}
<summary>
Get Program Space size
</summary>
public string Getsystemlength
{
get {return getdirsize ();}
}
#endregion

. NET Traversal service all variable information

<table colspan= "8" cellpadding= "5" border= "0" >
<tr>
<TD align= "CENTER" bgcolor= "#800000" width= "20%" >
<font style= "Arial Narrow" color= "#ffffff" size= "2" > Environment variable name </font>
</td>
<TD align= "CENTER" width= "80%" bgcolor= "#800000" >
<font style= "Arial Narrow" color= "#ffffff" size= "2" > Results </font>
</td>
</tr>
<%
foreach (String val in Request.ServerVariables)
{
Response.Write ("<tr>");
Response.Write ("<td bgcolor= ' f7efde ' align=center> <font style= ' ARIAL NARROW ' size= ' 2 ' >");
Response.Write (Val);
Response.Write ("</font></td>");
Response.Write ("<td bgcolor= ' f7efde ' align=center> <font style= ' ARIAL NARROW ' size= ' 2 ' >");
Response.Write (Request.servervariables[val]);
Response.Write ("</font></td></tr>");
}%>
</table>

Reprint please specify the source [http://samlin.cnblogs.com/]

Share to:

When calculating books 50 percent-80 percent

Just do the bidding network: eight claw fish Bidding network please many views

. NET get server information, such as Server version, IIS, etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.