Response和Request

login.htm

< form  method ="post"  action ="login.aspx" >
  //  method有两种方法是post和get,post对应于Request.Form,  get对应于Request.Querty.string
  // 用post 时URL不会加长,但用get 时URL会加长,所有传递参数以&&的形式显示在URL中
  //  由于起特性,在新闻系统中将用到 get

    
< table  style ="width: 318px" >
        
< tr >
            
< td  style ="width: 107px; height: 52px" >
            
</ td >
            
< td  style ="width: 291px; height: 52px" >
                
< input  id ="textUserName"  name ="textUserName"  type ="text"   /></ td >
            
< td  style ="width: 96px; height: 52px" >
            
</ td >
        
</ tr >
        
< tr >
            
< td  style ="width: 107px; height: 70px" >
            
</ td >
            
< td  style ="width: 291px; height: 70px" >
                
< input  id ="textUserPwd"  name ="textUserPwd"  type ="text"   /></ td >
            
< td  style ="width: 96px; height: 70px" >
            
</ td >
        
</ tr >
        
< tr >
            
< td  style ="width: 107px; height: 67px" >
            
</ td >
            
< td  style ="width: 291px; height: 67px; text-align: center" >
                
< input  id ="btnSubmit"  type ="submit"  value ="提交"    /></ td >
            
< td  style ="width: 96px; height: 67px" >
            
</ td >
        
</ tr >
    
</ table >


</ form >

 login.aspx.cs

 

using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

public   partial   class  Default2 : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
//string userName = Request["textUserName"].ToString();
        
//string userPwd = Request["textUserPwd"].ToString();
        string userName = Request.Form.Get("textUserName").ToString();
        
string userPwd = Request.Form.Get("textUserPwd").ToString();
        
//以上两种方法适用于 method=post,任意一种均可



        
string userName = Request.QueryString["textUserName"].ToString();
        
string userPwd = Request.QueryString["textUserPwd"].ToString();
        
// 以上方法适用于 mrthod=get



        Response.Write(
"登录的用户名是:"+userName+";密码是"+userPwd);
        
// 用于输出结果



        
if (userName == "zuo" && userPwd == "zuo")
        
{
            Response.Redirect(
"login2.aspx");
        }

        
else
        
{
            Response.Redirect(
"login.htm");
        }

        
// 以上方法用于验证用户名和密码,然后重新定位
    }

}

几点注意:

1. 在aspx文件中,Form只能出现一次,且无action属性,默认为其本身,但htm必须有action属性

     <form id="form1" method="post" runat="server"></form>

2.  post---Request.Form       get---Request..QueryString

3. Response的两个属性 Write 和 Redirect

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值