How to integrate Template published as web applications with the web applications that use this wrapper?
Asked Answered
T

2

6

I have the following case :

My current projects are like that :

A master page and set of pages.aspx inherit the layout from the master page.

Now i want to make it on large scale . So what i want to do is :

Two types of projects published as two separate web applications(Loosely Coupled) :

  1. The wrapper (the main general template for all other web
    applications) replace (the master page which used in the same
    application),this project used as a framework or template like this :(Header,Footer), [(Sidebar(Menu),Body) dynamic according to the web application which use the wrapper] .

enter image description here

  1. Any web application will fill the wrapper in two parts (The body and The menu) dynamically.

How to integrate the wrapper and the web applications which should use this wrapper and both of them published as two separate web applications ?


NOTE:

The main point , I don't want every change to the package(the wrapper) to republish all the applications which use this package(the wrapper) to take the update.

Tso answered 22/11, 2016 at 9:59 Comment(7)
can u breif what you are trying to do ..Kaykaya
@Webruster well,if i want to create a web application,usually i create a master page in the same project and use it.Now i don't want to do that because i have a lot of web applications that have to use the same master page ,so i want to reuse it and make a separate project for this master wrapper,so if i change something in this wrapper i don't have to change all my web applications which use it and publish all of them. Briefly i want an example to clarify this idea (the integration between (the wrapper with the details in my question) and (any web application which should use this wrapper) .Tso
@Webruster : Could you tell me if you want more details please ?Tso
no !! i am also looking for the best feasible way!!Kaykaya
@Webruster : many thanksTso
Is it acceptable to change the wrapper application whenever a child application changes?Jonathanjonathon
@Jonathanjonathon of course not , i don't want to change any of them when any change happens to one of them . It's a pain to change all the applications when i make a change to my main templateTso
J
3

I have solved this problem in the past by using NuGet packages. They can be as complex or as simple as you need them to be. A basic master page layout can be achieved simply by manually creating a .nuspec file, building it using the command line tool and hosting it on the file system (local or network).

Add a config file to the root of your template project - call it template.nuspec and add the following:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>    
    <id>MyAppTemplate</id>
    <version>1.0.0</version>
    <description>A template web application</description>
    <authors>Me or my company</authors>
  </metadata>  
  <files>
    <file src="Site.Master" target="content\Site.Master" />
    <file src="Site.Master.cs" target="content\Site.Master.cs" />
    <file src="Site.Master.designer.cs" target="content\Site.Master.designer.cs" />
  </files>
</package>

Note the target is "content" - this will drop the master page in the project root wherever the NuGet package is installed. You may also wish to change the namespace of the master page to $rootnamespace$ as this will do a source code transformation that will make the master page part of the same namespace as the rest of your project.

From the command line, you can then just call nuget.exe pack path\to\nuspec\file

which will result in a .nupkg file being created. For local development I usually drop it in C:\NuGet\Local, although that could be a network share \\MyShare\InternalNuget or there are solutions like ProGet or TeamCity if you want to take it further.

Then in Visual Studio you can add it as a package source:

Tools -> NuGet Package Manager -> Package Manager Settings -> Package Sources

Click on the plus sign and add your folder / unc path / url and then you can reuse it in any other project.

As a general rule it is better to allow NuGet to overwrite the existing Site.Master when you create the project, and then don't edit the files, as this allows you to manage changes centrally using NuGet package versioning. However if you do wish to make project specific changes you may do so, you just have to remember not to let the NuGet package overwrite the project version on subsequent updates.

You can include all types of file from your template project. This includes .ascx user controls, css and javascript files as well compiled or uncompiled base pages (inheriting from System.Web.UI.Page). The possibilities are endless. With a <asp:contentplaceholder/> and appropriate CSS, you could use a generic menu in most projects via a user control, but still substitute it for a more complex menu in other projects without modifying the main template.

EDIT:

I guess it could be possible to achieve the desired effect (at least for relatively simple content) by splitting the wrapper into two parts. The first would be a NuGet package containing the master page. This master page could contain iframes for the header and footer in the diagram, content placeholders and css and script tags for the common styles and javascript.

The second part of the wrapper would be a separate application, hosting the content of the iframes and the .css and .js files. Major changes like adding a new javascript library would still require updating the Master Page, but minor changes like adding a new function or css class or changing a brand or logo could be accomplished by changing the wrapper files and republishing it. Sort of like hosting your own simple CDN.

Master page looks like this:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="$rootnamespace$.SiteMaster" %>
<html>
<head runat="server">    
    <title><%: Page.Title %></title>    
    <link href="https://example.com/mywrapperapplication/styles/mywrapper.css" rel="stylesheet" />
</head>
<body>
    <iframe src="https://example.com/mywrapperapplication/header.html" />
    <form runat="server">                
        <asp:ContentPlaceHolder ID="MenuContent" runat="server"></asp:ContentPlaceHolder>            
        <asp:ContentPlaceHolder ID="BodyContent" runat="server"></asp:ContentPlaceHolder>
    </form>
    <iframe src="https://example.com/mywrapperapplication/footer.html" />
    <script type="text/javascript" src="https://example.com/mywrapperapplication/scripts/mywrapper.js"></script>
</body>
</html>

Then you have static content or a simple application deployed at https://example.com/mywrapperapplication

with 4 (or more) files:

header.html --or aspx or whatever
footer.html
/scripts/mywrapper.js
/styles/mywrapper.css

Any change you make to any of these files, will automatically be propagated in the wrapped application as they are linked from the master page. You would only need to republish the wrapped application if you wanted to add an additional file for example

<link href="https://example.com/mywrapperapplication/styles/mynewstyles.css" rel="stylesheet" />
Jonathanjonathon answered 25/11, 2016 at 13:24 Comment(8)
Could You provide a simple example pleaseTso
The main issue here is : if i publish the package application on server, and publish the consuming web applications .then i want to make a change to the packagethe template ,i don't want to republish my consuming applications again !! this's why i want to separate them in to projects .Could you clarify this point please ?Tso
I don't think there is a solution to not re-publishing them. Even if they were projects, you would still end up with a published website deployed to your server, that was independent of the source. You could maybe do something with iframes, but even if it gets you out of re-deploying I don't see how it gets you out of regression testing every application with every change of the template.Jonathanjonathon
This's the main point , i don't want every change to the package to republish all the applications which use this package to take the update.Tso
I would suggest that will make your applications very tightly coupled in fact. You cannot make a non-trivial change to the parent without needing to test the effect on all child applications. That was exactly the problem I faced that first led me to develop NuGet template packages, because in order to share the layout, css and user controls they were sharing the same solution.Jonathanjonathon
but i have many applications that suppose to use this template , and it will be a pain to tell all the developers to republish all their applications , every time i make a change in the main template .that's why i want them loosely coupled. the main template work just as a wrapper allowing me to pass menu of the consuming application.Tso
@AnynameDonotcare I have edited - think it might do roughly what you want nowJonathanjonathon
it made me a little confused . i have two types of applications : 1-The wrapper(you suggest to be a package) 2-the consuming application . now you said that the wrapper will be two separate applications !! Could you clarify the idea with a simple example illustrate the idea,please ?Tso
L
2

Why not publish the consumed applications as User Controls, and have the master page (your wrapper) inject them programmatically, similar to what DotNetNuke does.

https://msdn.microsoft.com/en-us/library/c0az2h86.aspx

The User Controls can be compiled separately and won't need to be recompiled when the wrapper is changed.

Lapstrake answered 1/12, 2016 at 3:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.