基本上我使用visual studio中提供的登录表单并尝试使用sql数据库进行身份验证。如果我输入的数据不正确,则会显示正确的验证,但是当我输入正确的数据时,它只刷新当前表单而不是记下destinationUrl部分。
我现在无法解决这个问题......帮助
以下是我的表格代码:
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 Username=@un and Password=@pw", 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)
{
}
}
}
答案 0 :(得分:0)
试试这个:
string returnUrl = Request.QueryString["ReturnUrl"];
if (returnUrl == null) returnUrl = @"~/yourfirstpage.aspx";
Response.Redirect(returnUrl);