Click here to Skip to main content
15,860,861 members
Articles / Web Development / IIS

Utility to convert file includes to virtual includes

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
4 Nov 2007CPOL1 min read 25.6K   106   19   2
A utility to convert file includes to virtual includes.

Screenshot - ConvertFile2Virtual.jpg

Introduction

Today I had to move an ASP application I developed some years ago to a new hosting provider. After uploading all the files, I discovered that the application had an error in the includes.

Active Server Pages, ASP 0131
Disallowed Parent Path

This error is caused by a configuration in IIS that many hosting providers use, that disallows includes of type file with relative paths to a parent folder, like this: <#include file="../../path_to_include">. The only solution is to replace all those includes with virtual includes with absolute paths such as: <#include virtual="/path_to_include">. This is a very annoying process because basically you have to edit by hand each individual file and include, because the absolute path depends on the including page's path and the included page's path. If you have a web application with hundreds of files, like I did, this is not an option. A full description of the error is available here.

So I developed a mini-utility to do this for me. You give it a start folder which should be your app's root folder, and it searches for all .asp files, replacing the file="" relative paths with virtual="" absolute paths.

Using the code

It is written as a console app in C# .NET 2.0. To run it, just copy it somewhere, open a command line, and execute:

ConvertFile2Virtual.exe path

where path is the path to your root path, such as "c:\projects\client website\". Please note that the path is surrounded by double quotes because the path contains spaces and it ends with a trailing backslash.

I hope this can be useful to someone else.

History

  • v1.0 - Initial release.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
GeneralIIS 6 and IIS 7 default settings for 'Parent paths' Pin
deeps000012-Nov-07 21:12
deeps000012-Nov-07 21:12 
IIS 6 and IIS 7 have 'Parent paths' disabled by default. We can enable them from IIS management console - 'Home Directory->Application settings->Configuration...->Options->Enable Parent Paths'
AnswerRe: IIS 6 and IIS 7 default settings for 'Parent paths' Pin
User 468201721-Nov-07 10:43
User 468201721-Nov-07 10:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.