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

Bry*_*ger 1 c# asp.net jquery webmethod

必须遗漏一些基本的东西.我在本地运行的aspx页面中从jquery调用web方法时遇到404错误.

<%@ 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>
Run Code Online (Sandbox Code Playgroud)

然后在代码页面后面

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

    }

}
Run Code Online (Sandbox Code Playgroud)

每次运行时我都会收到404错误我尝试将url更改为/empJquery.aspx/Test我也尝试了localhost/empJQuery.aspx/Test和localhost:48784/empJquery.aspx/Test但我似乎无法得到它.我需要在网络配置中添加一些内容吗?我正在运行.net 4.5谢谢

Bry*_*ger 9

好吧,我只是觉得我的应用程序是一种混合MVC,Web API,ASPX解决方案和我的路线CONFIGS被搞乱了我,所以我不得不补充:

 routes.IgnoreRoute("{page}.aspx/{*webmethod}");
Run Code Online (Sandbox Code Playgroud)