Andrey Shchekin
Andrey Shchekin

Reputation: 21609

How do I properly support colons (':') in URLs (WebApi within larger ASP.NET application)

I want some of my ids to be colon-separated, which means that my URL paths have colons in them, e.g. /somethings/xyz:123.

I have removed : from requestPathInvalidCharacters, but now I have another problem. It seems there are several third-party modules in the outside application that get PhysicalPath or do MapPath on all requests, which seems to have problem with colons:

[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

How do I resolve it without rewriting all those modules?

Upvotes: 0

Views: 619

Answers (2)

Andrey Shchekin
Andrey Shchekin

Reputation: 21609

I found the answer that fixes exceptions in PhysicalPath and MapPath (for all modules):

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

Upvotes: 1

govin
govin

Reputation: 6733

I haven't tested this myself but this might help. Check if this hotfix is installed - http://support2.microsoft.com/kb/932552

And then as per the document, you have to change the below registry settings.

After you apply this hotfix, you must enable it by setting the value of the VerificationCompatibility entry of the following registry subkey to 1:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET

DWord Value Name: VerificationCompatibility 
Value Data: 1

Upvotes: 0

Related Questions