在WebSecurity中传递其他数据 [英] Passing additional data in WebSecurity

查看:30
本文介绍了在WebSecurity中传递其他数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在ASP.NET MVC 4中使用默认表单身份验证实现.

I'm using default forms authentication implementation in ASP.NET MVC 4.

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
    if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
    {
       //Assign additional data
        return RedirectToLocal(returnUrl);
    }

    // If we got this far, something failed, redisplay form
    ModelState.AddModelError("", "The user name or password provided is incorrect.");
    return View(model);
}

这很好.我需要传递每个登录用户的一些其他数据,以供以后使用,而无需再次访问数据库.(例如:用户角色和角色详细信息)

This works fine. I need to pass some additional data of each logged in user, to use later, without accessing the database again. (ex: user roles and role details)

在不使用Session变量的情况下,WebSecurity中是否有任何实现?

Is there any implementation in WebSecurity to do this without using Session variable?

推荐答案

您可以使用此方法添加其他值和参数websecurity方法:

you can use this method to additional values and parameter websecurity method :

WebSecurity.CreateUserAndAccount(model.UserName, model.Password,
                        propertyValues: new
                        {
                            NameFamily = model.NameFamily,
                            PostCode = model.PostCode,
                            Address = model.Address,
                            Phone = model.Phone,
                            Lat = model.Lat,
                            Lng = model.Lng
                        });

这篇关于在WebSecurity中传递其他数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆