首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

小弟以前学JAVA,现在该C# 急问一个关于用户登陆验证的有关问题

2012-01-11 
小弟以前学JAVA,现在该C# 急问一个关于用户登陆验证的问题.我是用HTML向ASPX中提交一个用户表单~在ASPX上

小弟以前学JAVA,现在该C# 急问一个关于用户登陆验证的问题.
我是用HTML向ASPX中提交一个用户表单~在ASPX上读取并显示出来。
代码如下:
Login.html

<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head>
        <title> Index </title>
</head>
<body>
<form   action= "Login.aspx "   method= "post "   runat= "server ">
        <table   style= "left:   184px;   position:   relative;   top:   32px ">
                <tr>
                        <td   style= "width:   54px;   height:   30px ">
                                用户名 </td>
                        <td   style= "width:   181px;   height:   30px ">
                                <input   id= "txtUserName "     style= "width:   176px;   position:   relative;   height:   32px;   left:   0px;   top:   0px; "   type= "text "   /> </td>
                </tr>
                <tr>
                        <td   style= "width:   54px;   height:   30px ">
                                密&nbsp;   码 </td>
                        <td   style= "width:   181px;   height:   30px ">
                                <input   id= "txtUserPwd "   style= "width:   176px;   position:   relative;   top:   0px;   height:   32px;   left:   0px; "
                                        type= "text "   /> </td>
                </tr>
                <tr>
                        <td   colspan= "2 "   style= "height:   27px ">
                                <input   id= "Reset "   style= "left:   165px;   width:   50px;   position:   relative;   top:   0px;   height:   30px; "
                                        type= "reset "   value= "重置 "   onclick= "return   Reset1_onclick() "   />
                                <input   id= "login "   style= "left:   8px;   position:   relative;   top:   0px;   width:   50px;   height:   30px; "   type= "submit "


                                        value= "登陆 "   onclick= "return   login_onclick() "   /> </td>
                </tr>
        </table>

</form>
   
</body>
</html>

Login.aspx.cs
using   System;
using   System.ComponentModel;
using   System.Data;
using   System.Configuration;
using   System.Collections;
using   System.Drawing;
using   System.Web;
using   System.Web.Security;
using   System.Web.SessionState;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.WebControls.WebParts;
using   System.Web.UI.HtmlControls;

public     partial   class   Login   :   System.Web.UI.Page
        {
                private   void   Page_Load(object   sender,   EventArgs   e)
                {
                        string   userName   =Request[ "txtUserName "];
                        string   userPwd   =Request[ "txtUserPwd "];
                        //string   userName   =   Request.Form.Get( "txtUserName ");
                        //string   userPwd   =   Request.Form.Get( "txtUserPwd ");
                        //userName   =   Request.QueryString.Get( "txtUserName ");
                        //userPwd   =   Request.QueryString.Get( "txtUserPwd ");
                       
                          //userName   =     Request.Form.Get( "txtUserName ");
                        //userPwd   =   Request.Form.Get( "txtUserPwd ");

                if   (userName   ==   null   &&   userPwd   ==   null)
                        {
                              Response.Write( "用户密码为空 ");
                      }
                      else
                        {
                              Response.Write(userName);
                              Response.Write(userPwd);
                      }      


              }
}
结果输出的是:用户密码为空.
我不请是不是HTML的数据没提交过来,还是没接收到
用了很多方法就像注释里面的一样~
小弟没多少分,希望哪位能指点小弟一下
万分感激~!!



[解决办法]
很少用这种方式了,记得以前asp时经常用。

应该是你要指定html表单的name,而不只是指定id这个原因吧
[解决办法]

string userName =Request.Params[ "txtUserName "].ToString();
string userPwd =Request.Params[ "txtUserPwd "].ToString();

热点排行