在 IIS6 上使用 jqGrid 和 ASP.NET MVC 2 找不到 POST Ajax 调用 [英] POST Ajax call results in not found using jqGrid and ASP.NET MVC 2 on IIS6

查看:23
本文介绍了在 IIS6 上使用 jqGrid 和 ASP.NET MVC 2 找不到 POST Ajax 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我很困惑.我在 IIS6 上部署了一个 MVC 2 应用程序,一切正常,除了我的 jqGrid 调用来获取数据.

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

在我的开发机器上一切正常,但这是我正在使用的两个 URL

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

本地开发网络服务器:

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

IIS6(注意 https - 不确定这是否重要)

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

后一个 URL 会导致 HTTP 404,这确实令人困惑,因为在我的本地计算机上一切正常.JsonMethod[AcceptVerbs(HttpVerbs.Post)]

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

我的疏忽很大.

我所有的 JSON 请求都是 /Ctrl.mvc/JsonMethod.那么,在 IIS 服务器上,代码位于子文件夹 - AppName 中.因此,我得到了 404,因为找不到 https://domain/Ctrl.mvc/JsonMethod - 这是正确的.

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.

基本上,我需要在部署时更改我的 JSON 请求 - 我真的不喜欢,但也许有更好的方法?

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

推荐答案

将asp.net mvc beta部署到iis 6导致404的http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/.

您的应用程序中是否有更多使用 POST 的 URL?他们在工作吗?您是否有更多没有 .aspx 或 .mvc 之类的扩展名的 URL?他们工作吗?

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?

更新:在像你这样的所有 JavaScript 中,我的 URL 的不同基本/根部分都有问题.因为你使用jqGrid,我想你也有同样的问题.如果我在 Web 服务器上的虚拟目录中发布我的解决方案,那么所有调用我的 JavaScript 的 URL 都将被更改.于是我给了window.location.pathname,并用'/'分割,然后我找出一个新的rootPath对应新的位置.我放置在一个函数中的 URL 的这种变基,我在我的解决方案的所有 JavaScript 中调用该函数.Hire 是在我的网站上完美运行的代码片段:

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.

这篇关于在 IIS6 上使用 jqGrid 和 ASP.NET MVC 2 找不到 POST Ajax 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆