获取IIS设置

时间:2012-02-26 11:35:18

标签: c# asp.net .net iis iis-7

我想打印以记录有关运行IIS服务的网站的基本信息。

任何建议/示例如何完成?

2 个答案:

答案 0 :(得分:1)

将以下代码添加到页面加载事件,然后导航到页面。您应该找到有用的输出,并且它对于评估Web服务器安全区之间的差异非常有用。

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

try
dim outputString as string = string.empty

 outputString = "Server: " & HttpContext.Current.Server.MachineName.ToString() & "<br/>"
 outputString = outputString &  ".Net version: " & Environment.Version.ToString() & "<br/>"    
 outputString = outputString &  "machine config file directory: " & System.web.HttpRuntime.MachineConfigurationDirectory.ToString() & "<br/>"
 outputString = outputString & "<br/>"

 outputString = outputString &  "security principal user: " & System.Security.Principal.WindowsIdentity.GetCurrent().Name & "<br/>"
 outputString = outputString &  "computer (server) logon user identity: " & Request.LogonUserIdentity.Name & "<br/>"
 outputString = outputString &  "login in user identity: " & System.Windows.Forms.SystemInformation.UserName.ToString() & "<br/>"     
 outputString = outputString &  "app: " & System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString() & "<br/>"
  outputString = outputString & "<br/>"    

 outputString = outputString &  "app version: " & System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() & "<br/>"
 outputString = outputString &  "windows forms application product version: " & System.Windows.Forms.Application.ProductVersion & "<br/>"        
 'outputString = outputString &  "context items: " & HttpContext.Current.items.ToString() & "<br/>"
 outputString = outputString &  "app domain id: " & System.web.HttpRuntime.AppDomainAppId.ToString() & "<br/>"
 outputString = outputString & "<br/>"

 outputString = outputString &  "app domain app path: " & System.web.HttpRuntime.AppDomainAppPath.ToString() & "<br/>"
 outputString = outputString &  "app domain virtual path: " & System.web.HttpRuntime.AppDomainAppVirtualPath.ToString() & "<br/>"
 outputString = outputString &  "client script physical path: " & System.web.HttpRuntime.AspClientScriptPhysicalPath.ToString() & "<br/>"
 outputString = outputString &  "client script virtual path: " & System.web.HttpRuntime.AspClientScriptVirtualPath.ToString() & "<br/>"
 outputString = outputString & "<br/>"

 outputString = outputString &  "asp install directory: " & System.web.HttpRuntime.AspInstallDirectory.ToString() & "<br/>"
 outputString = outputString &  "Common language runtime directory: " & System.web.HttpRuntime.ClrInstallDirectory.ToString() & "<br/>"
 outputString = outputString &  "Code gen directory: " & System.web.HttpRuntime.CodegenDir.ToString() & "<br/>"

lblOutput.text = outputString
catch ex as exception
lblOutput.text = ex.tostring

end try


End Sub

答案 1 :(得分:0)

查看网站的IIS应用程序池标识的一种简单方法是使用以下代码将.aspx页面添加到默认目录中。确保启用匿名身份验证或Windows身份验证,然后尝试通过浏览器访问该页面。

<% @ Page Language="C#" %>
<%
Response.Write ("App Pool Identity - " + System.Security.Principal.WindowsIdentity.GetCurrent().Name);
%>

应该输出与此类似的东西

enter image description here