Click here to Skip to main content
Email Password   helpLost your password?

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

  1. 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.
  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.
  3. Note: This option will be available once you have installed the Web Deployment Setup.

  4. Add a strong name key to the solution which we will be using to sign all the DLLs.
  5. Now, we have to set the deployment project properties. Right-click on the deployment project and click 'Property Pages'.
  6. 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.
  7. Screenshot - output_assembly-Pic1.jpg

  8. 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.
  9. Screenshot - signing-pic2.jpg

  10. 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.
  11. 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.
  12. Screenshot - assemblyinfo-pic3.jpg

  13. 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:
  14. [assembly: System.Security.AllowPartiallyTrustedCallers]
  15. Build the deployment project under Release mode (any mode).
  16. 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:

  1. 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).
  2. Open the web.config file of your SharePoint site.
  3. Add the following line in under the <PageParserPath> section:
  4. <PageParserPath VirtualPath="/*" CompilationMode="Always" 
       AllowServerSideScript="true" IncludeSubFolders="true" />
  5. 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:
  6. <SafeControl Assembly="SampleWebSiteAssembly" 
       Namespace="SampleSiteNamespace" TypeName="*" Safe="True" />
  7. 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.
  8. Change the trust level from Minimal to Medium by changing the level attribute of the <trust> section from 'WSS_Minimal' to 'WSS_Medium'.
  9. 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:

  1. Open your SharePoint site in the SharePoint Designer (in this article, we are using SharePoint Designer 2007).
  2. Click on File-->Import-->File. This will open the Import dialog box.
  3. 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.
  4. 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).
  5. 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.
  6. 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.
  7. Delete the 'CodeFile' attribute from the Page directive as this is only for Visual Studio purposes.
  8. 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'.
  9. 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.
  10. 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.
 
 
Per page   
 FirstPrevNext
GeneralConverting asp.net website to sharepoint website
Member 2407903
2:10 8 Mar '10  
Hi,
We developed a website using visual studio 2003, asp.net and sql server. Now I need to vonvert that website into sharepoint website. We didn't used master pages and place holders in asp.net website. Can you give me the process for converting asp.net (vs 2003) website into sharepoint website (MOSS 2007, sharepoint designer 2007). Please try to reply me.

Thanks,
Manoj
manojpadhuri@gmail.com
GeneralServer block is not well
gayajegg
14:57 22 Feb '10  
I think i followed all the instructions but still get this error

An error occurred during the processing of /FormServerTemplates/Default.aspx. The server block is not well formed.

pls help!
GeneralAn error occurred during the processing of . The attribute 'autoeventwireup' is not allowed in this page.
gayajegg
14:13 22 Feb '10  
Hi,
I am stuck with this error.. I imported the aspx file into sharepoint desginer.. and when i try to view the page i get the follwoing error! pls help!
GeneralRe: An error occurred during the processing of . The attribute 'autoeventwireup' is not allowed in this page.
gayajegg
14:58 22 Feb '10  
I fixed this by resetting to site definition--->under site settings/look and feel. now stuck with a new error

An error occurred during the processing of /FormServerTemplates/Default.aspx. The server block is not well formed.
General.xsd files
ajingar
4:43 3 Feb '10  
Hi Srivatsan,

I've used your technique over and over again, and they are very good, thank you.

However, I am at a stumbling block now. We have a project (that someone else has written in asp.net), and it is my job to place it into SharePoint. The problem is, they are using .xsd files, any ideas how I can proceed with them?

Thanks, Ashok
AnswerRe: .xsd files
srivatsan24
17:41 3 Feb '10  
All you got to do is use it in the same way as an ASP.NET application. Just put it in the same relative path as the ASP.NET site. Relative to the file that uses it.

Srivatsan

Generalaspx page not populating in IIS
shibu.sebastian
7:55 11 Jan '10  
My asp.net application working fine on asp.net development server 32 bit(Visual Studio 2005). but when viewing the pages on production server(64bit) the page controls are not populating at all.

I am runing the programe in sharepoint context. deployed the program into sharepoint as DLL file imported all the aspx pages into shartepoint designer, but when viewing it on browser page is not populating with any data.

I copied the connection string into Shartepoint web.config file and i tried both windows and sql sever authentication. but still not populating.

please have a look at my ConnectionString on web.config


Any thoughts will be highly appreciated.
AnswerRe: aspx page not populating in IIS
srivatsan24
18:01 11 Jan '10  
Please use connection string as mentioned in the below site
http://www.techtoolblog.com/archives/webconfig-connection-string-settings-in-net-20[^]

It is advisable to use the connectionstring tag than using it in appsettings

Srivatsan

Generalasp.net web application not workong on sharepoint. global.asax problem [modified]
shibu.sebastian
1:00 6 Jan '10  
I followed ur steps in converting the asp.net web site to a sharepoint site.
i am using the web application instead of asp.net site.
the page working fine on sharepoint designer , but viewing it on browser, it displays the following error message.

Compiler Error Message: CS0433: The type 'ASP.global_asax' exists in both 'c:\WINDOWS\microsoft.net\Framework64\v2.0.50727\Temporary ASP.NET Files\root\e596ddcb\af72c2f2\assembly\dl3\b874e785\bc2d4b4c_188eca01\EmployeeDirectory.DLL' and 'c:\WINDOWS\microsoft.net\Framework64\v2.0.50727\Temporary ASP.NET Files\root\e596ddcb\af72c2f2\App_global.asax.8kqujh01.dll'


look at my specs below

connection to the database configured on web.config of the web application see the section below

add key="sEmployee_DirectoryDBConnectionString" value="Provider=sqloledb;Data Source=aber-dsql-001;Initial Catalog=Staff Directory;Integrated Security=SSPI";
. I copied the above settings to the corresponding section of sharepoint site's web.config file.


Main assembly Employee_directory.dll
Web deployment project assembly : EmployeeDirectory.dll


I copied these DLL files to the bin directory of the sharepoint site and tweak the web.config file as per your steps. But every time when on browser i am getting the above ASP.Global_asax problem.

At this stage i am confused with the global.asax file becuase sharepoint got its own global.asax file. what we need to do with the global.asax file of the web application. do we need to copy it to the sharepoint.

Looking forward to hear from you

modified on Wednesday, January 6, 2010 6:16 AM

GeneralConverting ASP.net web application with events and <% code
michellejohnsonaidmatrix
9:46 3 Dec '09  
I am getting errors when I try to convert a users application to SharePoint. I have read that any Eval statements need to be convert to a code behind. They are many of these because the user used the gridview to automatically populate the grid. This would be a lot of re-work. There are other issues also, Any ideas?
GeneralNot able to run Asp.net Website on Share point
mailneerajsehgal
20:36 5 Nov '09  
I tried your written steps for deploying asp.net web site to moss2007 but ,I got a error for user controls that "*.Ascx are not allowed here"
QuestionNo Namespace
ajingar
7:37 2 Oct '09  
Hi Srivatsan24,

Thanks for your article. I have a question for you - my web application only has 2 files and some images.

The 2 files are an WebGF086.aspx page and an WebGF086.aspx.vb page (web page and code-behind page). That's it.

I am not using any namespaces, so will your method work for me?

My .aspx page begins:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="WebGF086.aspx.vb" Inherits="WebGF086" %>

and my code-behind starts like this:

Partial Class WebGF086
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Forgive me if I sound very amateur (that's because I am!).

Any help would be greatly appreciated.

Kind Regards, Ashok
AnswerRe: No Namespace
srivatsan24
12:12 2 Oct '09  
Please put a namespace for your code behind and do whatever is mentioned in the article. Because the keywords codeFile is all visual studio centric.
(or if you do not want namespace)
just add a web deployment project and compile it to a single assembly. In the aspx page, i think you can just leave the inherits as is. The inherits has the Namespace.classname. So if you dont have a namespace, then just put the class name. But i would advice putting a namespace as it is always a best practice.

Srivatsan

QuestionRe: No Namespace
ajingar
12:31 4 Oct '09  
Hi Srivatsan,

Thanks for your quick response.

Can you give me an example of how to write a namespace for my 2 files (WebGF086.aspx and WebGF086.aspx.vb) but written in vb please?

Do I need to create a separate file to create the namespace, or do I create it within the WebGF086.aspx.vb file?

Would I have to re-write the code-behind file to something like this for example?

Namespace Ashok

Partial Class WebGF086
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'The remaining code in my code-behind page...

End Sub

End Class
End Namespace


Regards, Ashok
AnswerRe: No Namespace
srivatsan24
13:39 4 Oct '09  
you are right about the namespace code.
you can also refer any site that will help you in creating a namespace

you have to write it in your .vb file itself.

Srivatsan

QuestionRe: No Namespace
ajingar
1:22 5 Oct '09  
Hi Srivatsan,

Once again, thank you for your quick reply. I've done the namespace now (seems ok), so thanks.

In step 9 you said:

"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"
Well, I have no Class Libarary project, so shall I just ignore it?

Regards, Ashok
AnswerRe: No Namespace [modified]
ajingar
3:12 5 Oct '09  
Hi Srivatsan,

Thank you VERY VERY much indeed, I finally got my site to work within SharePoint (MOSS)!   Big Grin

I ignored step 9 as I didn't have a Class Library project anyway, but the rest I followed just like you said.

One thing I did come across, which other people might find useful:

The first time I loaded the page after following your instructions I got this message:

<b>Parser Error Message: This page allows a limit of 200 controls, and that limit has been exceeded.</b>

The solution is to go into the web.config file and go to the <configuration> section, then go to the <sharepoint> tag, then change the MaxControls attribute to 500 say.

Then there is no restriction. Everything worked fine!

Thanks Srivatsan! Jai Ram!   Thumbs Up Big Grin

modified on Tuesday, October 6, 2009 11:50 AM

GeneralToo much Words! [modified]
cl.kcitwm
18:43 12 Aug '09  
Too much words!

Only 4 Steps:

1. Create Web Application Project instead of web site.
2. Sign every project.
3. Every page's Inherits page property like this:
Inherits="Default,DllName,Version=,Culture=,PublicKeyToken=".
4. Create a Site Definition Project to deploy.

modified on Thursday, August 13, 2009 12:50 AM

GeneralRe: Too much Words!
srivatsan24
17:38 13 Aug '09  
ok. but what about people who need more explanation. guess a good teacher is one who teaches not only for the brightest in the class but for all. Thanks anyway.

Srivatsan

GeneralGreat article... Very helpful... One question...
Scott Wolfington
6:17 30 Jul '09  
Hello,

Thanks for writing a great article. I've successfully migrated a .NET application to a SharePoint site using your instructions.

Once an app is converted in this way, is there an easy way to roll out the functionality to many SharePoint sites? Maybe through a SharePoint custom feature?

Thanks again.

Regards,
Scott
GeneralParser error - please help
erereere
11:26 26 Jul '09  
Hey man,
Great article. Just what I was looking for.
Though I am not been able to work this thing out for myself.
I have created a website called "foo.com" and a class library "BLL" with namespace "namesp"

(1) In Step1 - 1 When you say "make sure you have proper name space" , could you please give me an example (Is it something what I have given : "namesp.BLL")
(2) In Step1 - 3 How would you add strong key name . ( I presume you would add snk to the class lib? which I have done)
(3) In Step2 - 4 what should be the entry in the web.config.
(4) In Step3 - 10 How would you give "Inherits" in my case.

I have followed the steps but I am constantly getting Pasrser error "Could not load type". If I remove the Inherit tag from the webpage then the page is displayed without error but no data on the page!

I would really appriciate if you can reply to these queries. Also like someone mentioned . If you have a mock code then please put it on the site as it would be extemely useful.



Best Regards
AnswerRe: Parser error - please help
srivatsan24
7:19 27 Jul '09  
Following are the answers for your questions
Question1: namespace MyCompany.Proj1
{
class MyClass
{
}
}

In the above example, the namespace will be MyCompany.Proj1
Question 2:
snkey is correct. you have to associate the strong name to the DLL. Your assumption is correct.

Question 3: <SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Common" Namespace="Microsoft.Practices.EnterpriseLibrary.Common" TypeName="*" Safe="True" />
This is the sample entry to be entered in web.config

Question 4: In the first namepace example, if the code is compiles as DLL with name SampleDLL, then following is the inherits entry
Inherits="MyCompany.Proj1.MyClass,SampleDLL"

I will try to put the code in. Thanks for the feedback.

Srivatsan

GeneralRe: Parser error - please help
erereere
9:27 28 Jul '09  
Thanks Sri for the quick reply. I have tried this but still no luck. it says try to compile the dll etc. I will try further in next few days and see what happens.

Do you think that for the bespoke developement (e.g. accesing custom database etc) best practice is to develope solutions and features?

Many Thanks
GeneralI have a problem with namespace in sharepoint
Sergio Rios
14:17 8 Jul '09  
how can i verify the right namespace and assembly for my project for adding references to my aspx file in a page directive because i got this message: "An error occurred during the processing of . Could not load type 'ExtranetProveedores.NS.ExtranetProveedores.Assembly'. "


thanks !!!
AnswerRe: I have a problem with namespace in sharepoint
srivatsan24
5:28 9 Jul '09  
To verify namespace you can use the .NET disassembler tool. It is usually found in the following location
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\ildasm.exe

If you are using the Web deployment setup, then the setup itself will put the required namespace and assembly in the aspx pages. Use a single assembly so that you can refer the same in al the pages.

Srivatsan


Last Updated 4 Apr 2008 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010