ASP.NET窗体身份验证 - 自动登录一个测试帐号在调试时? [英] ASP.NET forms authentication - auto login with a test account while debugging?

查看:96
本文介绍了ASP.NET窗体身份验证 - 自动登录一个测试帐号在调试时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用asp.net成员资格和角色提供允许登录的某些角色的成员能够获得取决于角色分配不同页面的Web应用程序。

I have a web application that uses the asp.net membership and role providers to allow logins that are members of certain roles to have access to various pages depending on role assignments.

在调试过程中,我想该应用与测试帐户自动登录,这样我就可以查看角色分配的功能,而不必去通过登录页面上输入凭据各一次。有没有一种简单的方法来做到这一点?

During debugging I'd like the app to log in automatically with a test account, so I can check the functionality of the role assignments, and not have to go through entering credentials on the login page each time. Is there an easy way to do this?

推荐答案

这code做这项工作。在为Login.aspx的Page_Load事件:

This code does the job. In Login.aspx's Page_Load event:

    Membership.ValidateUser("<userName>", "<password>")
    FormsAuthentication.RedirectFromLoginPage("<userName>", True)

<一个href=\"https://msdn.microsoft.com/en-us/library/system.web.security.membership.validateuser(v=vs.110).aspx\"相对=nofollow> MSDN文档

注意:成员使用 System.Web.Security 引用

这篇关于ASP.NET窗体身份验证 - 自动登录一个测试帐号在调试时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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