我有一个简单的网页,其中有一个 WebMethod。但即使我尝试了在谷歌上找到的所有内容后,它仍然不起作用。当我通过浏览器访问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";
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是设计
<%@ 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>
Run Code Online (Sandbox Code Playgroud)
我也尝试添加此 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>
Run Code Online (Sandbox Code Playgroud)
试试这个
[System.Web.Services.WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string Test()
{
return "Success";
}
Run Code Online (Sandbox Code Playgroud)
并确保其 POST 而不是 GET
| 归档时间: |
|
| 查看次数: |
8696 次 |
| 最近记录: |