来自Codeproject
http://www.codeproject.com/KB/sharepoint/ASPNET_to_Sharepoint.aspx
There are a lot of ASP.NET web developers who are moving to SharePoint site creation. This article will explain in detail how an ASP.NET webpage developed in Visual Studio can be converted into a SharePoint site. If there is a requirement for a website created in Visual Studio, just the old fashioned way with the code-behind logic and other layers like Data Access and Business Logic, to be converted into a SharePoint site, and still make it work the same way with the same code-behind, you are in the right place. This article deals with right that.
There is an ASP.NET website solution that contains three layers viz. Code-Behind Layer, Business-Logic Layer, and the Data-Access Layer. The website has functionality implemented in all these layers. The Business-Logic and the Data-Access layers are in a different Class Library project. We have to convert this website into a SharePoint site. Also, we want to use the same look and feel of the SharePoint site. So, we have to use the SharePoint master page instead of the one that we are having (we can also use our own master page; just that you have to add some default Place Holders that are required for the SharePoint functionalities). In this article, we are dealing with a website with the same look and feel as a SharePoint site.
There are three steps that are explained in the article which will help you to transform your ASP.NET Web Application into a SharePoint site.
Step1: Add a Web Deployment Project to your website solution that will create a single DLL for the website. This step will give us the code-behind DLL and other dependency DLLs for the website.
Step2: Copy the bin folder items (DLLs) into the SharePoint site, and tweak the web configuration file of the SharePoint site to use the copied DLLs.
Step3: Open your created SharePoint site in SharePoint Designer and import the web pages from our web application and link it to the appropriate DLLs.
Note: This option will be available once you have installed the Web Deployment Setup.
[assembly: System.Security.AllowPartiallyTrustedCallers]
Now, we have the DLLs that can be used in our SharePoint site for using the same functionality as in our ASP.NET site.
The next step in our SharePoint site creation is linking the DLLs that we have created in the procedure above into our already existing blank SharePoint site. There are also some changes that are required in our SharePoint site's web.config file (By default found in C:\Inetpub\wwwroot\wss\VirtualDirectories\<PortNo>). Following are the steps that has to be done:
<PageParserPath>
section:<PageParserPath VirtualPath="/*" CompilationMode="Always"
AllowServerSideScript="true" IncludeSubFolders="true" />
<SafeControls>
section:<SafeControl Assembly="SampleWebSiteAssembly"
Namespace="SampleSiteNamespace" TypeName="*" Safe="True" />
AllowPartiallyTrusted
.level
attribute of the <trust>
section from 'WSS_Minimal
' to 'WSS_Medium
'.Note: You can also do the following to enable the original errors being shown in the SharePoint site screen for easy error identification. You have to change the mode
attribute of the <customErrors>
section to Off
. Also, change the CallStack
attribute of the <SafeMode>
section to True
.
Let us say we have a link in our SharePoint site in the left navigation panel, on the click of which you want to display one of your ASP.NET pages in the content place holder of the SharePoint site. This is what we do:
MasterPageFile
' attribute in the Page
directive of the web page to a value same as the default.aspx in the SharePoint site, which is ~masterurl/default.master.CodeFile
' attribute from the Page
directive as this is only for Visual Studio purposes.ContentPlaceHolderID
of the place holders in the ASP.NET page to a relevant SharePoint site place holder. For example, the ContenPlaceHolderID
of the main content place holder of the ASP.NET page must be changed to 'PlaceHolderMain
'.Inherits
attribute to add the assembly name. For example, if the namespace is 'SampleSiteNamespace
' and the assembly name that the page uses for code-behind is SampleWebSiteAssembly, then we set Inherits="SampleSiteNamespace.SampleWebSiteAssembly"
, and this assembly must be in the bin of the SharePoint site as added in Step 2 above.