简体   繁体   English

asp.net mvc-当应用程序发布到IIS时,控制器操作将返回404

[英]asp.net mvc - When application published to IIS the controller action returns 404

I have an application that was debuging and running locally just fine. 我有一个正在调试并在本地运行的应用程序。 When I published it to IIS, the action on the controller is no longer found. 当我将其发布到IIS时,不再在控制器上找到操作。

It returns http://server/home/Table2?ids=122026000&ids=123201000&ids=122627000&ids=121514000&ids=123187000 404 (Not Found) 它返回http://server/home/Table2?ids=122026000&ids=123201000&ids=122627000&ids=121514000&ids=123187000 404 (Not Found)

I am using a JQuery AJAX function to pass IDS to the action that then returns a partial view with the model constructed from the IDS appropriately. 我正在使用JQuery AJAX函数将IDS传递给操作,然后该操作返回具有从IDS适当构造的模型的局部视图。

Controller 调节器

public class HomeController : Controller
{
    [HttpGet]
    public ActionResult Table2(string[] ids)
    {

        (......) //query database and build model 

        return PartialView("_Partial", Model);
    }
}

AJAX AJAX

var submitAgmtIds = function submitAgmtIds(ids) {

        $.get('Home/Table2', $.param({ ids: ids }, true), function (partialView) {
            $("#av-row-2").html(partialView);
        });

        expandTable();

    }

ROUTE These where kept as the default... ROUTE这些保留为默认值...

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

"ids" is an array such that var array = [1,2,3,4,5] “ ids”是一个数组,使得var array = [1,2,3,4,5]

Again this worked fine in debug but returns a 404 now that it is on a web server. 再次,这在调试中工作正常,但是现在返回404,因为它在Web服务器上。

Thoughts? 思考?

UPDATE UPDATE

I was able to get this to work by hard coding my application name into the ajax call such that {application name}/Home/Table .. This works as expected. 通过将我的应用程序名称硬编码到ajax调用中,使得{application name}/Home/Table ..可以正常工作。 How can I dynamically do this so it will work if the application is deployed under another name? 我如何动态地执行此操作,以便在以其他名称部署应用程序时它可以正常工作?

Hi you may try to change this line : $.get('Home/Table2', $.param({ ids: ids }, true), function (partialView) to like this: $.get('../Home/Table2', $.param({ ids: ids }, true), function (partialView) . 嗨,您可以尝试更改此行: $.get('Home/Table2', $.param({ ids: ids }, true), function (partialView)像这样: $.get('../Home/Table2', $.param({ ids: ids }, true), function (partialView)

Note: putting the two dot and forward slash ../ in front of the home, will solve your problem. 注意:将两个点和正斜线../放在房屋前面,将解决您的问题。

your Changed ajax code: 您更改的ajax代码:

var submitAgmtIds = function submitAgmtIds(ids) {

        $.get('../Home/Table2', $.param({ ids: ids }, true), function (partialView) {
            $("#av-row-2").html(partialView);
        });

        expandTable();

    }

Hope the above the information was useful , kindly let me know your thoughts or feedbacks 希望以上信息对您有所帮助,请让我知道您的想法或反馈

Thanks 谢谢

Karthik KARTHIK

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

相关问题 发布应用程序后,Asp.net MVC 5 Ajax POST 抛出异常 404(未找到) - Asp.net MVC 5 Ajax POST throws exception 404 (Not Found) after application is published ASP.NET MVC 3 AJAX请求返回404 Not Found错误 - ASP.NET MVC 3 AJAX request returns 404 Not Found error asp.net mvc ajax发布返回404找不到 - asp.net mvc ajax post returns 404 not found jqGrid调用ASP.NET MVC控制器操作丢失的Web应用程序名称 - jqGrid call ASP.NET MVC controller action lost web application name 当jquery帖子没有触发asp.net mvc控制器动作时,调试的最佳方法是什么 - What is the best way to debug when a jquery post is not firing off an asp.net mvc controller action 当执行jQuery的toggleClass()函数时,ASP.NET MVC控制器的操作再次执行 - ASP.NET MVC controller's action is executed again when jQuery's toggleClass() function is executed ASP.NET MVC AJAX发布到控制器操作不起作用 - ASP.NET MVC AJAX post to controller action not working 多次调用ASP.NET MVC后控制器操作 - ASP.NET MVC Post Controller Action Invoked multiple times ASP.NET MVC控制器动作和jQuery Ajax问题 - asp.net mvc controller action and jquery ajax issue 在ASP.NET MVC 3中将参数从JQuery传递到Controller Action - Passing Parameters from JQuery to Controller Action in ASP.NET MVC 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM