Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share aspx page between projects

We have a solution with multiple web projects, and there are some pages that should be present in several of them. So we'd need some sort of a shared project which contains aspx files, and which can be referenced by other web projects.

Now there are a few implementations out there:

One implementation described by ScottGu which involves building the shared project, and than copying the output aspx into the host project, and referencing the dll of the aspx. This method has the disadvantage that if the apsx gets modified it must been recopied.

Another option, based on David Ebbo's post would be to convert the aspx into ascx-es which can be referenced as custom controls, and than include those custom-control-aspx-es into the host project inside of some placeholder pages. But my concerns are: can all apsx pages transformed into an ascx? I mean there's no Page.LoadComplete event in user controls for example.

And yet another option is to use virtual directories that map into the shared webproject, as described in a Microsoft KB article. The problem again with this method is that the shared aspx-es must be in predefined directories(that is the virtual directory). If the name of virtual directory overlaps a physical directory, the virtual overrides it and no pages from the latter can be used. Is it perhaps possible to merge these two together?

Any thoughts? Thanks in advance P.S. How about debugging the shared pages?

like image 478
jaraics Avatar asked Mar 24 '11 13:03

jaraics


People also ask

Can multiple ASPX pages share the same code file?

Yes. It is technically possible, but it is not a supported way of using ASP.NET and there will likely be gnarly difficulties with it. You should use User Controls or AppCode instead. Save this answer.

How do I add ASPX page to Visual Studio?

Select the Visual C# -> Web templates group on the left. Then, select Web Form from the middle list and name it FirstWebPage. aspx. Click Add to add the web page to your project.


1 Answers

I solved this problem by making shared Class Library that contains .ascx controls. Have not found real difficulties when converting from .aspx pages to .ascx controls. Found this sample by ScottGu really simple and good place to start. http://webproject.scottgu.com/CSharp/usercontrols/usercontrols.aspx.

like image 153
azhons Avatar answered Nov 16 '22 00:11

azhons