Encountering 404 Error in controller's action methods following deployment on remote server

.JS Script

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

Action Method in Controller:

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

Encountering a 404 error on the server, while the code functions correctly on localhost. The problem seems to be related to the URL format but requires further investigation for resolution.

Answer №1

When deploying on a remote server, it's important to consider the location of your deployment. If you are deploying at the root, your application should work fine using a URL like http://www.example.com

However, if you have added an application or virtual directory, you will need to adjust the URL accordingly.

For example, use: window.location = '/[virdir]/Controller/GetByFilter?filter=' + filter1;

The best practice is to use absolute URLs instead of relative ones within the application.

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

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

Answer №2

One possible solution is to implement the following:

Redirect the user by using the syntax: window.location.href = "@Url.Action("ActionName","ControllerName")";

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transferring an array to PHP using AJAX

In this coding scenario, I initialize my array: let myArray = []; Within a loop, elements are added to the array as follows: myArray.push($(this).data('id')); // Example: [1, 2, 3, 4] Subsequently, I transmit this data to PHP using AJAX throu ...

Advantages of placing script src tags at the top of the body versus placing them at the bottom of the body

I've heard that it's best to place the script tags right before the closing body tag. However, when I follow this advice, my angularJS expressions don't seem to compute correctly for some reason. When I place the script tags in that location ...

The loading GIF in jQuery is malfunctioning when displayed simultaneously on multiple div elements

I am currently working on my Laravel dashboard's blade to showcase various statistics. These stats will be updated whenever the date picker is changed. Below is the code for my date picker: <div class="row"> <div class=&qu ...

verifying that all characters in an array are permissible

Can someone explain why this code always returns false even when I enter "abcdef" into the prompt, which should make it return true? var userinput = prompt('Enter characters:'); var lowercase = userinput.toLowerCase(); var allowedcharacters = ...

Learn the process of merging an array element into another object and keeping track of the total count

Initially, my array contains object elements as shown below: $scope.selectedIngredient = [object1, object2, object3, object1, object2]; Next, I have a new object : $scope.selectedIngredientResults = {}; Now, I want to create a JavaScript function that ...

Encountering difficulties while implementing the AJAX request with the Giphy API

I am just getting started with jQuery and JavaScript. My goal with the ajax or get method is to input any keyword (like maine coon, for example), hit submit, and then see a page full of maine coon gifs. The API code I am working with is from Giphy. func ...

What is the best way to incorporate my light/dark mode theme into index.js and have my header serve as the switch location?

Could someone assist me with setting up a theme around my index.js components and using a switch state in my header.js to toggle between light and dark themes? I'm looking for a way to simplify the process to minimize the amount of code needed. As a ...

What is the process to change the jQuery quiz outcome into a PDF when a user clicks a

I'm currently working on a jQuery quiz project where I want users to be able to download their results in PDF format with just one click. After doing some research, I came across the dompdf library, which allows me to convert HTML to PDF. If you&apos ...

How can I trigger the offcanvas opening in Bootstrap 5 through code?

I am having an issue with a bottom offcanvas on my webpage. I want to open it when a card is clicked, but despite trying to set the necessary attributes and using code from the documentation, it only shows the backdrop briefly before immediately dismissing ...

What is the best way to filter through JSON data in Vue.js?

I'm encountering an issue with my JSON file that I am rendering to a table. I have 11 columns including id, name, and more. I want to search by every column, but the functionality only works for one column. If I try to filter the data multiple times, ...

Issue: The module "node:util" could not be located while attempting to utilize the "sharp" tool

Upon adding sharp to my Node.js application and attempting to use it, I encountered the following error: /Users/username/Documents/GitHub/Synto-BE/node_modules/sharp/lib/constructor.js:1 Error: Cannot find module 'node:util' Require stack: - /Use ...

Comparing Visual Studio 2005 with 2008: Have you noticed the difference in the code automatically generated by the designer in '08 compared to '05?

As a beginner with .NET, Visual Studio, C#, and more, I have been exploring the differences between the code behind a form in 2008 compared to 2005. When working on a simple Windows Form app in C# and adding some controls along with MessageBox.Show event h ...

Leverage the power of AngularJS in ASP.NET without incorporating MVC

Is it possible to integrate AngularJS code into an ASP.NET project without using MVC architecture? I typically insert a script after the closing body tag like this: <script src="js/angular.js"></script> I have attempted to define the module ...

How can I reposition an image diagonally to a specific location using JavaScript in p5.js? Is there a method to display an image and then conceal it at a chosen location in p5.js?

Is there a way to move the third image diagonally until it intersects with the two images? var pic1; var pic2; var pic3; let posX=0 let posY=0 const rightwall=350; function preload(){ pic1=loadImage("5.png") pic2=loadImage("iron.jpg&qu ...

The jspdf function is not displaying any images in the PDF file

I am new to coding and encountered an issue when trying to download images in reactjs. After clicking the download button, I only receive a blank pdf file. https://i.stack.imgur.com/0XJcC.png The function in my react code that attempts to generate the p ...

How can one extract values from the web.config section within an app.config file?

I am currently working on unit testing values that will eventually be stored in a web.config file. To do this, I have created an app.config file in my test project with a web.config section to store the settings. Typically, I would use System.Configuration ...

Using AngularJS to pass a parameter to a directive's template

My basic set looks like this HTML <linear-chart chartData="myArray" height="666"> </linear-chart> JS ... ... app.directive('linearChart', function($window){ return{ restrict:'EA', template:"<svg ...

Implement VueJS functionality to prevent form submission upon submission and instead submit the form upon keyup

My form has the following structure: <form id="myForm" action="/searchuser" method="POST" @submit.prevent="onSubmit(inputValue)"> <div class="field"> <label class="label">Name</label> <div class="control"> ...

What am I doing wrong that causes me to repeatedly run into errors when trying to build my react app?

While attempting to set up a react.js web application in VScode using "npm," I encountered the following errors: npm ERR! code ERR_SOCKET_TIMEOUT npm ERR! errno ERR_SOCKET_TIMEOUT npm ERR! network Invalid response body while trying to fetch https://registr ...

What is the best method for testing routes implemented with the application router in NextJS? My go-to testing tool for this is vitest

Is it possible to test routes with vitest on Next.js version 14.1.0? I have been unable to find any information on this topic. I am looking for suggestions on how to implement these tests in my project, similar to the way I did with Jest and React Router ...