Asp.net 3.5 IIS 7 NHibernet www.sample.com 网站托管在虚拟目录中
它生成的网址类似于“/ sample / home / index”而不是“/ home / index”
好吧,应用程序正在使用上面的url但是当我调用任何Ajax数据时,例如casecade dropdwonlist,我返回404。
操作正常但只有当我返回Json(数据)时它返回404。 我尝试了GET和POST
代码
[HttpPost]
public ActionResult GetSubCategories2(int id)
{
var data = from subCat in CategoryService.GetChildByParentCategory(
CategoryService.GetCategoryByID(id))
select new { Value = subCat.ID, Text = subCat.CategoryName };
return Json(data);
}
我有一个安全过滤器&错误处理程序
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method
, Inherited = true, AllowMultiple = false)]
public class HandelRecordNotFound : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
if (filterContext.Exception.Message.IndexOf("No row with the given identifier exists") > -1)
{
//filterContext.HttpContext.Response.Redirect("~/Admin/InvalidRequestOrRecordNotFound");
filterContext.Result = new RedirectResult("~/Admin/InvalidRequestOrRecordNotFound");
filterContext.ExceptionHandled = true;
}
if (filterContext.Exception.Message.IndexOf("The DELETE statement conflicted") > -1)
{
//filterContext.HttpContext.Response.Redirect("~/Admin/InvalidRequestOrRecordNotFound");
filterContext.Result = new RedirectResult("~/Admin/InvalidRequestOrRecordNotFound");
filterContext.ExceptionHandled = true;
}
//filterContext.Exception.Message
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method
, Inherited = true, AllowMultiple = false)]
public class AdminAuthorization : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
base.AuthorizeCore(httpContext);
object userTypeObject = httpContext.Session["UserType"];
if (userTypeObject == null ||
(UserTypes)Enum.ToObject(typeof(UserTypes), userTypeObject) != UserTypes.Administrator)
{
return false;
}
return true;
}
}
除此之外,每件事都是正常的。
在客户端一切正常但在服务器JsonResult方法上返回错误404。
答案 0 :(得分:2)
关于您的操作过滤器的第一条评论:更改
filterContext.Result = new RedirectResult("~/Admin/InvalidRequestOrRecordNotFound");
为:
var routes = new RouteValueDictionary(
new { controller = "admin", action = "InvalidRequestOrRecordNotFound" }
);
filterContext.Result = new RedirectToRouteResult(routes);
第二个评论是关于你调用你的ajax动作的方式。您应该始终使用url帮助程序生成正确的路由,并且永远不要在脚本中对它们进行硬编码。例如:
而不是:
$.get('/home/someajax', function(result) {
});
执行:
$.get('<%= Url.Action("someajax") %>', function(result) {
});
答案 1 :(得分:0)
您的应用安装在名为“sample”的virt文件夹中,而不是安装在站点根目录中。
移动应用,调整路线或使用包含'/ sample /'前缀的正确网址。