asp.net WebMethod无法正常工作

时间:2015-04-21 13:01:02

标签: c# asp.net

我有一个简单的网页,里面有一个WebMethod。 但是,即使我尝试了在Google上找到的所有内容,它也无法正常工作。 当我通过浏览器转到http://server/test.aspx/Test时,即使删除了webMethod,它也会返回整个页面。 这是代码:

   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";
           }
       }
   }

这是设计

  <%@ 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>

我也试过添加这个Web.Config条目,但没有用。

 <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>

1 个答案:

答案 0 :(得分:4)

尝试这个

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

并确保其POST不要GET

相关问题