Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Collections;
- using System.Net;
- using System.Text;
- using WebDashboardLibrary;
- namespace Web.api
- {
- public class APIRequest : IHttpHandler
- {
- public void ProcessRequest(HttpContext context)
- {
- HttpRequest request = context.Request;
- HttpResponse response = context.Response;
- if (api.APIUtils.HandleCORSPreflight(request, response))
- {
- return;
- }
- if (api.APIUtils.CheckAuthentication(request, response))
- {
- Hashtable responseData = CreateResponseData(request, response);
- string jsonStr = JSON.Encode(responseData);
- string jsonpCallback = null;
- if (!string.IsNullOrEmpty(request.QueryString["jsonp"]))
- {
- jsonpCallback = request.QueryString["jsonp"];
- }
- if (jsonpCallback != null) // JSONP response
- {
- response.ContentType = "text/javascript";
- string jsonPStr = jsonpCallback + "(" + jsonStr + ");";
- response.Write(jsonPStr);
- }
- else // Normal JSON response
- {
- response.ContentType = "application/json";
- response.Write(jsonStr);
- }
- }
- else
- {
- response.StatusCode = (int)HttpStatusCode.Unauthorized;
- }
- }
- public virtual Hashtable CreateResponseData(HttpRequest request, HttpResponse response)
- {
- Hashtable responseData = new Hashtable();
- return responseData;
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement