Asp.net学习笔记1
时间:2011-06-04 来源:LinKang
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 </head>
6 <body>
7 <form action="Handler2.ashx" method="post">
8 <input type="hidden" name="ispostback" value="true" />
9 用户名:<input type="text" name="UserName"/>
10 <input type="submit" value="提交"/>
11 你好请登陆
12 </form>
13 </body>
14 </html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ASP.NET学习
{
/// <summary>
/// Handler2 的摘要说明
/// </summary>
public class Handler2 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//读取html代码
string fullPath = context.Server.MapPath("HTMLPage2.htm");
context.Response.Write(fullPath);
string content=System.IO.File.ReadAllText(fullPath);
context.Response.Write(content);
//判断直接进入还是提交进入 方法一 根据用户名是否为空判断
/* string userName = context.Request["UserName"];//可看作textBox的value
if(string.IsNullOrEmpty(userName))
{
context.Response.Write("直接进入");
}
else
{
context.Response.Write("提交进入");
}*/
//方法二
string userName=context.Request["UserName"];
string msg = "";
string ispostback = context.Request["ispostback"];
if (ispostback=="true")
{
context.Response.Write("提交进入");
msg = "尊敬的会员" + userName + "欢迎回来";
}
else
{
context.Response.Write("直接进入");
userName = "";
msg = "";
}
content = content.Replace("你好请登陆",msg);
context.Response.Write(content);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
相关阅读 更多 +










