如何正确支持URL中的冒号(':')(较大的ASP.NET应用程序中的WebApi)

时间:2014-11-10 04:38:20

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

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

我已从:移除requestPathInvalidCharacters,但现在我遇到了另一个问题。外部应用程序中似乎有几个第三方模块在所有请求中获得PhysicalPathMapPath,这似乎与冒号有问题:

[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

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

2 个答案:

答案 0 :(得分:1)

我找到了解决PhysicalPathMapPath(所有模块)异常的答案:

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

答案 1 :(得分:0)

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

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

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

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET

DWord Value Name: VerificationCompatibility 
Value Data: 1