asp.net mvc keep object alive, information

前端 未结 4 363
梦如初夏
梦如初夏 2020-11-30 13:17

i have this code

[HttpPost]
public ActionResult Index(LoginModel loginModel)
{
    if (ModelState.IsValid)
    { 
       // some lines of code . bla bla bla
         


        
4条回答
  •  渐次进展
    2020-11-30 14:06

    You only need to store the user's identity (username) once the user is authenticated - password is not needed. As such ASP.NET authentication already supports storing user's identity in the authentication cookie and you don't have to re-invent the wheel. You can get the identity using Controller.User property.

    EDIT: I am assuming that you have set up your application correctly for Forms Authentication. Regardless, here are few how-to/tutorial links that start you on it:

    1. http://www.apexa.net/Blog/web_design_Blog_20100319.aspx
    2. http://www.asp.net/mvc/tutorials/authenticating-users-with-forms-authentication-cs
    3. Explain solution so that you don't have to apply Authorize attribute on every action - http://blogs.msdn.com/b/rickandy/archive/2011/05/02/securing-your-asp-net-mvc-3-application.aspx

提交回复
热议问题