<%@ WebHandler Language="C#" Class="Handler" %>
|
|
using System;
|
using System.Web;
|
using System.IO;
|
|
public class Handler : IHttpHandler {
|
|
public void ProcessRequest (HttpContext context)
|
{
|
string action = HttpContext.Current.Request["action"];
|
if (action == "GetData")
|
{
|
GetData(context);
|
}
|
else if (action == "SaveData")
|
{
|
SaveData(context);
|
}
|
else if (action == "SaveLayerData")
|
{
|
SaveLayerData(context);
|
}
|
}
|
|
private void GetData(HttpContext context)
|
{
|
string strJson = "";
|
string name = context.Request["Name"];
|
string age = context.Request["Age"];
|
strJson = "姓名:" + name + ",年龄:" + age;
|
context.Response.Charset = "UTF-8";
|
context.Response.Write(strJson);
|
context.Response.End();
|
}
|
|
private void SaveData(HttpContext context)
|
{
|
string name = HttpContext.Current.Server.UrlDecode(context.Request["Name"]);
|
string txtPath = HttpContext.Current.Server.MapPath("./") + "bookmarks.json"; //MapPath("./")表示当前目录
|
StreamWriter sw = new StreamWriter(txtPath, false, System.Text.Encoding.UTF8);
|
sw.WriteLine(name);
|
sw.Close();
|
}
|
|
private void SaveLayerData(HttpContext context)
|
{
|
string name = HttpContext.Current.Server.UrlDecode(context.Request["Name"]);
|
string txtPath = HttpContext.Current.Server.MapPath("./") + "plotLayer.json";
|
StreamWriter sw = new StreamWriter(txtPath, false, System.Text.Encoding.UTF8);
|
sw.WriteLine(name);
|
sw.Close();
|
}
|
|
public bool IsReusable {
|
get {
|
return false;
|
}
|
}
|
|
}
|