2015-04-28 19 views
-1

我想爲我的ASP.NET Intranet應用程序啓用Windows身份驗證。 爲此,我在我的web.config文件中完成了以下步驟。帶有模擬功能的ASP.NET Windows身份驗證

<system.web> 
<authentication mode="Windows" > 

    </authentication> 
    <authorization> 
     <deny users="?"/> 
    </authorization> 
    <identity impersonate="true" userName="domain\myusername" password="mypwd" /> 
</system.web> 

而且我想在我的網頁訪問身份驗證的用戶名作爲

HttpContext.Current.User.Identity.Name 

它拋出一個「拒絕訪問」錯誤消息。

+0

那麼你必須在你的網頁上獲取模擬名稱嗎? –

+0

不,我在這裏沒有得到任何用戶名,它引發了訪問被拒絕的錯誤。當我刪除授權標記時,我可以訪問我的頁面,但不能獲取模擬的用戶。 – Karthikeyan

+0

嘗試使用'WindowsIdentity.Name'或'WindowsIdentity.GetCurrent()。Name'而不是'HttpContext.Current.User.Identity.Name'。 –

回答

3

嘗試使用WindowsIdentity.NameWindowsIdentity.GetCurrent().Name而不是HttpContext.Current.User.Identity.Name

只要向Claim添加角色,您可以在一些代碼的幫助下添加角色。這些鏈接可以幫助您:

Creating ClaimIdentity Object

Claim Based Security in C#

希望這有助於。