不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
VS2005一般处理程序(.ashx)示例
编辑:dnawo 日期:2009-05-24
在Web应用程序中,有时需要做个接口,该接口能接收以http get或post方式传递过来的数据,进行适当处理后在页面中输出结果返回给其他应用程序,显然,在页面中不能有html代码,所以我们得手工将全部html代码删除:
Query.aspx:
Query.aspx.cs:
使用一般处理程序(.ashx),我们就可以不必理会html相关内容,将精力放在代码上:
Query.ashx:
----------------------------------------------------------------------
说明:运行一般处理程序默认的代码会提示:文档的顶层无效。按下边修改即可:
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");
}
}
{
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;
}
}
}
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) {
//context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
//context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}






评论: 0 | 引用: 0 | 查看次数: 6221
发表评论
请登录后再发表评论!