asp.net 的帳號,有好多個。
其中,最常用的就是 Page.User.Identity,代表使用者登入後,系統認定該使用者的帳號。
這有什麼問題呢?原來,帳號的學問可大著呢。
protected void Page_Load(object sender, EventArgs e)
{
lblPage.Text = this.Page.User.Identity.Name;
lblThread.Text = Thread.CurrentPrincipal.Identity.Name;
lblWindowsIdentity.Text = WindowsIdentity.GetCurrent().Name;
lblLogonUserIdentity.Text = this.Page.Request.LogonUserIdentity.Name;
}
| Identity | 說明 |
| this.Page.User.Identity | 使用者登入後,系統用來識別該使用者的帳號 |
| Thread.CurrentPrincipal.Identity | 這個我不太了解。通常與this.Page.User.Identity相同。 |
| WindowsIdentity.GetCurrent() | 代表執行該網頁時,Windows 真正執行的identity |
| this.Page.Request.LogonUserIdentity | IIS 上設定的執行帳號。IIS 6 以後,就是 Application Pool 所指定的identity,通常是 Network Service |
這有哪些變化呢?
- IIS 上的驗證方式。有 anonymous, windows NTLM。
- IIS 上 Application pool 的 identity
- web.config 上的 <authenticaion mode=”Forms” or mode=”Window”
- web.config 上 <identity impersonate="true", 或 <identity impersonate="true" userName="userName" password="password"/>
這些設定,都可能影響上述4個 identity 的值。由於變化太多了,我也無法完全記錄下來。大家就自行試試看囉!
範例程式下載
沒有留言:
張貼留言