|
Introduction
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.
Scenario
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.
Steps Overview
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.
Step 1: Adding a web deployment project to your website solution that will create a single DLL for the website
- The first step is to make sure you have added the proper namespaces and avoided class name duplications within a namespace before going to step 2.
- Add a web deployment project into your website solution. This can be done by right clicking on the website project and choosing 'Add Web Deployment Project' option.
Note: This option will be available once you have installed the Web Deployment Setup.
- Add a strong name key to the solution which we will be using to sign all the DLLs.
- Now, we have to set the deployment project properties. Right-click on the deployment project and click 'Property Pages'.
- Go to the 'Output Assemblies' tab, and choose the 'Merge all assemblies to single assembly' option (this is the default option), and give the assembly name.

- Next, go to the Signing tab and choose the 'Enable strong naming' option, and choose the strong name key that you have created in step 3.

- Also check the option 'Mark the assemblies with AllowPartiallyTrustedCallersAttribute (APTCA)'. This will make the DLL partially trusted, and thus the SharePoint site can use them. Click on OK.
- The Data Access, Business Logic, or any other assemblies that are a dependency to the web application must be strong named with a strong name key.

- Also, we have to allow partially trusted callers for the dependency DLLs. This can be done by opening the Assembly.info file of the Class Library project and putting the following line of code as shown above:
[assembly: System.Security.AllowPartiallyTrustedCallers]
- Build the deployment project under Release mode (any mode).
- Go to the path where the deployment project has put the output. Here, in the bin directory, you will find the web deployment DLL file. If there are any dependency projects such as the Business Layer and the Data-Access Layer, those DLLs also will be copied to this bin folder.
Now, we have the DLLs that can be used in our SharePoint site for using the same functionality as in our ASP.NET site.
Step 2: 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
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:
- Copy the bin folder contents from your ASP.NET deployment folder into the bin folder of your SharePoint site (usually in C:\Inetpub\wwwroot\wss\VirtualDirectories\<PortNo>\bin).
- Open the web.config file of your SharePoint site.
- Add the following line in under the
<PageParserPath> section:
<PageParserPath VirtualPath="/*" CompilationMode="Always"
AllowServerSideScript="true" IncludeSubFolders="true" />
- Register the assemblies that will be used in the SharePoint site (web deployment DLL which has the code-behind code, the Business Layer and Data Access DLLs) as a SafeControl. For this, add the following under the
<SafeControls> section:
<SafeControl Assembly="SampleWebSiteAssembly"
Namespace="SampleSiteNamespace" TypeName="*" Safe="True" />
- Also add all the other dependency DLLs that your site will be using. Note that all these DLLs must be strong named and marked
AllowPartiallyTrusted.
- Change the trust level from Minimal to Medium by changing the
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.
Step 3: Open your created SharePoint site in SharePoint Designer and import the web pages from our web application
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:
- Open your SharePoint site in the SharePoint Designer (in this article, we are using SharePoint Designer 2007).
- Click on File-->Import-->File. This will open the Import dialog box.
- Click on 'Add File' and choose the ASPX page that you have created from your local folder. Please note that you have to take the ASPX file from the deployment folder and not the ASPX page that is there in the project. Click OK. This will import the page into your SharePoint site.
- Now, double-click on the newly imported page. Click on the Split option in the Design/Split/Code option in the centre pane (bottom left of the pane).
- As soon as you do this, you will see in the designer window an error that says: The Master Page file cannot be loaded. This is because the master file that we have used in the project is different from the master page that the SharePoint site uses. You can either import the master page or use SharePoint's default master page. In this article, we are going to use SharePoint's default master page.
- Change the '
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.
- Delete the '
CodeFile' attribute from the Page directive as this is only for Visual Studio purposes.
- Now, change the
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'.
- After mapping the place holders of the ASP.NET page to that of the SharePoint master page, the page will render in the design view with the default master page.
- Now, we have to change the
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.
Now, we have our ASP.NET site as a SharePoint site, ready to run with the same look and feel of the SharePoint site.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 52 (Total in Forum: 52) (Refresh) | FirstPrevNext |
|
 |
|
|
Hi... nice article.
I am a beginner to MOSS.
I tried out your article with a very simple asp.net website and it works great.
But now I am into problems when I try it with a more complex application involving Object Data Source and xsd Dataset i.e. involving database connectivity.
I have a Masterpage and a single web form in the website. Also I have cs files named UserBLL.cs and UserDAL.xsd in App_Code folder.
On the click of a button I fill the gridview on the page.
I successfully converted the Masterpage and the form into a shareopoint site.But when i run it and click on the button to fill the grid, it gives me below error.
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] MOSS2_XSDTableAdapters.UsersTableAdapter.InitConnection() +56 MOSS2_XSDTableAdapters.UsersTableAdapter.InitAdapter() +342 MOSS2_XSDTableAdapters.UsersTableAdapter.GetAllUsers() +22 MOSS2_NS.UsersBLL.GetUsers() +44
[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +308 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29 System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +480 System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1960 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69 System.Web.UI.Control.EnsureChildControls() +87 System.Web.UI.Control.PreRenderRecursiveInternal() +50 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
Do let me know if any further clarification is required.
Thanks in advance...
Cheers ~$~
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
hi ..
I'm new to this technology..
I have problem in step1: No.6 with: Enable strong naming; I couldn't find the key file location ?
shell I create this key file or what?
Thanks,
Best Regards, The Glory
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hi Srivatsan,
I am trying to integrate a very simple testing vb.net application into sharepoint. The application do have a label, input textbox and a submit button. When submit button clicked, the label should display the text in input textbox.
I followed all the step in your article, except Step 1 (8) and (9) because I do not use any dependents DLLs. But I getting error as below when I browse to the page.
Server Error in '/' Application. --------------------------------------------------------------------------------
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
This is my SafeControl setting
and this in the aspx page language="VB" masterpagefile="~masterurl/custom.master" inherits="TestV1.MyIndex, ExApps"
Between, I trying to put inherits="TestV1.MyIndex.ExApps" and inherits="TestV1.ExApps"
but it giving me error like Parser Error Message: Could not load type 'TestV1.ExApps'.
Actually, I like to integrate a more complicated application into sharepoint, which involved database store and retrieve. Unfortunately, I am stuck even in such a simple application. Highly appreciate all your help. Thanks!
Regards hlsiow
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hi srivatsan24,
i am trying to convert asp.net website to share point site.. i created web deploymnet project and copied to production share point website..i imported two .aspx files and my custom master page.
The problem is when trying to open My.aspx page it is saying Value does not fall within the expected range
some body saying
You cannot copy and paste the aspx page using SharePoint designer. First, export the aspx page using SharePoint designer to a physical file. Open the aspx page with notepad and search on the mso:PublishingPageLayout. You will notice your development portal URL is there. http://xxxdevelopmenturl/_catalogs/masterpage/BlankWebPartPage.aspx, Blank Web Part Page Replace your development URL (xxxdevelopmenturl) to the production URL and save it. Open your production site with SharePoint Designer and import the modified aspx page.
i am not able to find (mso:PublishingPageLayout) this in my aspx page.How to find this..
Or How to solve above error...
Regards
jagadeesh(MicroNetTechnicks)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
just change WSS_Minimal to Full in the trust node in the site's web.config. that should solve your problem.
Srivatsan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hai friend, I have created some Asp.Net web pages.And i have created one virtual directory in IIS and using that WebApplication. But i want to know what is the need to include Asp.Net Pages to Sharepoint site.(My question seems silly,I am new to sharepoint). Please tell me..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
you can either put it in the sharepoint site or you can put it in the layouts folder. or you can even have it in any virtual directory. All that is required is for the sharepoint site to access that and you give the URL of the page.
Srivatsan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
The Problem ------------- I have developed one webapplication that is Income and expenses and database is sqlserver 2005
Ide is vs 2005 with asp.net 2.0
i want to integrate this webapplication with sharepoint server as a sharepoint site defination or template..
i have installed sharepoint designer in my local system But sharepoint server is production system means remote sustem..
What i have developed --------------------------
i have developed webparts by using visual studio class library But in the webpart i have created dydnamically buttons and events..its working fine..
By using designer also i integrated .aspx file by using default masterpage and custom masterpage.by adding assemblies in
sharepoint port bin folder..and adding safecontrol in web.config file
But designer is not supporting to add .cs files and events also..
so please help me any procedure is there to integrate asp.net website with sharepoint server means already developed
website using like sharepoint port...
The Environment i Have used -----------------------------
operating system:windows server 2003
Visual studio 2005 Windows services 3.0 Visual studio 2005 extensios for sharepoint templates..
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Why do you need to add .cs file into the sharepoint site??? You have to compile the .cs files and create a dll which you will have to put in the Sharepoint site's bin directory. Please do so if you have done otherwise.
Srivatsan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
following error is what iam getting.
i have created namespace and it is working fine locally as a website. is it something related to gac . please help us.
also if you provide me your email id i can send you the code , so that you can help me.
thanks for the timely help you are rendering to us.
Server Error in '/' Application. --------------------------------------------------------------------------------
Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'MyAccNameSpace.MyAccountDeployment'.
Source Error:
Line 1: <%@ Import Namespace="MyAccNameSpace" %> Line 2: <%@ page language="C#" autoeventwireup="true" MasterPageFile="~masterUrl/default.master" Inherits="MyAccNameSpace.MyAccountDeployment" %> Line 3: Line 4: <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
Source File: /MyExpenses.aspx Line: 2
-------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Server Error in '/' Application. -------------------------------------------------------------------------- Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.
Source Error: [No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\45230dcf\af138ac0\App_Web_b949e1f6-2f5e-4220-a285-6e6904e7565a_-1638062225.yfp8fbge.0.cs Line: 0
Stack Trace:
[SecurityException: That assembly does not allow partially trusted callers.] DataLayer.Expense..ctor() +0 BusinessLogic.ExpenseBL..ctor() +37 MyAccountNameSpace.Expenses..ctor() +37 ASP.b949e1f6_2f5e_4220_a285_6e6904e7565a__1638062225..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\45230dcf\af138ac0\App_Web_b949e1f6-2f5e-4220-a285-6e6904e7565a_-1638062225.yfp8fbge.0.cs __ASP.FastObjectFactory_app_web_b949e1f6_2f5e_4220_a285_6e6904e7565a__1638062225_yfp8fbge.Create_ASP_b949e1f6_2f5e_4220_a285_6e6904e7565a__1638062225() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\45230dcf\af138ac0\App_Web_b949e1f6-2f5e-4220-a285-6e6904e7565a_-1638062225.yfp8fbge.1.cs System.Web.Compilation.BuildResultCompiledType.CreateInstance() +49 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +115 System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31 System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40 System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +139 System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +128 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +161 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
ok the problem is that you have not allowed partially trusted callers. Please read the article where is talks about Partially trusted callers. n the Assembly.cs you have to do some change. Please let me know if this helps. I am actually not available for the rest of the month. But i will try to help you if i find time. My personal Email Id is srivatsan24@gmail.com
Srivatsan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hai friend, After successful creation of my project i cant add "WEB DEPLOYMENT PROJECT" in to my Solution. Please Let me know.. Thank you. 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
You have to install the web deployment setup for visual studio. You can install it from http://msdn.microsoft.com/en-us/asp.net/aa336619.aspx And after that you just have to right-click on the website and click on 'Add Web Deployment project'.
Srivatsan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
It seems to have been removed of the article, why?
In my opinion this article could be much better if it was ilustrated with more screenshots, and more detailed in steps. Explanations leave gaps, I haven't been able to reproduce the practice. Yes, I am not a wise man, I know.
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
Hello Sri, I followed the steps given by you. I am getting following error while accessing page in SharePoint: Server Error in '/' Application. --------------------------------------------------------------------------------
Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'WebApplication2.WebApplication2.csproj_deploy'.
Source Error:
Line 1: <%@ Page Language="C#" MasterPageFile="~masterurl/default.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2.WebApplication2.csproj_deploy" %> Line 2: Line 3: <asp:content id="ContentPlaceHolder" contentplaceholderid="PlaceHolderMain" runat="server" xmlns:asp="#unknown">
Source File: /default.aspx Line: 1
-------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
I also cheked the assembly name and namesapce which are inherited from deployed application, still error persist. What can be the reason?? Waiting for ur reply. Thanks...
modified on Monday, August 11, 2008 9:13 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
There is definitely problem with the namespace of the project or the DLL is not placed in the bin folder. Please double check these. I dont think that there is any means by which this error would occur. Also open your DLL using the MSIL Disassembler usually found in Start-->All Programs-->Microsoft .NET Framework SDK V2.0-->Tools and check the namespace.
Srivatsan
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Thank you Sri for your reply
In the mean time I got following link : http://blogs.msdn.com/cjohnson/archive/2006/09/05/740498.aspx[^]
In this different method is given for converting Asp.net site into sharepoint. In this blog no strong key is generated but changes are made in aspx pages. I want to know what can be the cons and pros of the method explained by you and the method explained in this blog.
Thank You once again 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
In my method also you need not strong name. I have asked to strong name is because some will want to put it in the GAC and use it for different applications. thats why. Else both are the same. You can either have the pages imported into the site as i have mentioned or you can put it in the layouts directory. If you import it in the application using Sharepoint designer (as i have mentioned), the adv is you need not copy these files separately and move to the prod server during deployment. It will come part of the package. Else both are same.
Srivatsan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|

|