类型转换问题费了我半天光阴,汗.......

    今天做用户登录页面ilogon.aspx可真是让我吃尽苦头,花了整整八个小时,单步,测试等各种方法用尽了最后才总算告一段落,究其原因竟然是类型转换问题,冒汗不已 21.gif。可能是由于实践经验不足导致,想起以前看书都是觉得想类型转换等属于小问题而不曾放在心上,一直也未曾接触什么项目开发经验,这次算是让我认识到什么叫"不可小觑"了,特写此文以示警戒自己。
    登录页面是通过<iframe src='ilogon.aspx'></iframe>,验证通过后将直接进入ilogin.aspx,使用Session保存用户状态,以下为正确登录代码:
 1 None.gif          private   void  btnSubmit_Click( object  sender, System.EventArgs e)
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {    
 3InBlock.gif            if((Page.IsValid&&Session["ValidateCode"]!=null)&&txtValidatecode.Text.Trim().ToString()==Session["ValidateCode"].ToString())
 4ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 5InBlock.gif                //取出临时购物车CartID
 6InBlock.gif                EasybuyExcuData tempcart=new EasybuyExcuData();
 7InBlock.gif                String tempcartid=tempcart.GetCartID();
 8InBlock.gif                
 9InBlock.gif                //取出用户名内容
10InBlock.gif                string username=txtName.Text.Trim().ToString();
11InBlock.gif                //取出密码内容
12InBlock.gif                string pwd=txtPwd.Text.Trim().ToString();
13InBlock.gif               // EasybuyExcuData edata=new EasybuyExcuData();
14InBlock.gif                int userid=tempcart.UserLogin(username,pwd);
15InBlock.gif                
16InBlock.gif                if(userid!=0)
17ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
18InBlock.gif                    Session["userid"]=userid;
19InBlock.gif                    SqlConnection con=new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
20InBlock.gif                    SqlCommand com=new SqlCommand("select count(*) from ShoppingCart where CartID= @userid",con);
21InBlock.gif                    com.Parameters.Add("@userid",SqlDbType.NVarChar,50).Value =userid.ToString();
22InBlock.gif                    
23InBlock.gif                    con.Open();
24InBlock.gif                    int count=(Int32)com.ExecuteScalar();
25InBlock.gif                    con.Close();
26InBlock.gif                    if(count>0)
27ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
28InBlock.gif                        tempcart.TransplantShoppingCart(tempcartid.ToString(),userid.ToString());
29ExpandedSubBlockEnd.gif                    }

30InBlock.gif                    //Response.Redirect("ilogin.aspx");
31InBlock.gif                    Response.Redirect("testiframe.htm");
32ExpandedSubBlockEnd.gif                }

33InBlock.gif                else
34ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
35InBlock.gif                    lbMessage.Text="登录失败!请确认用户名或密码无误!";
36InBlock.gif                    //lbMessage
37InBlock.gif                    //Response.Redirect("Ilogonpage.aspx");response.redirect("welcome.aspx")
38ExpandedSubBlockEnd.gif                }

39InBlock.gif                    
40ExpandedSubBlockEnd.gif            }

41InBlock.gif            else
42ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
43InBlock.gif                lbMessage.Text="验证码不匹配,请检查后重新输入!";
44InBlock.gif                lbMessage.Visible=true;        
45InBlock.gif
46ExpandedSubBlockEnd.gif            }

47InBlock.gif            
48ExpandedBlockEnd.gif        }
     

转载于:https://www.cnblogs.com/feiren1421/archive/2006/03/27/360308.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值