views:

138

answers:

2

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.domain.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)]

Let me know if any more info is needed - I appreciate any and all help with this!

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?

+2  A: 

Look at http://stackoverflow.com/questions/239981/deploy-asp-net-mvc-beta-to-iis-6-causing-404s 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.

Oleg
Ugh, wow - what an oversight - see my update
Dan
I like it; I'll definitely look into something like this :). Thanks Oleg!
Dan
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
+1  A: 

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) %>' 
});
Coderuckus
Ah nice - never thought of this. Although the call for the grid is in a separate js file. Worth trying though, thanks!
Dan