我有一个项目在MVC5 .Net 4.5.2中有一些视图然后我在解决方案中添加了第二个MVC项目,该项目使用razorgenerator nuget包来预编译视图以便在第一个项目中使用。接下来,我使用了一个自定义的GlobalFilterCollection,我将其添加到GlobalFilters中,以将用户定向到第一个项目中的视图或第二个项目中的特定视图。
在VS2013(IIS Express)中本地运行时,此方案很有用。当我把它放在服务器上时(Win server 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);
}
}
}
调用Javascript以请求在IIS上失败的后续视图:
$.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'
});
答案 0 :(得分:0)
这只是网址,在本地运行时我不需要指定域名。