ASP.NET AJAX PageMethods Causes Full Page Load for .NET 4.5 IIS 7.5

I call pageMethod in the codebehind of an aspx page. I get the answer for the whole page instead of the webMethod answer. Also, I tried calling the same webMethod using jquery and got the whole page as an answer.

Client: <asp:ScriptManager ID="scriptManager1" runat="server" EnablePartialRendering="True" EnablePageMethods="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" > function TestNumber() { PageMethods.getNumber(ResponseTest); } function ResponseTest(response){ var num = response.d; } CodeBehind: [WebMethod] public static int getNumber() { return accountNumber; } 

I am using .NET 4.5.1 and IIS7.5, and I think that the problem is solved in embedded without extension URLS in VS2013. I am using the following web.config sys.webserver

  <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true"> <remove name="ScriptModule" /> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </modules> <handlers> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <remove name="OPTIONSVerbHandler" /> <remove name="TRACEVerbHandler" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> </system.webServer> 

I tried the same thing through jQuery ajax call and got the whole page. Did I miss something?

+4
jquery ajax pagemethods
source share
3 answers

If you use friendly URLs, add

 PageMethods.set_path(PageMethods.get_path() + '.aspx'); 

in js

Good luck

+4
source share

Friendly URLs (the URL library without an extension, which is part of the default project template) do not support calling routines [WebMethod]. If you must use [WebMethod], remove friendly URLs from the project. This can be done from the Nuget Package Manager window.

After removing this package, you may need to fix the links in your project and in the Web.config file to add the missing .aspx extensions.

+3
source share

yes, this is similar to setting up web.config.

try removing this line from the <modules> <remove name="ScriptModule" />

just add

 <system.webServer> <modules> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </modules> </system.webServer> 
0
source share

All Articles