0

MVC5 .Net 4.5.2 にいくつかのビューを持つプロジェクトがあります。次に、最初のプロジェクトで使用できるように razorgenerator nuget パッケージを使用してビューをプリコンパイルする 2 番目の MVC プロジェクトをソリューションに追加しました。次に、GlobalFilters に追加したカスタム GlobalFilterCollection を使用して、ユーザーを最初のプロジェクトのビュー、または 2 番目のプロジェクトの特定のビューに誘導しました。

このシナリオは、VS2013 (IIS Express) でローカルに実行するとうまく機能します。ただし、サーバー(Winサーバー2008、IIS7)に配置すると、javascriptによって呼び出されたときにビューが見つかりません。最初に呼び出されたビューのみです。

何か案は?

定義されたルート:

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
            );

使用したフィルター:

override public void OnActionExecuting(ActionExecutingContext filterContext)
{
    else
    {
        string requestedAction = (filterContext.ActionDescriptor).ActionName;
        string requestedController = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

        //If we are already going to the controller action which serves the login view when not logged in, then ignore the filter:
        if ((requestedAction == "Login" || requestedAction == "LoginAction") && requestedController == "DBLogin")
        {
            base.OnActionExecuting(filterContext);
            return;
        }

        var Session = filterContext.HttpContext.Session;

        //If we got here, then another page was requested, so verify the login and change the route if necessary:
        if (Session["IsLoggedIn"] != null && (bool)Session["IsLoggedIn"] == true)
        {
            base.OnActionExecuting(filterContext);
            return;
        }
        else
        {
            RouteValueDictionary reRouter = new RouteValueDictionary();
            reRouter.Add("action", "Login");
            reRouter.Add("controller", "DBLogin");
            filterContext.Result = new System.Web.Mvc.RedirectToRouteResult(reRouter);
        }
    }
}

IIS で失敗する後続のビューを要求するために呼び出される Javascript:

$.support.cors = true;
$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: SERVER_TO_USE + "/DBLogin/LoginAction",
    data: parameters,
    success: function (data, textStatus, jqXHR) {
        callBackLoginSuccess(data);
    },
    error: function (jqXHR, textStatus, errorThrown) {
        console.log(textStatus);
        console.log(errorThrown);
        hasError = true;
        lastErrorMessage = errorThrown;
    },
    complete: function (jqXHR, textStatus) {
        if (hasError) {
            var errorObject = ErrorHandling.BuildClientSideError(lastErrorMessage);
            ErrorHandling.ShowErrors(errorObject);
        }
    },
    dataType: 'json'
});
4

1 に答える 1

0

ローカルで実行しているときは、ドメインを指定する必要はありませんでした..

于 2014-06-11T21:53:54.287 に答える