1
基本上我使用visual studio中提供的登录表单并尝试使用sql数据库进行身份验证。如果我输入了不正确的数据,则会出现正确的验证,但是当我在此刻输入正确的数据时,它只刷新当前表单而不是记录destinationUrl部分。在asp.net登录表单不会直接登录页面
我在现在该怎么解决这个亏损...帮助
下面是我的形式代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace com.tortoise.Admin.AdminViews
{
public partial class WebForm1 : System.Web.UI.Page
{
private string strcon = WebConfigurationManager.ConnectionStrings["TortoiseDBConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
private bool UserLogin(string un, string pw)
{
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("Select Username from Admins where [email protected] and [email protected]", con);
cmd.Parameters.AddWithValue("@un", un);
cmd.Parameters.AddWithValue("@pw", pw);
con.Open();
string result = Convert.ToString(cmd.ExecuteScalar());
if (string.IsNullOrEmpty(result)) return false; return true;
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string un = Login1.UserName;
string pw = Login1.Password;
bool result = UserLogin(un, pw);
if (result)
{
e.Authenticated = true;
Session["username"] = un;
Login1.DestinationPageUrl =
String.Format("Manager.aspx?{0}", Request.QueryString.ToString());
}
else e.Authenticated = false;
}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
}
}
试试'String.Format(“〜/ Manager.aspx?{0}”,...'我总是用'Response.Redirect' – TestWell
我从来没有用过任何东西,q-string有一个总是自动填充和重定向。你可能需要添加web.config中的某些东西,Sry我忘记了现在的东西,或者删除并重新添加登录控件。 – wazz
p.s.您可以对管理区域使用单独的登录和web.config。 – wazz