ASP.Net/Network/HttpRuntime

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Show Runtime Info

   <source lang="csharp">

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ShowRuntimeInfo" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">

   <title>Runtime Inspector</title>

</head> <body>

   <form id="form1" runat="server">
       <asp:button ID="Button1" runat="server" text="Show HTTP Runtime Properties" onclick="OnShowInfo" />
       <asp:button ID="Button2" runat="server" text="Restart the Application" OnClick="Button2_Click" /> 

       <asp:Label runat="server" id="TheRuntimeInfo" />     
   </form>

</body> </html> File: Default.aspx.cs using System; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Reflection; using System.Text; using System.IO;

public partial class ShowRuntimeInfo : System.Web.UI.Page {

   protected void OnShowInfo(object sender, EventArgs e)
   {
       DisplayRuntimeInfo();
   }
   private void DisplayRuntimeInfo()
   {
       StringBuilder sb = new StringBuilder("");
       sb.Append("AppDomainAppId:");
       sb.Append(HttpRuntime.AppDomainAppId);
       sb.Append("
"); sb.Append("AppDomainAppPath:"); sb.Append(HttpRuntime.AppDomainAppPath); sb.Append("
"); sb.Append("AppDomainAppVirtualPath:"); sb.Append(HttpRuntime.AppDomainAppVirtualPath); sb.Append("
"); sb.Append("AppDomainId:"); sb.Append(HttpRuntime.AppDomainId); sb.Append("
"); sb.Append("Temp ASP.NET Directory"); sb.Append(HttpRuntime.CodegenDir); sb.Append("
"); Assembly[] listOfAssem = AppDomain.CurrentDomain.GetAssemblies(); sb.Append("Assemblies in the AppDomain ("); sb.Append(listOfAssem.Length.ToString()); sb.Append(")
"); ArrayList list = new ArrayList(); foreach (Assembly a in listOfAssem) { try { list.Add(Path.GetFileName(a.Location)); } catch { } } list.Sort();
sb.Append("
    "); foreach (object asm in list) { sb.Append("
  • "); sb.Append((string)asm); sb.Append("
  • ");
           }
    
    sb.Append("
");
       sb.Append("</td></tr></table>");
       TheRuntimeInfo.Text = sb.ToString();
   }
   protected void Button2_Click(object sender, EventArgs e)
   {
       HttpRuntime.UnloadAppDomain();
       DisplayRuntimeInfo();
   }

}

</source>