Asp.net mvc 2 ASP.NET MVC 2.0 IIS 7.0和404错误

Asp.net mvc 2 ASP.NET MVC 2.0 IIS 7.0和404错误,asp.net-mvc-2,iis-7,asp.net-ajax,Asp.net Mvc 2,Iis 7,Asp.net Ajax,Asp.NET3.5 IIS 7 NHibernet www.sample.com 托管在虚拟目录中的网站 其生成url类似于“/sample/home/index”,而不是“/home/index” 应用程序正在使用上面的url,但当我调用任何Ajax数据(如casecade DropdOnlist)时,我返回404 操作工作正常,但只有当我返回Json(数据)时,它才会返回404。 我尝试了GET和POST 代码 我有一个安全过滤器和错误处理程序 [AttributeUsage(At

Asp.NET3.5 IIS 7 NHibernet www.sample.com 托管在虚拟目录中的网站

其生成url类似于“/sample/home/index”,而不是“/home/index”

应用程序正在使用上面的url,但当我调用任何Ajax数据(如casecade DropdOnlist)时,我返回404

操作工作正常,但只有当我返回Json(数据)时,它才会返回404。 我尝试了GET和POST

代码

我有一个安全过滤器和错误处理程序

    [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。

您的应用程序安装在名为“sample”的virt文件夹中,而不是安装在站点根目录中


移动应用程序、调整路线或使用包含“/sample/”前缀的正确URL

关于动作过滤器的第一句话:更改

filterContext.Result = new RedirectResult("~/Admin/InvalidRequestOrRecordNotFound");
致:

第二点是关于调用ajax操作的方式。您应该始终使用url帮助程序生成正确的路由,而不要在脚本中硬编码它们。例如:

而不是:

$.get('/home/someajax', function(result) { 

});
做:

$.get(“”,函数(结果){
});

否我的客户端主网站正在root上运行,因此我无法将其移动到root。我通常以子域的形式在自己的域中演示我的工作,如“”,因为我从未在生成的URL中找到“wayzsoft”或“client”。我认为,即使是子域也作为虚拟目录托管。第二,我对JsonResult有问题,不是对ActionResult和内容有问题,谢谢您的回答,但InvalidRequestOrRecordNotFound是一个视图,我只是重定向到视图。对于URL,我严格要求用户URL.Action。
var routes = new RouteValueDictionary(
    new { controller = "admin", action = "InvalidRequestOrRecordNotFound" }
);
filterContext.Result = new RedirectToRouteResult(routes);
$.get('/home/someajax', function(result) { 

});
$.get('<%= Url.Action("someajax") %>', function(result) { 

});