locked
When deploying MVC app on server ajax cant find action but Localhost is does. RRS feed

  • Question

  • User-544325736 posted

    Hello everyone

    I have a MVC5 application when I run it on my localhost everything works without any errors. When I publish my app then I transfer it to Windows Server 2016 I put the files in wwwroot in the IIS folder and I link everything to create a new website in IIS. I then run the website and it works. I get my javascript code to work but when I go and run my ‘ajax’ methods I get an 404 error and in the function I cannot find my controller action so the method will work. Here is my actual error: xxx.xxx.xx x.219/Parts/DoPartBookFunc?bookval=8 404 (Not Found), Failed to load resource: the server responded with a status of 404 (Not Found)

    I been researching and trying a bunch of different things but so far no luck. Some I tried was @Url.action(“”,””), adding a ~ in front adding ../ in front making a global file and many other things. If someone knows how to fix this it would be hugely appreciated.

    $("#PartBook").on("change", function () {
                    var selectV = $(this).val();
                    var selectT = $(this).text();
    
                    $.ajax({
                        url: '/Parts/DoPartBookFunc',
                        type: 'GET',
                        dataType: 'json',
                        data: { bookval: selectV },
                        //contentType: 'application/json; charset=utf-8',
                        success: function (data) {
                            //alert("s" + data.PartNextNumber);
    

    Thursday, July 11, 2019 1:33 PM

All replies

  • User475983607 posted

    A 404 (Not Found) is pretty specific.  You did not post the Controller Actions so I assume Parts.DoPartBookFunc does not exist or the method is not decorated with an [HttpGet] attribute.

    Have you tried opening the URL in the browser?  

    Edit: this is a duplicate thread...

    https://forums.asp.net/t/2157647.aspx?Publsh+Deploying+MVC5+on+Windows+Server+getting+404+for+an+Action+but+on+Local+it+works+great+

    Thursday, July 11, 2019 2:09 PM
  • User1520731567 posted

    Hi ExceedingLife,

    I came from your previous post.

    Different configuration environments may have different solutions.

    I'm glad that you have solved the issue by yourself and post your solution.

    This may help others who faces the same issue get inspiration.

    You could post the details answer and mark it as answer in your two posts.

    Thank you very much.

    Best Regards.

    Yuki Tao

    Friday, July 12, 2019 7:54 AM