我有一個網站,說的地址是: website.com 如果我進入網站,並點擊一個按鈕,應彈出一個消息框它將無法正常工作。按鈕沒有響應時,沒有顯示完整的網頁url
,如果我進入網站是這樣的: website.com/Default.aspx
它的方式兩種方式顯示在同一頁面,但使用的Default.aspx名稱只是在按鍵響應。
我試着這樣做:
if (!Request.Url.ToString().Contains("Default.aspx"))
{
Response.Redirect("Default.aspx");
}
但出於某種原因,並沒有幫助。爲什麼會發生這種情況,我該如何解決?
Buttonclick:
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
Session.Clear();
Session.RemoveAll();
Response.Cookies.Clear();
Login user = new Login(txtID.Text, txtPassword.Text);
if (user.IsValid)
whois = user.sc;
else
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["hakerendbConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("SELECT COUNT(id) FROM tblCEO WHERE id = '" + txtID.Text + "' AND password = '" + txtPassword.Text + "'", conn);
conn.Open();
if (cmd.ExecuteScalar().ToString() == "1")
{
conn.Close();
popupCeo.Visible = true;
return;
}
else
{
conn.Close();
ajaxPanel.Alert("ת.ז או סיסמא שגויה.");
return;
}
}
}
catch { ajaxPanel.Alert("תקלה במערכת, אנא חזרו מאוחר יותר הבעיה בטיפול."); }
try
{
HttpCookie user = new HttpCookie("UserName", Security.Encrypt(txtID.Text));
user.Expires = DateTime.Now.AddHours(1);
if (chkbox.Checked)
user.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Clear();
Response.Cookies.Add(user);
switch (whois)
{
case Security.level.Investor:
Response.Redirect("InvestorProjectViewer.aspx");
break;
case Security.level.Agent:
Response.Redirect("AgentManager.aspx");
break;
case Security.level.SeniorAgent:
Response.Redirect("SeniorManager.aspx");
break;
}
}
catch { }
}
後按一下按鈕處理程序的代碼解決了這個煩惱。 – Michael 2014-09-01 17:26:54
@michaelmoore Here – Bodokh 2014-09-01 17:28:13