【问题标题】:Get Requests returning 404 on IIS but works locally获取在 IIS 上返回 404 但在本地工作的请求
【发布时间】: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: 我也在服务器上尝试了以下更改,但没有运气。

https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/deployment/using-asp-net-mvc-with-different-versions-of-iis-cs

这是更改后的路由配置。

  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


    【解决方案1】:

    将 MVC 应用程序放在 apsecureeditor/webapp 文件夹中不会改变应用程序中页面的路由,因为您使用项目的路由集从控制器调用操作,而不是本地文件/视图的位置(服务器) 硬盘。尝试完全按照本地项目加载 URL,即从 URL 中完全删除 apsecureeditor/webapp。

    【讨论】:

    • 我的应用主页可以正常使用这个网址:jwebtst201/apsecureeditor/WebApp,但其他操作似乎没有加载。
    • 这表明您在 iis 上设置站点的方式存在其他问题,当您转到路由 url 时会发生什么?
    • 当我转到路由 url 时,我收到 404 错误。 “找不到该页面。您要查找的页面可能已被删除、更改名称或暂时不可用。”
    • 那么您的问题与您的代码无关,该网站可能在 iis 上以某种方式未正确设置,或者您的 webconfig/publishing 中可能存在错误。我建议针对 iis 提出一个新问题,询问为什么您的网站出现 404 错误,并提供有关您迄今为止为设置网站所做的工作的信息。
    猜你喜欢
    • 1970-01-01
    • 2023-03-17
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多