Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to include common aspx pages into different Web Application Projects?

Posted on 2007-10-11
13
Medium Priority
?
1,471 Views
Last Modified: 2012-08-13
Hi,  I have two separate web applications which include many common aspx pages.  I would like to separate the common pages into a single directory which are then referenced by the two Web Application Projects, rather than having actual copies.

I can easily share simple class files across the projects by simply adding references.  However, that does not seem to work for aspx pages.  How can I do this?
0
Comment
Question by:davisnw
  • 7
  • 4
12 Comments
 
LVL 3

Author Comment

by:davisnw
ID: 20059721
One thing I have tried is adding the following to the .csproj file of the separate web applications:

  <ItemGroup>
    <Compile Include="..\Gateway.Common\index.aspx">
      <Link>index.aspx</Link>
    </Compile>
    <Compile Include="..\Gateway.Common\index.aspx.cs">
      <Link>index.aspx.cs</Link>
      <SubType>ASPXCodeBehind</SubType>
      <DependentUpon>index.aspx</DependentUpon>
    </Compile>
    <Compile Include="..\Gateway.Common\index.aspx.designer.cs">
      <Link>index.aspx.designer.cs</Link>
      <DependentUpon>index.aspx</DependentUpon>
    </Compile>
  </ItemGroup>

However, although the files then show up in the project (as links) I get strange errors:

Error      1      Keyword, identifier, or string expected after verbatim specifier: @      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      1      3      Gateway.AdminView
Error      2      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      6      88      Gateway.AdminView
Error      3      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      7      97      Gateway.AdminView
Error      4      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      20      81      Gateway.AdminView
Error      5      Preprocessor directives must appear as the first non-whitespace character on a line      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      22      74      Gateway.AdminView
Error      6      A namespace does not directly contain members such as fields or methods      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      1      1      Gateway.AdminView
Error      7      Keyword, identifier, or string expected after verbatim specifier: @      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      1      3      Gateway.BorrowerView
Error      8      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      6      88      Gateway.BorrowerView
Error      9      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      7      97      Gateway.BorrowerView
Error      10      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      20      81      Gateway.BorrowerView
Error      11      Preprocessor directives must appear as the first non-whitespace character on a line      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      22      74      Gateway.BorrowerView
Error      12      A namespace does not directly contain members such as fields or methods      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      1      1      Gateway.BorrowerView

These errors are not due to errors in the page, because the page works fine when added directly rather than as a link.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20059790
Can you try adding the aspx from another project by using Add Existing Item? Lets see if it creates a new copy for itself or tries to share the same physical file
0
 
LVL 3

Author Comment

by:davisnw
ID: 20060375
Add Existing Item creates a copy.  What I need is for it to share the same physical file.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 21

Expert Comment

by:surajguptha
ID: 20060399
Why not add a link to the other web page from the Menu ?
0
 
LVL 3

Author Comment

by:davisnw
ID: 20060660
Because these two applications are published on different servers - one internal and one external.  Also, the unique pages of the individual applications need to share session state with the common files.  Thus the common files actually need to be part of the Web Application Project, but linked to the same file for development purposes.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20060776
I dont think it is possible to reference to the same physical files from two different projects. Even if the IDE lets us point to another physical directory it would defy all rules of security, session sharing, deployment in my opinion.
0
 
LVL 3

Author Comment

by:davisnw
ID: 20060837
To be clear, it is only needing to reference the same physical file during development for the purposes of maintaining the same common codebase.  At deployment, copies of the common files will be deployed to their separate directories.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20060848
Even during development all these rules would apply and thats the reason i think it is not possible
0
 
LVL 3

Accepted Solution

by:
davisnw earned 0 total points
ID: 20067126
I found a solution that will work for my case.  I set up multiple Web Application Projects in the same base directory and added the two projects to the same solution.  Then I added links like so to the csproj file:

  <ItemGroup>
    <Content Include="..\App1Config\Web.config">
      <Link>Web.config</Link>
    </Content>
    <Content Include="..\App1Config\App1AppSettings.config">
      <Link>App1AppSettings.config</Link>
      <DependentUpon>Web.config</DependentUpon>
    </Content>
    <Content Include="..\App1Config\App1Connections.config">
      <Link>App1Connections.config</Link>
      <DependentUpon>Web.config</DependentUpon>
    </Content>
    <Content Include="..\App1Config\App1Authentication.config">
      <Link>App1Authentication.config</Link>
      <DependentUpon>Web.config</DependentUpon>
    </Content>
  </ItemGroup>

(similarly for Application2, but the links point to different configs)

In the IDE, on the properties for each of these links I set "Build Action" = "Content" and "Copy To Output Directory" = "Do not copy"

Finally I modified the respective csproject files to remove the files from the bin directory if they existed from a build of the other project by defining the <Target Name="BeforeBuild"> ...  </Target>

In the root directory, I added individual folders for the Unique pages of each individual application.

Now, I add the common files to both projects, and since they are in the same physical directory, they both point to the same physical file.  I only add the unique application folders to their respective Web Application Projects.

When I publish, I just make sure that under Copy, "Only files needed to run this application" is selected (which is default).  Now the common files will each be copied to the respective servers, but the unique files will only be copied for the appropriate application.
0
 
LVL 3

Author Comment

by:davisnw
ID: 20067151
BTW: another neat trick I discovered:

In order to edit the csproj files with full Intellisense, do the following:

Right click on the Project and select "Unload Project"
Right click on the Project agian and select "Edit Project"
When done editing, Right click on the project and select "Reload Project"
0
 
LVL 3

Author Comment

by:davisnw
ID: 20067268
One other part of the solution that I forgot to mention:

In order for you to be able to debug the individual applications within the IDE, you may find it necessary to add a process to copy the appropriate web.configs from their individual configuration directories to the root application directory.  The links will take care of publishing, but they don't seem to get processed for a build within the IDE.

For example:

<Target Name="BeforeBuild">
   <Copy SourceFiles="..\App1Config\Web.config;..\App1Config\App1Authentication.config;..\App1Config\App1AppSettings.config;..\App1Config\App1Connections.config" DestinationFolder=".\" />
</Target>
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20084417
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question