How can I get aspnet compiler to handle a page that contains an include file

1.4k Views Asked by At

I have a web application that lands on a shared hosting platform for my company. That platform has global header/footer code that all applications on the platform consume using include files. I can't change how the header files are structured and how they are to be cosumed--that is dictated to me by another group. I have a build server that does not has IIS installed by design. I am attempting to use the aspnet_compiler.exe during the build process to generate the precompiled website files for deployment.

However, when the build runs I get errors like this:

/Company/Controls/Header.ascx(7): error ASPPARSE: Failed to map the path '/sites/header.inc'.

The Header.ascx control has this server-side include in the HTML:

<!-- #include virtual="/sites/header.inc" -->

On my local machine, I have created a virtual directory in IIS named "sites" that points to the global header code (which I have also copied to my local machine). This same "sites" virtual exists in IIS on the hosting environment. I would really like to avoid having to install IIS on the build machine because it is a shared build machine and I don't anyone to mistakenly work IIS dependencies into their code. The build machine shouldn't need to have IIS.

What is the best way to get the precompiled site files that aspnet_compiler.exe produces during my build without installing IIS?

3

There are 3 best solutions below

2
On

Don't use server-side includes. They are ancient technology and are disabled on most modern sites.

I recommend you instead create .ascx files to replace each of the .inc files, and use those instead.

2
On

Microsoft has a very simple example of how to replace an include statement...

http://support.microsoft.com/kb/306575

Looking at the path of your error it seems you are already using some sort of global user control and I'm guessing this is a file which is reused by other applications or languages so I would suggest coming up with a more custom version with error handling and such since it is working over a mapped drive but the basic answer is you need to read the file and output it to the stream during the Render event.

0
On

Try this:

<!-- #include virtual="~/sites/header.inc" -->

The ~ is a shortcut for "root of the web application."