2012-04-11 34 views

Trả lời

33

Bạn có thể sử dụng System.Security.Principal.WindowsIdentity.GetCurrent().Name để xác định Danh tính mà ứng dụng hiện đang chạy. This link cung cấp một tiện ích tốt đẹp hiển thị danh tính theo đó aspx được chạy.

+0

Nếu tôi thay đổi thông tin nhận dạng ứng dụng trong Trình quản lý IIS thì không nên System.Security.Principal.WindowsIdentity.GetCurrent(). – p0enkie

+6

Ok đối với một người nào đó có thể gặp khó khăn, đây là mã tôi đã sử dụng để lấy tên người dùng đã bắt đầu AppPool (danh tính của nó): ApplicationPool pool = serverManager.ApplicationPools ["YoutAppPoolName"]; pool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser; string user = pool.ProcessModel.UserName; – p0enkie

+1

@ p0enkie 'serverManager' là gì? – Kiquenet

2

Bạn cần thực hiện tham chiếu đến Microsoft.Web.Administration (trong Microsoft.Web.Administration.dll). Microsoft.Web.Administration.dll nằm trong C: \ Windows \ System32 \ inetsrv.

//Add this to your using statements: 
using Microsoft.Web.Administration; 

//You can get the App Pool identity like this:  
public string GetAppPoolIdentity(string appPoolName) 
{ 
    var serverManager = new ServerManager(); 

    ApplicationPool appPool = serverManager.ApplicationPools[appPoolName]; 
    appPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser; 
    return appPool.ProcessModel.UserName;    
}