defaulthandler.ashx.cs

来自「帮助你了解AJAX的核心」· CS 代码 · 共 49 行

CS
49
字号
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Xml;

namespace Linkedu.Web.WebWWW
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    public class DefaultHandler : IHttpHandler
    {
        protected XmlDocument _xmlResult;

        public void ProcessRequest(HttpContext context)
        {
            if (context.Request["T"] != null)
            {//GET xmlhttp测试
                context.Response.ContentType = "text/xml";
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(string.Format(@"<time>GET:{0}</time>", System.DateTime.Now));
                xmlDoc.Save(context.Response.OutputStream);
                context.Response.End();
            }
            else
            {//POST xmlhttp测试
                context.Response.ContentType = "text/xml";
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(context.Request.InputStream);
                if (xmlDoc.DocumentElement.Name == "T")
                {
                    xmlDoc.LoadXml(string.Format(@"<time>POST:{0}</time>", System.DateTime.Now));
                    xmlDoc.Save(context.Response.OutputStream);
                    context.Response.End();
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?