문제

I have a post action called Login which does some server side validation and the actual logging in of the user. I have another post action where the user resets their password. I would like this action to directly log them in upon success, instead of bringing them back to the login back to type in their new credentials.

I would like to somehow call the logic I've already written. How would I achieve this?

도움이 되었습니까?

해결책

Can't you just extract the part of your Login action that does the actual logging in to another method of your controller? Which could then also be called from your ResetPassword action.

public class FirstController : BaseLoginController
{
    [HttpPost]
    public ActionResult Login()
    {
        base.ExecuteLogin();
    }
}

public class SecondController : BaseLoginController
{
    [HttpPost]
    public ActionResult ResetPassword()
    {
        base.ExecuteLogin();
    }
}

public class BaseLoginController
{
    protected void ExecuteLogin()
    {
        // login logic
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top