Query.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Query.aspx.cs" Inherits="Query" %>Query.aspx.cs:
public partial class Query : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int key = 0;
if (HttpContext.Current.Request["key"] != null)
{
key = Convert.ToInt16(HttpContext.Current.Request["key"]);
if (key > 9 && key < 21)
{
HttpContext.Current.Response.Write("1_http://www.mzwu.com/");
return;
}
}
HttpContext.Current.Response.Write("0_Error");
}
}使用一般处理程序(.ashx),我们就可以不必理会html相关内容,将精力放在代码上:
Query.ashx:
<%@ WebHandler Language="C#" Class="Query" %>
using System;
using System.Web;
public class Query : IHttpHandler {
public void ProcessRequest (HttpContext context) {
int key = 0;
if (context.Request["key"] != null)
{
key = Convert.ToInt16(context.Request["key"]);
if (key > 9 && key < 21)
{
context.Response.Write("1_http://www.mzwu.com/");
return;
}
}
context.Response.Write("0_Error");
}
public bool IsReusable {
get {
return false;
}
}
}----------------------------------------------------------------------
说明:运行一般处理程序默认的代码会提示:文档的顶层无效。按下边修改即可:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
[color=Green]//context.Response.ContentType = "text/plain";[/color]
context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}
评论(0)
暂无评论。