2017-09-29 335 views
0

我正在嘗試爲有效用戶設置cookie,但我無法使用SetAuthCookie作爲拋出提到的錯誤。我添加了System.Web.Security名稱空間,但仍無法使用它。我需要爲此安裝一些特殊的nuget包嗎?名稱空間「FormAuthentication」中不存在類型或名稱空間名稱「SetAuthCookie」

以下是我在控制器的操作方法都試過:

[HttpPost] 
public ActionResult Login(User user) 
{ 
    if (user.Username.ToLower() == "admin" || user.Password == "admin") 
    { 
     FormAuthentication.SetAuthCookie(user.Username, false); 
    } 
    return View(); 
} 

enter image description here

回答

1

它應該是FormsAuthentication

你錯過了 'S'

相關問題