The reason of Ajax.ajaxmethod invalidation in IIS7 and its solving method

Source: Internet
Author: User
Tags iis
Using the Ajax.ajaxmethod method in the asp.net of the server under all normal, with IIS, JS is always the CS class can not find, the specific solution is as follows, encounter similar situation friend may refer to the following  

Recently done with the Ajax.ajaxmethod method, in the asp.net of the server under all normal, with IIS, JS is always CS class can not find, I was depressed, tossing the majority of days, finally found the cause of the error.

Because I am publishing the site is IIS7, so in Web.config location file <system.webServer>
My problem is due to the failure to notice the IIS version of the problem, resulting in ... The drama is sad!

Now the whole method to pay attention to all write down, but also convenient to see later, the hope of the encounter can let people encounter the same error to see, save a little precious time, after all, life is valuable, little God, less a few hair, haha ...

Directly on the Internet to find a comprehensive, don't scold me plagiarism ...

Use Ajaxmethod to satisfy a few points:
1, if there is no Ajax.dll file, first download a to
2. Add Ajax.dll to project references: Right-click the project name-"Add Project Reference" in the VS Solution Explorer-Browse, find Ajax.dll OK
3, Webcofig If it is IIS7, you need to add <add name= "ajax" verb= "Post,get path=" ajax/* in <system.webServer></system.webServer>. Ashx "Type=" ajax.pagehandlerfactory, Ajax "/>
In the CS program, add

Copy Code code as follows:


protected void Page_Load (OBJECTSENDER,EVENTARGSE)


{


Ajax.Utility.RegisterTypeForAjax (typeof (ClassName));//classname is the class name of this CS file


}


Write CS method preceded by [Ajax.ajaxmethod ()],
If you want to make the Ajaxmethod inside can call session, write: [Ajax.ajaxmethod (Httpsessionstaterequirement.read)],
Such as:

Copy Code code 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 public, otherwise the call in JS will be prompted "Do not support this property or method"

4, to ensure that the page has <form runat= "server" ></form> label.

5, aspx in JavaScript when called with the class name, such as:
var address = classname.getaddress (' 123 '). Value;

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.