加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 从ASP.NET MVC 1迁移到ASP.NET MVC 2后的PathToo

发布时间:2020-12-16 06:43:17 所属栏目:asp.Net 来源:网络整理
导读:我已将我的应用程序从MVC 1更新为MVC 2.之后,一些页面抛出PathTooLongException: [PathTooLongException: The specified path,file name,or both are too long. The fully qualified file name must be less than 260 characters,and the directory name mu
我已将我的应用程序从MVC 1更新为MVC 2.之后,一些页面抛出PathTooLongException:

[PathTooLongException: The specified path,file name,or both are too long. The fully qualified file name must be less than 260 characters,and the directory name must be less than 248 characters.]
   System.IO.Path.SafeSetStackPointerValue(Char* buffer,Int32 index,Char value) +7493057
   System.IO.Path.NormalizePathFast(String path,Boolean fullCheck) +387
   System.IO.Path.NormalizePath(String path,Boolean fullCheck) +36
   System.IO.Path.GetFullPathInternal(String path) +21
   System.Security.Util.StringExpressionSet.CanonicalizePath(String path,Boolean needFullPath) +73
   System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str,Boolean needFullPath) +278
   System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access,AccessControlActions control,String[] pathListOrig,Boolean checkForDuplicates,Boolean needFullPath,Boolean copyPathList) +87
   System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access,String path) +65
   System.Web.InternalSecurityPermissions.PathDiscovery(String path) +29
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath,VirtualPath baseVirtualDir,Boolean allowCrossAppMapping) +146
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath) +37
   System.Web.HttpServerUtility.Execute(IHttpHandler handler,TextWriter writer,Boolean preserveForm,Boolean setPreviousPage) +43
   System.Web.HttpServerUtility.Execute(IHttpHandler handler,Boolean preserveForm) +28
   System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler,Boolean preserveForm) +22
   System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext) +284
   System.Web.Mvc.WebFormView.RenderViewPage(ViewContext context,ViewPage page) +82
   System.Web.Mvc.WebFormView.Render(ViewContext viewContext,TextWriter writer) +85
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +267
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult actionResult) +10
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,String actionName) +320
   System.Web.Mvc.Controller.ExecuteCore() +104
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +36
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +53
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +30
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8678910
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously) +155

我知道ASP.NET中260-character-url-lenght的问题,但我的应用程序在更新到ASP.NET MVC 2.0之前工作正常!

此问题不仅发生在本地,也发生在远程主机上

我比较了RenderView方法实现.

MVC 1:

public virtual void RenderView(ViewContext viewContext) {
    ViewContext = viewContext;
    InitHelpers();
    // Tracing requires Page IDs to be unique.
    ID = Guid.NewGuid().ToString();
    ProcessRequest(HttpContext.Current);
}

MVC 2:

public virtual void RenderView(ViewContext viewContext) {
    ViewContext = viewContext;
    InitHelpers();

    bool needServerExecute = false;

    SwitchWriter switchWriter = viewContext.HttpContext.Response.Output as SwitchWriter;
    if (switchWriter == null) {
        switchWriter = new SwitchWriter();
        needServerExecute = true;
    }

    using (switchWriter.Scope(viewContext.Writer)) {
        if (needServerExecute) {
            // It's safe to reset the _nextId within a Server.Execute() since it pushes a new TraceContext onto
            // the stack,so there won't be an ID conflict.
            int originalNextId = _nextId;
            try {
                _nextId = 0;
                viewContext.HttpContext.Server.Execute(HttpHandlerUtil.WrapForServerExecute(this),switchWriter,true /* preserveForm */);
            }
            finally {
                // Restore the original _nextId in case this isn't actually the outermost view,since resetting
                // the _nextId may now cause trace ID conflicts in the outer view.
                _nextId = originalNextId;
            }
        }
        else {
            ProcessRequest(HttpContext.Current);
        }
    }
}

解决方法

这更像是ASP.NET 4.0的默认限制,而不是ASP.NET MVC 1.0到2.0的迁移问题.在web.config中尝试 increasing this limit:

<httpRuntime maxUrlLength="1000" relaxedUrlToFileSystemMapping="true" />

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读