从调用jQuery的C#的WebMethod返回的.NET aspx页面404错误 [英] calling webmethod from jquery C# returning 404 error in .net aspx page

查看:225
本文介绍了从调用jQuery的C#的WebMethod返回的.NET aspx页面404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须在这里失去了一些东西基本。我得到一个404错误调用从jQuery的一个WebMethod在我本地运行一个aspx页面。

must be missing something basic here. I am getting a 404 error calling a webmethod from jquery in an aspx page I'm running locally.

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

然后在页面背后的code

then in the code behind page

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

    }

}

我得到一个404错误,每当我跑我试图改变URL来/empJquery.aspx/Test我也试过本地主机/ empJQuery.aspx /测试和本地主机:48784 / empJquery.aspx /测试,但我似乎无法为拿到它,为实现它。我需要的东西添加到我的web配置?我运行.NET 4.5
谢谢

I'm getting a 404 error whenever I run I attempted changing url to /empJquery.aspx/Test I also tried localhost/empJQuery.aspx/Test and localhost:48784/empJquery.aspx/Test but I can't seem to get it. Do I need to add something to my web config? I'm running .net 4.5 thanks

推荐答案

好,我只是觉得我的应用程序是一个混合的MVC,网络API,ASPX解决方案,我的路线CONFIGS被搞乱了我,所以我不得不添加routes.IgnoreRoute ({PAGE}的.aspx / {*}的WebMethod);

ok I just found it my app is a hybrid mvc, web api, aspx solution and my route configs were messing me up so I had to add routes.IgnoreRoute("{page}.aspx/{*webmethod}");

这篇关于从调用jQuery的C#的WebMethod返回的.NET aspx页面404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆