Re-usable asp.net web pages
I want to build a re-usable asp.net invoice module. This means that I want to utilise this module from several web-sites. This invoice module wil be indipendant and will have its own business layer with its own business logic.
My question : How do I achieve this seperation with asp.net. The webiste that implements this invoice module should be responsible for the theme ect. So is it possible to have re-usable asp.net pages, in say a dll or seperate project, which inherits the theme of the site that implements this module?
开发者_StackOverflowAny ideas would be appreciated
You can implement a webservice that make the operations and returns clean HTML, then theme it in the final page.
You can have a UserControl in its own dll, and then reference that dll in each web-site that needs it. You will need to make a page on each web-site that contains the UserControl, but that is standard operating procedure. I don't have much experience with Themes or Skins in ASP.NET, but if you need to, you can add Properties to the UserControl that will map into the inner ASP.NET controls to allow themes to work.
You can implement the functionality in an HttpHandler: Deployment is a simple matter of copying the dll and a couple of changes in web.config.
However working with HttpHandlers means a lot of hand-written HTML which may be a bit daunting, especially considering your project is like to be fairly complicated.
HTTP Handlers and HTTP Modules Overview on MSDN. LOTS of additional info here on SO and Google in general.
You could put the Invoice Module project code into UserControls, which your sites reference as a DLL. This is not ideal, because it requires you to create "container pages" that apply themes to the UserControls for the entire Invoice Module project.
To get around this issue, you can create a separate "Invoice Module" web project that resides in it's own directory. Then, each website has a Virtual Directory that points to the Invoice Module.
The Invoice Module pages' Master Page would be implemented in the parent web application to accomplish site-specific theming.
Virtual Directory Example
Assume you have two sites that use the Invoice Module, called "Site1" and "Site2". They could reside in these directories:
- C:\Websites\Site1
- C:\Websites\Site2
In IIS, you set each site to have a Virtual Directory named "InvoiceModule" pointing to:
- C:\Websites\InvoiceModuleContainer\InvoiceModule
In each of the Invoice Module ASPX pages, they would have a a Page Declaration similar to:
<%@ Page Language="C#" MasterPageFile="~/InvoiceModuleMaster.master"
AutoEventWireup="true" Title="Untitled Page" %>
(Note usage of a VirtualPath in the MasterPageFile path.) The InvoiceModuleMaster.master file would reside in the following directories:
- C:\Websites\Site1\InvoiceModuleMaster.master
- C:\Websites\Site2\InvoiceModuleMaster.master
- C:\Websites\InvoiceModuleContainer\InvoiceModuleMaster.master (Not used, just to allow the InvoiceModule project to compile.)
Thus, each site only has to add one Master page file to get the site-specific "theme". And no duplication of the entire Invoice Module is required.
精彩评论