超级菜鸟:怎么用C#在Asp.Net下面做登陆和注册? http://www.chinabs.net/aspnet/default.asp?infoid=40 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用服务端验证方式做个asp:Button,写click事件,取得你的用户,密码,构造sql语句验证错的话出个提示,对的话,转到登录后的页面 //可以用用看public String Login(string workId,string password) { SqlConnection myConnection = new SqlConnection (ConfigurationSettings.AppSettings["ConnectionString"]) ; SqlCommand myCommand = new SqlCommand ("Aspx_UserLogin",myConnection) ; myCommand.CommandType = CommandType.StoredProcedure ; //Add WorkId ; SqlParameter paramWorkId = new SqlParameter ("@WorkId",SqlDbType.NVarChar,10) ; paramWorkId.Value = workId ; myCommand.Parameters.Add(paramWorkId) ; //Add Password ; SqlParameter paramPassword = new SqlParameter ("@Password",SqlDbType.NVarChar,10) ; paramPassword.Value = password ; myCommand.Parameters.Add(paramPassword) ; //Add UserId ; SqlParameter paramUserId = new SqlParameter ("@UserId",SqlDbType.Int,4) ; paramUserId.Direction = ParameterDirection.Output ; myCommand.Parameters.Add(paramUserId) ; //Open the Connection and Execute the Command ; myConnection.Open() ; myCommand.ExecuteNonQuery() ; myConnection.Close() ; int UserId = (int) (paramUserId.Value) ; if (UserId == 0) return null ; else return UserId.ToString() ; }//==============================void Page_Load(Object sender,EventArgs e) { if(Request.Form["workId"]!= null) { Air.UserDB UserSystem = new Air.UserDB() ; string UserId = UserSystem.Login(Request.Form["workId"],Request.Form["password"]) ; if (UserId == null) { string scriptStr = "<script>alert('用户名或者密码有错误,请重新登陆!')<" ; scriptStr += "/" ; scriptStr += "script>" ; Response.Write(scriptStr) ; } else { Air.UserDetails userDetails = UserSystem.GetUserDetails(UserId) ; Response.Redirect("Main.aspx"); } } } 怎么获得服务器的域名 存储过程有问题?? 本人菜鸟,传参 如何用编程的方法将excel中的数据导入到sql Server2000 中? 我想使用HyperLink控件,但是我不希望显示它的下划线,请问该如何操作!谢谢 字符串用正则表达式替换问题 关于存储过程返回值的问题。急 asp.net连接oracle 无法解析指定的连接标识符 关于datagrid的页面跳转问题 怎么样在sql server里实现全文检索?我碰到了一些问题,欢迎大家都来讨论啊! 很多高手都没有解决的一个 小小 问题!求教! 分页与排序冲突吗?
做个asp:Button,写click事件,取得你的用户,密码,构造sql语句验证
错的话出个提示,对的话,转到登录后的页面
{
SqlConnection myConnection = new SqlConnection (ConfigurationSettings.AppSettings["ConnectionString"]) ;
SqlCommand myCommand = new SqlCommand ("Aspx_UserLogin",myConnection) ;
myCommand.CommandType = CommandType.StoredProcedure ;
//Add WorkId ;
SqlParameter paramWorkId = new SqlParameter ("@WorkId",SqlDbType.NVarChar,10) ;
paramWorkId.Value = workId ;
myCommand.Parameters.Add(paramWorkId) ;
//Add Password ;
SqlParameter paramPassword = new SqlParameter ("@Password",SqlDbType.NVarChar,10) ;
paramPassword.Value = password ;
myCommand.Parameters.Add(paramPassword) ;
//Add UserId ;
SqlParameter paramUserId = new SqlParameter ("@UserId",SqlDbType.Int,4) ;
paramUserId.Direction = ParameterDirection.Output ;
myCommand.Parameters.Add(paramUserId) ;
//Open the Connection and Execute the Command ;
myConnection.Open() ;
myCommand.ExecuteNonQuery() ;
myConnection.Close() ;
int UserId = (int) (paramUserId.Value) ;
if (UserId == 0)
return null ;
else
return UserId.ToString() ;
}
//==============================
void Page_Load(Object sender,EventArgs e)
{
if(Request.Form["workId"]!= null)
{
Air.UserDB UserSystem = new Air.UserDB() ;
string UserId = UserSystem.Login(Request.Form["workId"],Request.Form["password"]) ;
if (UserId == null)
{
string scriptStr = "<script>alert('用户名或者密码有错误,请重新登陆!')<" ;
scriptStr += "/" ;
scriptStr += "script>" ;
Response.Write(scriptStr) ;
}
else
{
Air.UserDetails userDetails = UserSystem.GetUserDetails(UserId) ;
Response.Redirect("Main.aspx");
}
}
}