【问题标题】:How do I properly support colons (':') in URLs (WebApi within larger ASP.NET application)如何正确支持 URL 中的冒号 (':')(大型 ASP.NET 应用程序中的 WebApi)
【发布时间】:2015-01-06 08:18:53
【问题描述】:

我希望我的一些 id 用冒号分隔,这意味着我的 URL 路径中有冒号,例如/somethings/xyz:123.

我已经从requestPathInvalidCharacters 中删除了:,但现在我遇到了另一个问题。外部应用程序中似乎有几个第三方模块在所有请求上获取PhysicalPath 或执行MapPath,这似乎与冒号有问题:

[NotSupportedException: The given path's format is not supported.]
   System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) +14633709
   System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) +351
   System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +151
   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.Hosting.HostingEnvironment.MapPath(VirtualPath virtualPath) +107

如何在不重写所有模块的情况下解决它?

【问题讨论】:

  • 看看这个答案是否有帮助:stackoverflow.com/a/12085167/745969
  • 我认为它没有帮助——它含糊地说“ASP.net 不允许冒号”,但是如果我禁用所有模块,它就可以正常工作。唯一的问题是是否有更好的解决方法(禁用给定 URL 的所有模块?)。

标签: asp.net asp.net-web-api


【解决方案1】:

我找到了修复PhysicalPathMapPath 中异常的答案(适用于所有模块):

<httpRuntime ... relaxedUrlToFileSystemMapping="true" />

【讨论】:

    【解决方案2】:

    我自己没有对此进行测试,但这可能会有所帮助。检查是否安装了此修补程序 - http://support2.microsoft.com/kb/932552

    然后根据文档,您必须更改以下注册表设置。

    应用此修补程序后,您必须通过将以下注册表子项的 VerificationCompatibility 条目的值设置为 1 来启用它:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET
    
    DWord Value Name: VerificationCompatibility 
    Value Data: 1
    

    【讨论】:

      猜你喜欢
      • 2013-10-06
      • 1970-01-01
      • 2011-06-09
      • 2010-10-14
      • 2020-10-04
      • 1970-01-01
      • 2014-06-26
      • 1970-01-01
      相关资源
      最近更新 更多