programmatic login with .net membership provider

后端 未结 4 1239
耶瑟儿~
耶瑟儿~ 2021-01-02 18:49

I\'m trying to unit test a piece of code that needs a currently logged in user in the test. Using the .Net 2.0 Membership Provider, how can I programmatically log in as a us

4条回答
  •  不知归路
    2021-01-02 19:12

    Using your Membership Provider you can validate a user using Membership.ValidateUser. Then you can set the authentication cookie using FormsAuthentication.SetAuthCookie. As long as you have a cookie container this should allow you to log in a user.

提交回复
热议问题