Yesudass Moses
Yesudass Moses

Reputation: 1859

asp.net WebMethod not working

I have a simple webpage which has a WebMethod in it. But it's not working even after I tried everything I found on Google. When I go to http://server/test.aspx/Test through browser, It returns entire page even if the webMethod is removed. This is the code:

   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Web;
   using System.Web.UI;
   using System.Web.UI.WebControls;

   namespace IgnisAccess
   {
       public partial class test : System.Web.UI.Page
       {

           protected void Page_Load(object sender, EventArgs e)
           {

           }

           [System.Web.Services.WebMethod]
           public static string Test()
           {
               return "Success";
           }
       }
   }

This is the Design

  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="IgnisAccess.test" %>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
     <head runat="server">
       <title></title>
     </head>
     <body>
        <form id="form1" runat="server">
           <div>
           </div>
        </form>
     </body>
   </html>

I have tried adding this Web.Config entry too, but of no use.

 <system.web>
     <httpModules>
         <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </httpModules>
 </system.web>

Upvotes: 4

Views: 9135

Answers (1)

Ja9ad335h
Ja9ad335h

Reputation: 5075

try this one

[System.Web.Services.WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string Test()
{
    return "Success";
}

and make sure its POST not GET

Upvotes: 5

Related Questions