Home ยป How To Guides | Technology

Integrate BlogEngine 2.0 With Your Existing Website In asp.net 4.0

  14. Sep 2011 by Soan

Integrate BlogEngine Dot 

net With Existing Website Running On asp.net 4.0 Are you looking to set up a Blog on your existing asp.net website and have finalized BlogEngine Dot Net, then this article will help you do the set up.

For those who do not know, it is an open source blog application written in asp.net and C#. It can be easily integrated with your current website to provide the blog (writing articles) facility to your website users. You can go throught he BlogEngine website to know about the featrues it supports.

We also use the same Blog application to power our community on this site here.

BlogEngine 2.0 can be used independently or can be integrated with your exisitng website. We are going to talk about the integration with existing website.

Download BlogEngine 2.0

It can be downloaded from here. The current version of BlogEngine is 2.5 but we are using 2.0 as version 2.5 has some issues with existing website integration and hence we also have not moved on to it yet.
We are using the BlogEngine.NET 2.0 (Web) version. If you want to play with the BE code or want to customize it, you should download the SRC code zip.

Convert BE to work on asp.net 4.0 and IIS 7.0

The BE 2.0 is built on asp.net 3.5. But if your existing website is running on asp.net 4.0, you can easily port BE 2.0 to work on asp.net 4.0 too.
No need to make any special adjustments, just follow the steps and it should be good to work on asp.net 4.0. No need to mention that your existing website should already be running on asp.net 4.0.

If you use Godaddy.com to host your website, you may like to follow the instructions here to set up asp.net 4.0 in Godaddy for your exsiting website..

Integration with existing asp.net 4.0 website

  1. Set up Blog in a subfolder:
    The best and clean approach of using Blog is to keep all the code related to blog in a separate subfolder under your root website. For example, if your website code is placed at YOURWEBSITE.com (called root), then we should set up blog at YOURWEBSITE.com/Blogs. The word Blogs can be anything of your choice.

    So, create a folder Blogs in your website's root.
    YOURWEBSITE.com or ~/ --> Stores all your website code. May contain some other folders too.
    YOURWEBSITE.com/Blogs/ or ~/Blogs/ --> Stores all your BE 2.0 code.

  2. Unzip BE 2.0 and copy to existing website:
    Unzip the BlogEngine.NEt (Web) code that you have downloaded. The file structure would look something like this:

    BlogEngine.NET 2.0 (web) \BlogEngine.Web[All Files and folders]

    Copy all files and folders from above path to YOURWEBSITE.com/Blogs folder. This brings all BE 2.0 code to your existing website and need some folder movements to make it work.

  3. Move [App_*] folders to Root:
    Copy (Copy and paste) all [App_*] folders from YOURWEBSITE.com/Blogs/ to YOURWEBSITE.com. If you already have these folders in your existing website, you can safely add the BE contents in same folders.
    BE 2.0 would have following folders that need to be copied: App_Code, App_GlobalResouces, App_Data. Please remember that you should NOT copy App_Data folder. if you are upgrading BE from earlier BE installation.

  4. Move Bin folder to Root:
    Move (Cut and paste) Bin folder from YOURWEBSITE.com/Blogs to YOURWEBSITE.com. If you already have this folder in your existing website, you can safely add the BE bin's contents in it.

  5. Create Database (Optional):
    BE can run on databse or XML store. If you want to run it on a database, you should follow this step else you can skip it. BE supports multiple DB's like MySQL, MS SQL server etc.You may already have a database in your existing website. I would advise you to create a new one to keep things separate and clean. Right click 'App_Data' folder, select 'Add New Item'->'SQL Server Database' and to create a new SQL server DB for storing blog data.

    Once done with your DB, create the DB schema using the SQL script available in ~\Blogs\setup folder. Choose your Db and it contains the necessary script and run it your DB manager to create table schema.

  6. Merge web.config files of existing website and BE 2.0:
    This is the most important and time consuming part of integration.
    Open the existing website's web.config file from ~/ and make the following changes step by step:

    1. Find following tag
      < configuration > < configSections >
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
        
          


    2. Find following tag
      < configuration >
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
      
      		
      			
      				
      				
      			
      		
      	
      
      
      

      Please not that this entry is for specifying the data store mechanism for BlogEngine. If you are using the database to store BE data, change the defaultprovider value to DbBlogProvider. Example:
      <blogProvider defaultProvider="DbBlogProvider">

    3. Find following tag
      < connectionStrings >
      and add the following line (If it contains another tags, let them be there. Don't delete):
       
      
      
      
      
      

      The connectionString in above tag should point to the database which you created in above steps. If you are not using database to store BE data, you can skip this tag entry.

    4. Find following tag
      < appSettings >
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
       
      
      	
      	
      	
      	
      	
      	
      	
      	
      	
      	
      	
      	
      	
      	
      	
      
      
      

      The BlogEngine.VirtualPath i.e. folder where Blog code resides should be ~/Blogs

    5. Find following tag
      < system.web >
      < compilation >
      < assemblies >
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
      	
      	
      	
      	
      	
      	
      	
      
      
      
      

      NOTE: These tag may already exist in your web.config. If any one of them is already there, don't add another one.

    6. Find following tag
      < system.web >
      < compilation >
      < expressionBuilders >
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
      
              
              
              
              
              
              
            
      
      
      

      NOTE: The expression builder tag may not be available in your existing web.config. If it is not there, you can add one for yourself inside < system.web > < compilation >

    7. Find following tag
      < system.web >
      and add the following line/s (If it contains another tags, let them be there. Don't delete):
      
      
      
      
      
      
      
      
      

      NOTE: These tag may already exist in your web.config. If any one of them is already there, don't add another one.

    8. Find following tag
      < system.web >
      < httpHandlers>
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
      
      		
      


    9. Find following tag
      < system.web >
      < httpModules >
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
      
      
      
      
      
      
      
      
      
      
      


    10. Find following tag
      < system.web >
      < pages >
      < controls >
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
      
      
      
      


    11. Find following tag
      < system.web >
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
      
      	
      		
      		
      	
      
      
      
      


    12. Find following tag
      < system.webServer > < modules > :
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
        
      
         
            
          
      
        
            
      
      
      
      


    13. Find following tag
      < system.webServer > < handlers > :
      and add the following line (If it contains another tags, let them be there. Don't delete):
      
      
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                   
               
      		
      
      


    14. Existing Asp.net membership and BE:
      If you already have existing membership (user registration and login/log out functionality) enabled in your existing website, then you do not need any other settings now. You are done. But if you don't have any or want to switch to BE's membership, you should add following tags for it:
      1. Find following tag
        < system.web >
        and add the following line (If it contains another tags, let them be there. Don't delete):
         
        
        
              
               
            
        
        
        
        NOTE: This tag may already exist in your web.config. If it is already there, REPLACE it with the above one.

      2. Find following tag
        < system.web >
        and add the following line (If it contains another tags, let them be there. Don't delete):
         
        
        
              
                
                
                
              
            
            
              
                
                
                
              
            
        
        
        
        NOTE: These tags may already exist in your web.config. If they are already there, REPLACE them with the above ones. Also, if you are using database, enable the DbMembershipProvider instead of XmlRoleProvider.

    Wow..we are done with merging the web.config files. The toughest battle has been won.
  7. Disable or Delete config file in Blogs:
    Since we have merged the BE configuration with existing website, we should delete the config files given in YOURWEBSITE.com/Blogs. This file should be either excluded from project or deleted:
    web.config

  8. Set up Blog to compile:
    Ideally, all BE 2.0 code should reside ~/Blogs/ folder but there are some places where it tries to find some folders in the root(~/) itself and throws an error if not found. To remove these errors, make following movements:

    1. Copy some folders in root (~/) :
      Copy and paste admin, Account, Scripts, Styles, themes and widgets folders from ~/Blogs/ to ~/ .

    2. Move (Cut and paste) some files to root (~/) :
      Copy and paste web.sitemap and Global.asax file from ~/Blogs/ to ~/ . If your website root already contains global.asax file, then you should merge the two to avoid any collisions.



  9. Write permission on App_Data folder:
    Make sure that you have write permissions on App_Data folder for BE to store data.

  10. Run:
    You should now run the BE installation by launching the
    ~/Blogs OR YOURWEBSITE.com/Blogs
    . This will open the ~/Blogs/Default.aspx page.

    If you can see the welcome message (welcome blog post), your set up has succeeded.



That is it. Good luck. If you face any issues, ask in comments and i will be glad to help you.

Would you like to share this article?

QR Code for this page Scan this QR code to open this article in any mobile browser or share with friends.


For more helpful articles like this, subscribe to our free newsletter or stay connected on social networks:

SUBSCRIBE
Subscribe to AM22 tech in Reader or by Email
Sign up for our updates in Email (Free):

 

Have questions? Write into comments or ask in forum