programmatic login with .net membership provider

后端 未结 4 1238
耶瑟儿~
耶瑟儿~ 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条回答
  •  旧时难觅i
    2021-01-02 19:24

    Does your code actually need a user logged in via ASP.NET, or does it just need a CurrentPrincipal? I don't think you need to programmatically log in to your site. You can create a GenericPrincipal, set the properties you need, and attach it to, for example Thread.CurrentPrincipal or a mocked HttpContext. If your code actually needs RolePrincipal or something then I would change the code to be less coupled to ASP.NET membership.

提交回复
热议问题