prettify

baseline

Ajax C#

  • Visual Studio 2010/Solution Explorer
  • Solution.Add New Project.Visual C#.Web.ASP_NET Empty Web Application
  • Project.Add New Item.Visual C#.Generic Handler
aj.ashx
  1. <%@ WebHandler Language="C#" Class="Aj" %>
  2. using System;
  3. using System.IO;
  4. using System.Web;
  5. public class Aj : IHttpHandler {
  6.     public void ProcessRequest (HttpContext context) {
  7.         Stream stIn = context.Request.InputStream;
  8.         int nLen = (int)stIn.Length;
  9.         byte[] aIn = new byte[nLen];
  10.         stIn.Read(aIn, 0, nLen);
  11.         System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  12.         string sData = enc.GetString(aIn);

  13.         string[] aData = sData.Split();
  14.         int nA = Convert.ToInt32(aData[2]);
  15.         int nB = Convert.ToInt32(aData[3]);
  16.         int nResult = nA + nB;  
  17.         context.Response.CacheControl = "no-cache";
  18.         context.Response.ContentType = "application/javascript";
  19.         context.Response.Write("["+nResult.ToString()+"]");
  20.     }
  21.      public bool IsReusable {get {return false;}}
  22. }

No comments:

Post a Comment