• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1519
  • Last Modified:

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

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
davisnw
Asked:
davisnw
  • 7
  • 4
1 Solution
 
davisnwAuthor Commented:
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
 
surajgupthaCommented:
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
 
davisnwAuthor Commented:
Add Existing Item creates a copy.  What I need is for it to share the same physical file.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
surajgupthaCommented:
Why not add a link to the other web page from the Menu ?
0
 
davisnwAuthor Commented:
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
 
surajgupthaCommented:
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
 
davisnwAuthor Commented:
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
 
surajgupthaCommented:
Even during development all these rules would apply and thats the reason i think it is not possible
0
 
davisnwAuthor Commented:
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
 
davisnwAuthor Commented:
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
 
davisnwAuthor Commented:
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
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now