当点击此url时,答案是System.NotSupportedException
http://localhost/missingcontroller/missingaction/503/page:10
这是ASP.NET MVC 3中的错误吗? 知道怎么解决吗?
System.NotSupportedException:不支持给定路径的格式。
[NotSupportedException: The given path's format is not supported.]
System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) +12652424
System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) +165
System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +112
System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +38
System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path) +92
System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) +639
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +195
System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +94
System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext) +436
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +384
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +785284
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +785284
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +785284
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +785360
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.431
这不是重复
首先这个问题不重复。 我不是试图在网址中使用“:”,而是处理来自机器人的电话,这些机器人正在收集网站,有时在网址中使用“:”。
正确答案
正确的答案埋在StringExpressionSet.CanonilizePath方法中:
internal static string CanonicalizePath(string path, bool needFullPath)
{
if (path.IndexOf('~') != -1)
{
string text = null;
StringExpressionSet.GetLongPathName(path, JitHelpers.GetStringHandleOnStack(ref text));
string arg_21_0 = (text != null) ? text : path;
path = arg_21_0;
}
if (path.IndexOf(':', 2) != -1)
{
throw new NotSupportedException(Environment.GetResourceString("Argument_PathFormatNotSupported"));
}
if (!needFullPath)
{
return path;
}
string fullPathInternal = Path.GetFullPathInternal(path);
if (path.EndsWith(StringExpressionSet.m_directorySeparator + ".", StringComparison.Ordinal))
{
fullPathInternal = ((!fullPathInternal.EndsWith(StringExpressionSet.m_directorySeparator)) ? (fullPathInternal + StringExpressionSet.m_directorySeparator + ".") : (fullPathInternal + "."));
}
return fullPathInternal;
}
看看这一行,你就会明白没有补丁就无法处理这些网址......
if (path.IndexOf(':', 2) != -1)
throw new NotSupportedException(Environment.GetResourceString("Argument_PathFormatNotSupported"));
CanonicalizePath阻止“:”出现在url中的任何位置,并且无法替换此方法或其中一种调用方法。
一种解决方案可能是在global.asax Application_Error中处理此异常,提取英文字符串“不支持给定路径的格式”。如果异常是NotSupportedException类型,则重写url。但这可能会错误地处理其他真正的错误...
另一个解决方案可能是使用IIS重写模块(不是asp.net!)来动态替换传入URL中的任何“:”与另一个已知字符。