【发布时间】:2017-11-01 16:59:05
【问题描述】:
我在 IIS 6.0 服务器上托管我的 MVC 应用程序(Angular Js + MVC 4)。
我的路线配置如下:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
下面是控制器代码:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public JsonResult GetAppSettings()
{
try
{
string useAdvancedSearch = ConfigurationSettings.AppSettings["UseAdvancedSearch"];
return Json(new { userAdvancedSearch = Boolean.Parse(useAdvancedSearch) }, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return Json(new { message = ex.ToString() }, JsonRequestBehavior.AllowGet);
}
}
}
我在 Angular js 控制器中的 Ajax 调用如下:
var ConfigService =
function (configConstants, $http, $q) {
this.getAppSettings = function () {
var d = $q.defer();
var get = $http({
method: "GET",
url: "Home/GetAppSettings",
dataType: 'json',
headers: { "Content-Type": "application/json" }
});
get.then(function (response) {
d.resolve(response.data);
console.log(response.data);
}, function (err) {
console.error(JSON.stringify(err));
d.reject(err);
});
return d.promise;
};
};
这个调用在本地 IIS express 中提供了正确的数据,但是当我在 IIS 上运行相同的东西时,我得到了 404 错误。
加载资源失败:服务器响应状态为 404 (未找到)
我在 localhost 中的网址是:http://localhost:63555/Home/GetAppSettings
IIS 服务器 URL 是:http://******/apsecureeditor/WebApp/Home/GetAppSettings
该项目位于服务器上的 apsecureeditor/webapp 文件夹中。
在 IIS 服务器上执行此操作时出现 404 错误。
我的框架是 MVC 4,.net 4.0,IIS 的版本是 6.0。
这里有什么我遗漏的吗?
编辑 1: 我也在服务器上尝试了以下更改,但没有运气。
这是更改后的路由配置。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { action = "Index", id = "" }
);
}
【问题讨论】:
标签: c# angularjs asp.net-mvc iis iis-6