Common ashx calls

Source: Internet
Author: User

Directly Add code

There is still a certain degree of versatility

<% @ WebHandler Language = "C #" Class = "MyService" %> using System; using System. web; using System. collections. generic; // <summary> // test access path: http: // localhost: 2484/TestAjaxFrameWork/MyService. ashx? C = class1 & m = hello & parm1 = 23 & parm2 = 33 & parm3 = 4 // </summary> public class MyService: IHttpHandler {public void ProcessRequest (HttpContext context) {AjaxHelper ajax = new AjaxHelper (context. request. queryString ["c"], context. request. queryString ["m"]); List <string> objlist = new List <string> (); foreach (string item in context. request. queryString. keys) {if (item! = "C" & item! = "M") {objlist. add (context. request. queryString [item]) ;}} object [] parms = objlist. toArray (); ajax. processRequest (context, parms);} public bool IsReusable {get {return false ;}}}

  

 

Using System; using System. collections. generic; using System. linq; using System. text; using System. reflection; using System. collections; using System. web. compilation; using System. web; /// <summary> /// AjaxHelper abstract description /// </summary> public class AjaxHelper {// <summary> /// name of the class to be accessed // /</summary> public string ClassName {get; set ;}//< summary> /// method to be accessed /// </summary> public string MethodName {get; se T;} // <summary> // name of the constructor initialization class, method /// </summary> /// <param name = "className"> </param> /// <param name = "methodName"> </param> public AjaxHelper (string className, string methodName) {this. className = className; this. methodName = methodName;} public void ProcessRequest (HttpContext context, object [] parms) {// The Method Name of the class name cannot be blank. if (string. isNullOrEmpty (this. className) | string. isNullOrEmpty (this. methodNa Me) {Report404Error (context); return;} // obtain the current Assembly. This limits that the called ajax class must be an Assembly with the current class. Assembly curAssembly = Assembly. getExecutingAssembly (); // get the common class var ts = from t in curAssembly that contains ajax class features. getExportedTypes () let a = (AjaxClassAttribute []) t. getCustomAttributes (typeof (ajaxclassattrites), false) where. length> 0 select t; // obtain the Type of the current access type = ts. firstOrDefault (t => string. compare (this. className, t. Name, true) = 0); // method for obtaining the current access MethodInfo method = type. getMethod (this. methodName, BindingFlags. static | BindingFlags. instance | BindingFlags. public | BindingFlags. ignoreCase); // checks whether ajax method features are included. AjaxMethodAttribute [] attrs = (AjaxMethodAttribute []) method. getCustomAttributes (typeof (ajaxmethodattrites), false); if (attrs. length! = 1) {Report404Error (context);} // call the method. invoke (Activator. createInstance (type), parms);} private void Report404Error (HttpContext context) {throw new HttpException (404, "the service class that can process requests is not found. Current request address:" + context. request. rawUrl) ;}//< summary> // custom feature, indicating ajax class /// </summary> public class AjaxClassAttribute: attribute {}/// <summary> // custom feature, indicating the ajax method. // </summary> public class AjaxMethodAttribute: Attribute {}

  

Using System; using System. collections. generic; using System. linq; using System. web; [AjaxClass] /// <summary> // summary of Class1 /// </summary> public class Class1 {public Class1 () {/// TODO: add the constructor logic here //} [AjaxMethod] public void hello (string parm1, string parm2, string parm3) {HttpContext. current. response. write ("test context," + parm1 + "," + parm2 + "," + parm3 + ",");}}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.