一般執行ASP.NET的網站程式時,預設都是用匿名存取的

預設是用一個IUSR或NetWork Service的匿名帳號

 

(Window驗證通常是用在內部網路喔)

如果要用使用者登入的Window作業系統的帳號密碼來當

成是網站的驗證的話

IIS要去設定成Window驗證

和把匿名存取關閉

和把Impersonation打開,這是用使用者帳號來模擬的

(也就是用使用者的帳號來驗證一些權限)

 

網站部份是改Web.Config檔

<configuration>

<system.web>

  <authentication mode="Windows"/>

  <identity impersonate="true"/>

</system.web>

</configuration>

 

程式中用User.Identity.Name可顯示登入者的帳號

用System.Security.Principal.WindowsIdentity.GetCurrent().Name

可知道目前是以哪一個帳號來執行網站程式

 

arrow
arrow
    全站熱搜

    welkingunther 發表在 痞客邦 留言(2) 人氣()