[英]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.