[英]Windows authentication on webpage - No user
我在我的 webconfig 中啟用了 Windows 身份驗證。 現在我想檢索試圖訪問網頁的用戶,如下所示:
[AllowAnonymous]
public async Task<ActionResult> Index()
{
try
{
var username2 = System.Web.HttpContext.Current.User.Identity.Name;
}
}
我無法從Curent.User.Identity.Name
獲取任何用戶。 它只是空白。 為什么這個?
我也嘗試禁用匿名身份驗證,但是當我這樣做時,會提示登錄對話框。 我不想要那個。
我只想讓試圖訪問該頁面的計算機用戶。 這可能嗎?
而且我不是在尋找Environment.Username
,因為當我部署到主服務器時它不起作用。
請嘗試使用 [Authorize] 屬性
我在控制器中的代碼是這樣工作的 -
[Authorize(Roles="# Some_team_name")]
public ActionResult Foo(string param1)
{
string windowsLogonName = User.Identity.Name;
...............
...............
PS:我希望版主能理解,評論一個仍然需要50分,所以我把我的評論放在了答案區。 希望沒問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.