从 jquery C# 调用 webmethod 在 .net aspx 页面中返回 404 错误

calling webmethod from jquery C# returning 404 error in .net aspx page

这里一定是遗漏了一些基本的东西。我在 aspx 页面中从 jquery 调用 webmethod 时收到 404 错误,我在本地 运行ning。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="empJquery.aspx.cs" Inherits="webApiOracle.empJquery" %>

<!DOCTYPE html>

<html lang="en">
<head runat="server">
    <title>jquery emps</title>
    <script src="Scripts/jquery-1.10.2.min.js"></script>
    <link href="../Content/bootstrap.min.css" rel="stylesheet" />
    <script type="text/javascript">


        $(document).ready(function () {
            getEmployees();

        });

        function getEmployees() {
            jQuery.ajax({
                url: 'empJquery.aspx/Test',
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () {
                    alert("Start!!! ");
                },
                success: function (data) {
                    alert("a");
                },
                error: function (msg) { alert("Sorry!!! "); }

            });
        }

    </script>

然后在页面后面的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using webApiOracle.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;


namespace webApiOracle
{
    public partial class empJquery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [System.Web.Services.WebMethod]
        public static string Test()
        {

            return "Success";
        }

    }

}

每当我 运行 我尝试将 url 更改为 /empJquery。aspx/Test 我也尝试过 localhost/empJQuery。aspx/Test和 localhost:48784/empJquery.aspx/Test 但我似乎无法理解。我需要在我的网络配置中添加一些东西吗?我正在 运行ning .net 4.5 谢谢

好的,我刚发现我的应用程序是混合 MVCWeb APIASPX 解决方案,我的路由配置让我一团糟所以我不得不添加:

 routes.IgnoreRoute("{page}.aspx/{*webmethod}");