if (Request.QueryString["Username"] != null)
{
Login1.UserName =Request.QueryString["Username"];
Login1.Password = Request.QueryString["Password"];
if (FormsAuthentication.Authenticate(Login1.UserName, Login1.Password))
{
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
}
}
else{
if (FormsAuthentication.Authenticate(Login1.UserName, Login1.Password))
{
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
}
}
如何将querystring密码传递给Login1.Password.I我正在使用FormsAuthentication方法登录。但是Login1.Password不接受来自querystring的值.Is Login1.Password会给出打字错误吗?请帮忙
答案 0 :(得分:1)
您不需要Authenticate
的登录控件,请将用户名和密码作为参数
string username= Request.QueryString["Username"];
string password = Request.QueryString["Password"];
if (FormsAuthentication.Authenticate(username, password))
{
FormsAuthentication.RedirectFromLoginPage(username, true);
}
但不建议将密码作为查询字符串发送,最好阅读How to safely include password in query string
答案 1 :(得分:1)
您可以直接将查询字符串参数传递给Forms Authentication Authenticate函数,如下所示
if (Request.QueryString["Username"] != null && Request.QueryString["Password"] != null)
{
if (FormsAuthentication.Authenticate(Request.QueryString["Username"].ToString(), Request.QueryString["Password"].ToString()))
{
// Authentication successful code
FormsAuthentication.RedirectFromLoginPage(Request.QueryString["Username"].ToString(), true);
}
else
{
// Authentication unsuccessful code
}
}
else
{
// Parameter invalid or missing code
}