您将如何将 ASP.NET 站点转换为 SharePoint 站点? [英] How would you convert an ASP.NET site to work as a SharePoint site?

查看:38
本文介绍了您将如何将 ASP.NET 站点转换为 SharePoint 站点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一个包含隐藏代码的 ASP.NET 站点.您现在需要将此网站移动到 SharePoint 环境,在该环境中它将成为其自己的 Web 应用程序中网站集的根网站.在不完全重新处理每个页面的情况下实现这一目标的最简单方法是什么?以下是一些选项 - 可能还有其他选项:

  1. 将每个网页转换为用户控件,并将其静态嵌入到自己的页面中.
  2. 将每个网页转换为用户控件,并使用 Web 部件(例如 SmartPart)将其嵌入.
  3. 将每个网页转换为用户控件,并将其放入 CONTROLTEMPLATES.
  4. 将页面放入 _layouts 并视为应用程序页面.
  5. 将页面放入文档库并禁用所有 SharePoint 安全设置.

解决方案

我是这样做的:

首先,您需要为 ASP.NET 站点的二进制文件创建一个 DLL,否则配置所有内容将是无休止的工作.最简单的方法是,如果您有一个 Web 应用程序项目.如果您有一个网站"项目,您可以按照 MSDN (http://msdn.microsoft.com/en-us/library/aa983476.aspx) 这就是我所做的,或者也有一个 Web 部署项目加载项(http://weblogs.asp.net/scottgu/archive/2008/01/28/vs-2008-web-deployment-project-support-released.aspx) 来获取单个 DLL,尽管我还没有尝试过.确保为程序集命名为强名称,以便可以将其部署到 GAC.

1) 使用空白站点"模板,以通常的方式创建 Web 应用程序和网站集.如果您使用的是表单身份验证,您还需要将其扩展到 Windows 身份验证站点以进行下一步.

2) 在 SharePoint Designer 中打开新网站集的根网站(不是,真的).

3) 从菜单中,File->Import->Import Site Wizard,选择 File System 并浏览到您的 Web 应用程序或网站项目,然后打开它(选中Include Subsites"),Next,Finish.

4) 从 SharePoint Designer 的并排导入视图中,选择您的 .aspx 和 .ascx 文件并将它们复制到您的 SharePoint 网站(右键单击并选择发布选择文件").还要复制任何静态内容文件、图像等和您的母版页以供参考.不要复制任何代码隐藏文件.

5) 在 SharePoint Designer 中,修改母版页库中的默认母版页以重现旧的 ASP.NET 母版页(但包括 minimum.master 占位符,以便它也适用于普通 SharePoint 页面).

6) 仍然在 SharePoint Designer 中,对于每个 .aspx 页面,使用菜单格式->母版页->附加母版页并选择默认母版页.如有必要,您还可以重新映射内容占位符.

7) 将 ASP.NET 项目的 DLL 复制到网站根目录的 bin 文件夹(例如 C:\Inetpub\wwwroot\wss\VirtualDirectories\MySharePointWebApplication\bin).它也可以部署到 GAC,这将允许他们在完全信任的情况下运行.如果您的应用程序依赖于其他 DLL,也请复制这些.

8) 修改网站根目录中的 web.config,为 ASP、NET 应用程序 DLL 和您复制的任何其他 DLL 添加 SafeControl 元素,例如<SafeControl Assembly="WebApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d7bb9cf4fbfef0d6" Namespace="WebApplication1" TypeName="*" Safe="True" AllowRemoteDesigner="True"/>.

9) 为您站点的根目录添加一个 PageParser 异常:<PageParserPath VirtualPath="/*" CompilationMode="Auto" AllowServerSideScript="true" IncludeSubFolders="true"/>.

10) 如果您有用户控件,您还需要将目录添加到 SafeControls,例如如果根目录中有 .ascx 文件,请将 <SafeControl Src="~/*" IncludeSubFolders="True" Safe="True" AllowRemoteDesigner="True"/> 添加到您的 web.config.

请注意,最后几个步骤削弱了 SharePoint 的安全模型,因此它应该只是一个临时解决方案.即使这样,您也可能需要修改一些隐藏代码以使用 SPSecurity.RunWithElevatedPrivileges 使其在 SharePoint 应用程序的上下文中工作.如果需要长期解决方案,可以将动态页面或其中的一部分作为用户控件或 Web 部件嵌入到 SharePoint 页面中.

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.

解决方案

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 alternatively 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.

这篇关于您将如何将 ASP.NET 站点转换为 SharePoint 站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆