tags:

views:

1679

answers:

4

Imagine you have an ASP.NET site which includes code behind. You now need to move this site to a SharePoint environment where it will be the root site of a site collection in its own web application. What is the easiest way of achieving this without completely re-working each page? Here are some options - there may be others:

  1. Convert each web page to a user control, and embed this statically in its own page.
  2. Convert each web page to a user control, and embed this using a web part (e.g. SmartPart).
  3. Convert each web page to a user control, and put it in CONTROLTEMPLATES.
  4. Put the pages in _layouts and treat as application pages.
  5. Put the pages in a document library and disable all the SharePoint security settings.
+2  A: 

Or just use a feature to deploy them to SharePoint in a folder i.e.

http://sharepointserver/yourapplication/default.apsx

As long as the DLL's are available (either in the GAC, which is automatic Full Trust, or in the Bin (write Code Access Security Policies) your pages will work. Heck, you can even use the SharePoint Master page.

Colin
Don't you need to set trust level to WSS_Full for this to work?
Depends? If you deploy to the GAC then the DLL's have Full Trust automatically. If you deploy to the Bin Directory then you determine the trust level through the mentioned CAS Policies.P.S. It is considered Bad Practice to set the trust level to full through the web.config.
Colin
+1  A: 

Using SmartPart is probably the easiest solution. If you already have existing site, I don't see the point of rewriting everything just because of Sharepoint. If you continue development and use sharepoint as the platform then you might want to look into options other than SmartPart also.

Edit. Also you might want to check out this question I asked some time ago

Kuytu
+1  A: 

I would say it depends on how you want the pages to look to the end-user and what you want to do with them in the future.

If you just need it up and running quickly, then try Colin's solution. But I'm not sure what the point is of putting the application into SharePoint then?

If a consistent SharePoint look and feel is important and you want to slowly integrate the pages over time to SharePoint, then I would convert them to user controls and use SmartPart. You will then get the outer chrome/functionality of SharePoint and can update your user controls in time with SharePoint functionality. There is also the easier development experience of user controls rather than dynamically creating them in code (a la traditional web part development).

Alex Angas
The likely scenario is that you want a SharePoint site moving forward, but you want to start from an existing ASP.NET site.
A: 

Here is how I have done this:

First you need to have a single DLL for the binaries of the ASP.NET site otherwise it is an interminable faff to get everything configured. The easiest way is if you have a web application project. If you have a "web site" project you can either convert it as described on MSDN (http://msdn.microsoft.com/en-us/library/aa983476.aspx) which is what I do, or there is also a web deployment project add-in (http://weblogs.asp.net/scottgu/archive/2008/01/28/vs-2008-web-deployment-project-support-released.aspx) to get a single DLL although I have not tried this. Make sure you strong name the assembly so it can be deployed to the GAC.

1) Create the web application and web site collection in the usual way, using the "Blank Site" template. If you are using Forms authentication you will need to extend it to a Windows authentication site also for the next step. 2) Open the root site of the new site collection in SharePoint Designer (no, seriously). 3) From the menu, File->Import->Import Site Wizard, select File System and browse to your web application or web site project, and open it (check "Include Subsites"), Next, Finish. 4) From the side-by-side import view in SharePoint Designer, select your .aspx and .ascx files and copy them into your SharePoint site (right click and select "Publish Select Files"). Also copy across any static content files, images, etc. and your master page for reference. Don't copy across any code-behind files. 5) In SharePoint Designer, modify the default master page in the master page gallery to reproduce your old ASP.NET master page (but include the minimal.master placeholders so that it will work with a vanilla SharePoint page also). 6) Still in SharePoint Designer, for each of your .aspx pages, use the menu Format->Master Page->Attach Master Page and choose the default master page. You can also re-map the content placeholders if necessary. 7) Copy the DLL for your ASP.NET project to the bin folder of the web site root directory (e.g. C:\Inetpub\wwwroot\wss\VirtualDirectories\MySharePointWebApplication\bin). It can also be deployed to the GAC which will allow them to run with full trust. If your application depends on other DLLs copy these also. 8) Modify web.config in the web site root to add a SafeControl element for the ASP,NET application DLL, and any other DLLs you have copied, e.g. <SafeControl Assembly="WebApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d7bb9cf4fbfef0d6" Namespace="WebApplication1" TypeName="*" Safe="True" AllowRemoteDesigner="True" />. 9) Add a PageParser exception for the root of your site: <PageParserPath VirtualPath="/*" CompilationMode="Auto" AllowServerSideScript="true" IncludeSubFolders="true"/>. 10) If you have user controls you will also need to add the directory to SafeControls, e.g. if you have .ascx files in the root add <SafeControl Src="~/*" IncludeSubFolders="True" Safe="True" AllowRemoteDesigner="True" /> to your web.config.

Note that the last few steps weaken the security model of SharePoint, and so it should only be an interim solution. Even then you may need to modify some of your code-behind to use SPSecurity.RunWithElevatedPrivileges for it to work within the context of a SharePoint application. If a longer term solution is required the dynamic pages, or parts of them, can be embedded in SharePoint pages as user controls or web parts.

bill