ASP.NET AJAX PageMethods call load whole page for .NET 4.5 IIS 7.5
Asked Answered
I

3

5

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

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 the issue is realted to in built extensionless 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 through Jquery ajax call and got whole page. Am i missing any thing?

Ichinomiya answered 12/2, 2014 at 6:29 Comment(2)
can any one please share correct sys.webserver configuration for AJAX page method or jquery ajax call approaches, considering the default extensionless entries in IIS7+. I am using .NET 4.5.1. thanks.Ichinomiya
So did you ever figure this out?Nancinancie
I
4

Friendly URLs (the extensionless URL library that's part of the default project template) doesn't support invocation of [WebMethod] routines. If you must use [WebMethod], uninstall Friendly URLs from the project. This can be done from the Nuget Package Manager window.

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

Isomer answered 12/2, 2014 at 17:6 Comment(0)
P
4

If you are using friendly urls, then add

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

to your js

Good luck!

Purvey answered 8/8, 2014 at 18:31 Comment(0)
E
0

yes, it seems to be web.config setting.

try removing this line from <modules> section <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>
Expose answered 12/2, 2014 at 7:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.