简体   繁体   English

部署到远程服务器后控制器操作方法中的 404 错误

[英]404 Error in controller action methods after deploying to remote server

.JS File .JS文件

$("#drpdwn").change(function ()
{
    var filter1 = document.getElementById("drpdwn").value;
    window.location = '/Controller/GetByFilter?filter=' + filter1;
});

Actionmethod in controller:控制器中的动作方法:

public ActionResult GetByFilter(string filter)
{
    var model = obj.GetByFilter(filter);
    return View(model);
}

This throws a 404 on server but works as expected on localhost.这会在服务器上引发 404,但在本地主机上按预期工作。 problem is with URL part and I have no clue how to fix it.问题在于 URL 部分,我不知道如何修复它。

There are few things when you depoly on remote server, if you deploy at root then it will work ie http://www.example.com当您在远程服务器上 depoly 时,几乎没有什么事情,如果您在 root 下部署,那么它将起作用,即http://www.example.com

But if you added application or virtual directory then you need to use virtual directory too.但是如果您添加了应用程序或虚拟目录,那么您也需要使用虚拟目录。

i.e. window.location = '/[virdir]/Controller/GetByFilter?filter=' + filter1;

So best option will be use absolute url instead of relative to the application.

i.e. window.location = 'http://www.example.com/Controller/GetByFilter?filter=' +filter1;

or window.location = 'http://www.example.com/myapp/Controller/GetByFilter?filter=' +filter1;

You could use something like this你可以使用这样的东西

window.location.href = "@Url.Action("ActionName","ControllerName")"; window.location.href = "@Url.Action("ActionName","ControllerName")";

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

相关问题 加载资源失败:部署项目后,服务器响应状态为404错误 - Failed to load resource: the server responded with a status of 404 error after deploying project 远程服务器返回错误:(404)找不到-HttpWebResponse - The remote server returned an error: (404) Not Found - HttpWebResponse Axios 在删除操作后给出 404 错误 - Axios giving 404 error after delete action 将 PWA(渐进式 Web 应用程序)部署到 Firebase 后,如何修复“加载资源失败:服务器响应状态为 404 ()”错误? - How to fix "Failed to load resource: the server responded with a status of 404 ()" error after deploying PWA (Progressive Web App) to Firebase? 在登录后继续使用Remote => true /控制器操作继续表单发布 - Continue Form Post with remote => true / Controller Action after Devise Login 在服务器中刷新页面后 ReactJS 404 错误 - ReactJS 404 error after refreshing the page in server 在 Github 上部署我的 React 应用程序后,我收到 404 错误页面(请帮忙) - I am getting a 404 error page after deploying my react app on Github (help please) 为什么我的控制器操作返回 404? - Why is my controller action returning 404? 部署生产版本时出现404错误 - Getting a 404 error when deploying production build 单击以执行控制器操作(远程:true),然后更新href - Click for controller action (remote: true) and then update href
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM