简体   繁体   English

asp.net WebMethod无法正常工作

[英]asp.net WebMethod not working

I have a simple webpage which has a WebMethod in it. 我有一个简单的网页,其中包含WebMethod。 But it's not working even after I tried everything I found on Google. 但是,即使我尝试了在Google上找到的所有内容后,它也无法正常工作。 When I go to http://server/test.aspx/Test through browser, It returns entire page even if the webMethod is removed. 通过浏览器访问http://server/test.aspx/Test时 ,即使删除了webMethod,它也会返回整个页面。 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. 我也尝试添加此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>

try this one 试试这个

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

and make sure its POST not GET 并确保其POST不获取

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM