Vault of Thoughts

2006-07-06

Please visit my new blog at vaultofthoughts.net

PathsBuildProvider update

I have used my PathsBuildProvider a while now and I have came across some issues. I have found two major issues.


The first issue had to do with the fact that from some strange reason
the development web server treats root directory "/" in a different
way than IIS. So redirecting to /aplicationname/page.aspx has
different effect those two servers. I have made a change so that the
property is not statically encoded to return a string but rather to
use System.Web.VirtualPathUtility.ToAbsolute("~/Default.aspx"). As far
as I know it works on both IIS and the development server.


The second issue has to do with the application name being encoded in
the code as in Paths.WebTest.Default_aspx. Imagine however that you
deploy your application under a different name say WebTest2. It no
longer works and strange things happen. To overcome this I have
changed the code to allways use the AppRoot as a root directory name.


I have also included the changes proposed by Will Gant. The changes are simple yet brilliant. He proposed that the properties returning file paths to be static. In fact that was what I have first implemented but then I have run to a problem with doing something like Paths.AppRoot.Directory1.Directory2.Default_aspx since if all properties are static than I'm not able to return anything meaningful (an object instance) from such property. Will's solution uses a fact that when you reference a directory as in Paths.AppRoot.Directory1 what you really get is not a property Directory1 of AppRoot object/class, but a namespace qualified Directory1 class name which in turn has static properties.


As usuall, the code is available here and here

If you liked this article why not support its author by making a donation?

0 Comments:

Post a Comment

<< Home