Causes and solutions for invalid Ajax. AjaxMethod in IIS7

Source: Internet
Author: User

Recently used Ajax. when the AjaxMethod method is used, everything works normally on the asp.net server. When iis is used, the cs class is always not found in js, so I am depressed and have been tossing for a long time, finally, the error cause is found.

Because I use iis7 to publish a website. <system. webServer>
My problem is that I didn't notice the iis version problem... Miserable drama!

Now I want to write down all the things that need to be paid attention to in the whole method, so that I can look at it later. What I hope will help people who encounter the same mistake to see it and save some valuable time. After all, is life precious, pay less attention and drop a few hairs. Haha...

Find a comprehensive article on the Internet. Don't scold me for plagiarism...

The following requirements must be met when using AjaxMethod:
1. If no ajax. dll file exists, download one first.
2. Add ajax. dll to project reference: Right-click the project name in Solution Explorer of VS, and choose "add project reference"> browse. Find ajax. dll to confirm.
3. add <add verb = "POST, GET" path = "ajax/*. ashx" type = "Ajax. PageHandlerFactory, Ajax"/> to For IIS7. webServer> </system. add <add name = "ajax" verb = "POST, GET" path = "ajax/* To webServer> /*. ashx "type =" Ajax. pageHandlerFactory, Ajax "/>
Add
Copy codeThe Code is as follows:
Protected void Page_Load (objectsender, EventArgse)
{
Ajax. Utility. RegisterTypeForAjax (typeof (ClassName); // ClassName is the class name of this CS File
}

Compile the CS method, and add [Ajax. AjaxMethod ()] before the method.
To enable the AjaxMethod to call the session, write it as [Ajax. AjaxMethod (HttpSessionStateRequirement. Read)],
For example:
Copy codeThe Code is as follows:
[Ajax. AjaxMethod ()]
Public string GetAddress (string UserID)
{
String Address = "";
// Do somthing to get the address here
Return Address;
}

Note that the method should be written as public. Otherwise, the system will prompt "This attribute or method is not supported" when calling in JS"

4. Make sure the page contains the <form runat = "server"> </form> label.

5. Add the class name when calling aspx javascript, for example:
Var address = ClassName. GetAddress ('20140901'). value;

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.