javascript - 我的用户登录错误验证消息曾经显示在 chrome 上,但现在不显示了
问题描述
当我在 Visual Studio 上调试我的网站的用户登录页面并尝试测试无效用户登录的错误验证时,ClientScript.RegisterStartupScript 错误消息不显示,页面只是自行刷新。对不起,如果我不够具体,我会尽力解释情况。如果您需要更多信息,请告诉我。
**This is my aspx.cs codes:**
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
public partial class Login : System.Web.UI.Page
{
static readonly string scriptErrorUserId =
"<script language=\"javascript\">\n" +
"alert (\"Error - UserID you keyed in is taken up, please key in another UserID\");\n" +
"</script>";
static readonly string scriptErrorField =
"<script language=\"javascript\">\n" +
"alert (\"Error - Some fields are empty please fill them up\");\n" +
"</script>";
static readonly string scriptSuccessNewAccount =
"<script language=\"javascript\">\n" +
"alert (\"Your account has been succesfully created - Thank You!\");\n" +
"</script>";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSignin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["SQLAzureConnection"].ConnectionString);
con.Open();
Type csType = this.GetType();
SqlCommand sqlcmd;
SqlDataReader rdr;
string strSql1 = "SELECT * FROM Customer ";
sqlcmd = new SqlCommand(strSql1, con);
rdr = sqlcmd.ExecuteReader();
string encryptedPwd = WMASecurity.Encrypt(txtpw.Text);
while (rdr.Read() == true)
{
if (txtUsername.Text == (string)rdr["cCustID"] &&
encryptedPwd == (string)rdr["cPassword"])
//txtPassword.Text == (string)rdr["cPassword"])
{
Session["sFlag"] = "T"; //sFlag = "T" means user has logged in
Session["sUserId"] = rdr["cCustID"];
Session["sName"] = rdr["cName"];
Session["sContact"] = rdr["cPhoneNo"];
Session["sGender"] = rdr["CGender"];
Session["sEmail"] = rdr["cEmail"];
Session["sAddress"] = rdr["cAddress"];
Session["sPoints"] = rdr["cPoints"];
Session["stotalspend"] = rdr["ctotalspend"];
string welcomeMsg = "Welcome " + Session["sName"];
Master.MasterpageLabel.Text = welcomeMsg;
Master.divLogin.Visible = false;
Master.divLogout.Visible = true;
Master.divUpdate.Visible = true;
con.Close();
String strUserId = (string)Session["sUserId"];
cDataRoutines DROObject = new cDataRoutines();
DROObject.cCreateRecs(strUserId);
Response.Redirect("Homepage.aspx");
return;
}
}
//
Session["sFlag"] = "F"; //sFlag = "F" means user has failed to logged in
Session["sName"] = "";
Session["sUserId"] = "";
Session["sAddress"] = "";
Session["sEmail"] = "";
Session["sContact"] = "";
Session["sGender"] = "";
txtUsername.Text = "";
con.Close();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["SQLAzureConnection"].ConnectionString);
con.Open();
Type csType = this.GetType();
//Check to ensure that UserId keyed in is not being in used by other Customers
SqlCommand sqlcmd;
SqlDataReader rdr;
string strSQLSelect = "SELECT cCustID FROM Customer ORDER BY cCustID";
sqlcmd = new SqlCommand(strSQLSelect, con);
//SqlDataReader reader = sqlcmd.ExecuteReader();
rdr = sqlcmd.ExecuteReader();
string encryptedPwd = WMASecurity.Encrypt(txtPassword.Text);
while (rdr.Read() == true)
if (txtUserId.Text == (string)rdr["cCustID"])
{
ClientScript.RegisterStartupScript(csType, "Error", scriptErrorUserId);
con.Close();
return;
}
if (txtUserId.Text == "")
{
ClientScript.RegisterStartupScript(csType, "Error", scriptErrorField);
con.Close();
return;
}
if (txtAddress.Text == "")
{
ClientScript.RegisterStartupScript(csType, "Error", scriptErrorField);
con.Close();
return;
}
if (txtName.Text == "")
{
ClientScript.RegisterStartupScript(csType, "Error", scriptErrorField);
con.Close();
return;
}
if (txtEmail.Text == "")
{
ClientScript.RegisterStartupScript(csType, "Error", scriptErrorField);
con.Close();
return;
}
if (txtPassword.Text == "")
{
ClientScript.RegisterStartupScript(csType, "Error", scriptErrorField);
con.Close();
return;
}
// insert new record
string strSQLInsert = "INSERT INTO "
+ " Customer (cCustID, cName, cPassword, cPhoneNo, CGender, cEmail, cAddress)"
+ " VALUES (@CustID, @Name, @Password, @Contact, @Gender, @Email, @Address)";
sqlcmd = new SqlCommand(strSQLInsert, con);
sqlcmd.Parameters.AddWithValue("@CustID", txtUserId.Text);
sqlcmd.Parameters.AddWithValue("@Name", txtName.Text);
sqlcmd.Parameters.AddWithValue("@Password", encryptedPwd);
sqlcmd.Parameters.AddWithValue("@Contact", txtContact.Text);
sqlcmd.Parameters.AddWithValue("@Gender", Genderdropdown.SelectedValue);
sqlcmd.Parameters.AddWithValue("@Email", txtEmail.Text);
sqlcmd.Parameters.AddWithValue("@Address", txtAddress.Text);
sqlcmd.ExecuteNonQuery();
con.Close();
txtUserId.Text = "";
txtPassword.Text = "";
txtName.Text = "";
txtAddress.Text = "";
txtEmail.Text = "";
ClientScript.RegisterStartupScript(csType, "Success", scriptSuccessNewAccount);
// prepare Session variables for newly registered customer
Session["sFlag"] = "T";
Session["sCustId"] = (string)txtUserId.Text;
Session["sName"] = (string)txtName.Text;
Session["sContact"] = (string)txtContact.Text;
Session["sGender"] = (string)Genderdropdown.SelectedValue;
Session["sEmail"] = (string)txtEmail.Text;
Session["sAddress"] = (string)txtAddress.Text;
}
}`enter code here`
this is my webconfig file:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->`enter code here`
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
<connectionStrings>
<add name="AlanandguysSQLConnectionString" connectionString="Data Source=DESKTOP-V6SOBQI;Initial Catalog=AlanandguysSQL;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="AlanandguysSQL (1)ConnectionString" connectionString="Data Source=DESKTOP-V6SOBQI;Initial Catalog="AlanandguysSQL (1)";Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="AlanandguysSQL (1)ConnectionString2" connectionString="Data Source=DESKTOP-V6SOBQI;Initial Catalog="AlanandguysSQL (1)";Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="AlanandguysSQL (1)ConnectionString3" connectionString="Data Source=DESKTOP-V6SOBQI;Initial Catalog="AlanandguysSQL (1)";Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="SQLAzureConnection" connectionString="Data Source=alannguys.database.windows.net;Initial Catalog=alannguys;Integrated Security=False;User ID=serverlogin;Password=Alannguys123;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
<customErrors mode="Off" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
</system.webServer>
</configuration>
解决方案
推荐阅读
- android - Android studio - 如何将图像保存到 SECONDARY_STORAGE
- ios - AutoLayout系统设置的NSAutoresizingMaskLayoutConstraint引入的神秘值
- html - 即使添加了元标记,html 表单也没有响应
- c# - 如何配置 Visual Studio Code 以从适用于 Linux 的 Windows 子系统 (WSL) 运行/调试 .NET (dotnet) Core?
- python - Python re.sub() 不会替换每个匹配项
- git - git结帐
或者 - reactjs - TypeError: react__WEBPACK_IMPORTED_MODULE_6___default.a.lazy 不是 react@16.5.2 的函数
- angular - Angular Kendo 是否支持服务器端分页?
- python - Django Wagtail 'expected string or bytes-like object' 错误
- pyspark - pyspark:按内部值的长度过滤行