1.请求-处理-响应
新建一般处理程序:handler;
浏览方式-设为默认值;
请求:http://localhost:18367/Handler1.ashx;
处理响应,向浏览器画出html:
context.Response.ContentType = "text/html";
context.Response.Write("<h1>Hello World</h1>");
2.vs2012默认使用iisweb服务器,vs2010是用vsweb开发服务器;基于安全考虑,iis默认不允许浏览目录,直接访问ashx文件名就可以,iis一般在c:\ProgramFiles\IIS Express;
项目-右键属性-web-修改服务器;
3.一般处理程序的请求参数:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
String action = context.Request["name"];
int age =Convert.ToInt32(context.Request["age"]);
context.Response.Write("<h1>Hello World--" + action + "</h1>");
context.Response.Write("<h1>caonimei--"+age+"</h1>");
}
http://localhost:1108/Handler1.ashx?name=lyc&age=45
4.表单提交:
添加新建项--html文件
<body>
<form action="Handler1.ashx" method="get">
姓名:<input type="text" name="name"/><br />
年龄:<input type="text" name="age"/><br />
<input type="checkbox" name="isvip"/>
<input type="submit"/>
</form>
</body>
----------
context.Response.ContentType = "text/html";
String name = context.Request["name"];
int age =Convert.ToInt32(context.Request["age"]);
String isvip=context.Request["isvip"];
context.Response.Write("<h1>Hello World--" + name + "</h1>");
context.Response.Write("<h1>caonimei--"+age+"</h1>");
if (isvip=="on")
{
context.Response.Write("<h1>你是vip</h1>");
}
else
{
context.Response.Write("<h1>你是傻逼</h1>");
}
//name是可以重复 的;
action="Handler1.ashx" //提交给Handler1.ashx处理
//只有input\textarea\select的value属性值才会提交给服务器;标签必须设定name属性;name是给服务器用的,id是dom用的;
5.get和post
get把数据填到url地址栏上提交;
post传递表单是隐藏到http报文中的。
get传递的数据量有限,post没有限制;
post无法通过url在其他用户中还原;
get方式:如果url中有特殊汉字符号等则需要对url进行编码;
6.http协议:浏览器和服务器交流协议
http不保持连接,不保持连接可以处理更多的请求;
请求头;
响应头;
context.Response.ContentType = "text/html";//表示返回html;
context.Response.ContentType = "text/plain";//表示返回文本;
7.redirect重定向
是向浏览器发回302重定向,是通知浏览器重新访问url这个网址;在地址栏中可以看到地址的变化;
context.Response.Redirect("HtmlPage1.html");
8.
新建一般处理程序:handler;
浏览方式-设为默认值;
请求:http://localhost:18367/Handler1.ashx;
处理响应,向浏览器画出html:
context.Response.ContentType = "text/html";
context.Response.Write("<h1>Hello World</h1>");
2.vs2012默认使用iisweb服务器,vs2010是用vsweb开发服务器;基于安全考虑,iis默认不允许浏览目录,直接访问ashx文件名就可以,iis一般在c:\ProgramFiles\IIS Express;
项目-右键属性-web-修改服务器;
3.一般处理程序的请求参数:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
String action = context.Request["name"];
int age =Convert.ToInt32(context.Request["age"]);
context.Response.Write("<h1>Hello World--" + action + "</h1>");
context.Response.Write("<h1>caonimei--"+age+"</h1>");
}
http://localhost:1108/Handler1.ashx?name=lyc&age=45
4.表单提交:
添加新建项--html文件
<body>
<form action="Handler1.ashx" method="get">
姓名:<input type="text" name="name"/><br />
年龄:<input type="text" name="age"/><br />
<input type="checkbox" name="isvip"/>
<input type="submit"/>
</form>
</body>
----------
context.Response.ContentType = "text/html";
String name = context.Request["name"];
int age =Convert.ToInt32(context.Request["age"]);
String isvip=context.Request["isvip"];
context.Response.Write("<h1>Hello World--" + name + "</h1>");
context.Response.Write("<h1>caonimei--"+age+"</h1>");
if (isvip=="on")
{
context.Response.Write("<h1>你是vip</h1>");
}
else
{
context.Response.Write("<h1>你是傻逼</h1>");
}
//name是可以重复 的;
action="Handler1.ashx" //提交给Handler1.ashx处理
//只有input\textarea\select的value属性值才会提交给服务器;标签必须设定name属性;name是给服务器用的,id是dom用的;
5.get和post
get把数据填到url地址栏上提交;
post传递表单是隐藏到http报文中的。
get传递的数据量有限,post没有限制;
post无法通过url在其他用户中还原;
get方式:如果url中有特殊汉字符号等则需要对url进行编码;
6.http协议:浏览器和服务器交流协议
http不保持连接,不保持连接可以处理更多的请求;
请求头;
响应头;
context.Response.ContentType = "text/html";//表示返回html;
context.Response.ContentType = "text/plain";//表示返回文本;
7.redirect重定向
是向浏览器发回302重定向,是通知浏览器重新访问url这个网址;在地址栏中可以看到地址的变化;
context.Response.Redirect("HtmlPage1.html");
8.