1

This is puzzling me. I deployed an MVC 2 application to IIS6 and everything works fine except for my jqGrid calls to get data.

All is well on my development machine, but here are the two URLs I'm working with

Local dev web server:

POST http://localhost:port/Ctrl.mvc/JsonMethod

IIS6 (notice https - not sure if that matters)

POST https://www.example.com/AppName/Ctrl.mvc/JsonMethod

The latter URL results in a HTTP 404, which is really confusing as all works well on my local machine. The JsonMethod is properly declared with [AcceptVerbs(HttpVerbs.Post)]

Edit

Quite an oversight on my part.

All of my JSON requests are /Ctrl.mvc/JsonMethod. Well, on the IIS server, the code is in a sub-folder - AppName. As such, I'm getting a 404 because https://domain/Ctrl.mvc/JsonMethod is not found - which is correct.

Basically, I need to change my JSON requests when I deploy - which I really don't like, but perhaps there is a better way?

halfer
  • 19,824
  • 17
  • 99
  • 186
Dan
  • 724
  • 2
  • 9
  • 23

3 Answers3

2

Look at Deploy asp.net mvc beta to iis 6 causing 404's and http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/.

Do you have more URL in your application where POST are used? Are they work? Do you have more URLs without an extension like .aspx or .mvc? Are they work?

UPDATED: I had a problem with different base/root parts of my URL in all JavaScripts like you. Because you use jqGrid, I think you have the same problem. If I publish my solution in a virtual directory on a Web Server, then all URLs which call my JavaScripts will be changed. So I give window.location.pathname and split it with '/', then I find out a new rootPath corresponds to the new location. Such rebasing of URLs I placed in a function which I call inside of all JavaScripts of my solution. Hire is code fragment which works perfect on with my site:

var pathArray = window.location.pathname.split( '/' );
var rootPath = '';
for (var i = 0; i < pathArray.length; i++) {
    var p = pathArray[i];
    if (p === "") {
        continue;
    }

    if (p.toLowerCase() !== 'home') {
        rootPath += '/';
        rootPath += p;
    } else {
        break;
    }
}
this.urlBase = rootPath + '/Repository.svc';
this.urlExportBase = rootPath + '/ExportToExcel';

The solution is not perfect, but it works. It can be that you should change this "rebasing" function to make it working with your side.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I like it; I'll definitely look into something like this :). Thanks Oleg! – Dan May 13 '10 at 11:46
  • 1
    I am glad to help you Dan! Sometime one writes an answer with a code and listen nothing from the person who asked the question, but if I read "Thanks, it works" it’s enough and I am look also like ☺. – Oleg May 13 '10 at 12:07
2

Use the mvc helpers to generate the url for the jqGrid ajax function to ensure the correct url is used.

$('#mygrid').jqGrid({ 
    url: '<%= Url.Action("MyControllerJsonAction", Model.RouteValues) %>' 
});
Annagram
  • 700
  • 7
  • 16
  • Ah nice - never thought of this. Although the call for the grid is in a separate js file. Worth trying though, thanks! – Dan May 15 '10 at 12:50
0

When I use VS2012 release my project(MVC+Kendo UI) to IIS6.0 .The problem come out. F12 debug the error is 404,Chrome say the page can't find .

It's because the url is not right when you should add the Doamin in the url:

The right code is:

function QueryExpSendList() {
var EValid = true;
var uri = AJAXBaseUrl;
if (AJAXBaseUrl.indexOf("localhost") > 0) {
    uri = AJAXBaseUrl + "AJAX/QuerySendList/";
}
else {
    uri = AJAXBaseUrl + "KQExpress/AJAX/QuerySendList/";
}
GenerateExpressSendGrid(uri);
$("#QueryResult").show();

}

The Error Code:

function QueryExpSendList() {
var EValid = true;
var uri = AJAXBaseUrl + "AJAX/QuerySendList/";
GenerateExpressSendGrid(uri);
$("#QueryResult").show();

}

By sirili@163.com

sirili
  • 1