Làm cách nào để tôi nhận được danh tính của ứng dụngHãy lập trình trong C#? Tôi muốn người dùng trong hồ bơi ứng dụng và KHÔNG phải là người dùng hiện đang đăng nhập.Nhận Hồ sơ Ứng dụng Hồ sơ theo chương trình
24
A
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.
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;
}
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
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
@ p0enkie 'serverManager' là gì? – Kiquenet