[英]Deploy ASP.NET Core Docker project - get a 405 error (locally in my IIS, web requests works). How to fix it?
[英]Get Requests returning 404 on IIS but works locally
我将MVC应用程序(Angular Js + MVC 4)托管在IIS 6.0服务器上。
我的路线配置如下:
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(未找到)
我在本地主机的网址是: 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:我也在服务器上尝试了以下更改,但没有运气。
这是更改后的routeconfig。
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 = "" }
);
}
将MVC应用程序放置在apsecureeditor / webapp文件夹中不会更改应用程序页面的路由,因为您是使用项目的路由集而不是本地(服务器)硬盘上文件/视图的位置从控制器调用操作的。 尝试完全像本地项目一样加载URL,即,从URL中完全删除apsecureeditor / webapp。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.