简体   繁体   English

MVC4扩展WebSecurity.Login

[英]MVC4 Extending WebSecurity.Login

I have a need to use (and validate) both UserName, and Business Name as part of a Login Process. 我需要在登录过程中同时使用(并验证)用户名和公司名称。 So that my Login Form takes in CompanyId, UserId and Password. 这样我的登录表单就可以输入CompanyId,UserId和Password。

This all works fine up to the point where I call 一切正常,直到我打电话为止

 if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))

I can't just add in model.Companyid as a parameter to that method, I am hoping that it is just possible to extend this, or do I need to write my own Login method from scratch? 我不能只是将model.Companyid作为该方法的参数添加,我希望可以对此进行扩展,还是我需要从头开始编写自己的Login方法?

Of course! 当然!

public class ExtendWebSecurity
{
    public static boolean Login(
        this WebSecurity ws,
        string username,
        string password,
        boolean persist,
        int companyId)
    {
        // Add your logic
        return ws.Login(username, password, persistCookie: persist);
    }
}

Note, this has not been tested. 注意,这尚未经过测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM