Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <%@ WebHandler Language="C#" Class="SystemAreaCodeOP" %>
  2.  
  3. using System.Web;
  4.  
  5. public class SystemAreaCodeOP : IHttpHandler {
  6.  
  7. public void ProcessRequest (HttpContext context)
  8. {
  9. AllowHttpMethod(context.Request.HttpMethod,"POST");
  10.  
  11. string CountyTownData = "[]";
  12.  
  13. string AreaCode = context.Request.Form["a"] ?? "";
  14. int p = 0;
  15. int.TryParse(context.Request.Form["p"], out p);
  16.  
  17. if (AreaCode == "County")
  18. {
  19. CountyTownData = Newtonsoft.Json.JsonConvert.SerializeObject(SystemAreaCode.GetCountyList());
  20. }
  21. else if (AreaCode == "Town")
  22. {
  23. if (p > 0) CountyTownData = Newtonsoft.Json.JsonConvert.SerializeObject(SystemAreaCode.GetTownList(p));
  24.  
  25. }
  26. else if (AreaCode == "Village")
  27. {
  28. if (p > 0) CountyTownData = Newtonsoft.Json.JsonConvert.SerializeObject(SystemAreaCode.GetVillageList(p));
  29. }
  30.  
  31. context.Response.ContentType = "application/json; charset=utf-8";
  32. context.Response.Write(CountyTownData);
  33. context.Response.End();
  34.  
  35.  
  36.  
  37. }
  38.  
  39. public bool IsReusable {
  40. get {
  41. return false;
  42. }
  43. }
  44.  
  45. protected void AllowHttpMethod(string myMethod,params string[] methods)
  46. {
  47. bool HasPower = false;
  48.  
  49. System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(methods);
  50.  
  51. for (int i = 0; i <= methods.Length - 1; i++)
  52. {
  53. if (methods[i].Trim().ToUpper().Equals(myMethod))
  54. {
  55. HasPower = true;
  56. break;
  57. }
  58. }
  59.  
  60.  
  61. if (HasPower == false)
  62. {
  63. throw new HttpException(404, "Not found");
  64. //Response.Redirect("~/html/ErrorPage/NoPower.html");
  65. //string myScript = "<script>alert('您無權操作此頁面');history.go(-1);</script>";
  66. //Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "DisableTop", myScript, false);
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement