Ales Rosina's blog

shelastyle.net
Subscribe

Publishing NopCommerce 2.0 to Azure



 

So if you haven’t heard, NopCommerce is great open source project for e-commerce type sites. The latest version is rewritten in ASP.NET MVC, so you don’t need to bother with WebForms anymore.

I thought, that since it’s codebase was changed from 1.9 version it should also work very easily on Azure platform. But unfortunately that is not the case. If you take a close look at how nopCommerce works, you’ll see, that it needs write permissions for configuring connection string (actually it is stored in Settings.txt file in App_Data folder). I will not argue if that’s good or not, we just need to port it to Azure, that’s all :)

So for the first step, we need to deploy app on a local machine to get a full database. With a standard “Import and Export Data Wizard”, which you get with SQL Server installation, you can transfer database from local SQL Server instance to Azure based (read more on how to configure SQL Azure in this short tutorial). For more info on how to do a transfer, referrer to this great article on Microsoft TehNet Wiki.

So, when you’re done with configuring database, we’ll need to customize a bit NopCommerce. First of all, download version with source and open it in Visual Studio. You’ll need to have Azure SDK installed on your machine. You can add new empty Azure project in NopCommerce Solution and after it’s added, right click on Roles folder and choose Add>Web Role Project in solution. Add Nop.Web and that’s it for Azure configuration.

Now here comes tricky part – you need to include a few more folders in Nop.Web solution – that is folder Administration and folder Plugins. That’s because Visual Studio packages only folders included in project. After you’ve done that, you’ll also need to add a few more Refereces – try to build the project and check which references are missing.

One more thing before you’ll be able to upload to Azure – we need to change where Connection string is stored. I choose Web.config, where you need to add two new keys in appSettings section:

    <add key="DataProvider" value="sqlserver"/>
    <add key="DataConnectionString" value="Server=tcp:sth.database.windows.net,1433;
Database=nopcommerce;User ID=username@sth;Password=your_pwd;
Trusted_Connection=False;Encrypt=True;
"/>
and after that, you’ll also need to edit DataSettingsManager.cs (found in Data folder in Nop.Core project), where you’ll simply delete content of SaveSettings() function and replace LoadSettings() with:

public virtual DataSettings LoadSettings()
{
    var ret = new DataSettings();
    ret.DataProvider = ConfigurationManager.AppSettings["DataProvider"];
    ret.DataConnectionString = ConfigurationManager.AppSettings["DataConnectionString"];
    return ret;
}
And if you’re lucky enough, NopCommerce should be ready and published after Visual Studio does it’s magic of uploading/starting Azure instance.

   

author: Aleš Rosina | Comments: 6 | Tags:
17
October
2011

 
Todd Whitehead on 14. November 2011 at 04:01

Just what I was looking for!

Could you please elaborate on how you added the Administration and plugin folders to the nop.web project.

Aleš Rosina on 14. November 2011 at 10:05

You'll just need to click "Show all files" in solution explorer and include in project folder "Adminidtation" and "Plugins".

Todd Whitehead on 15. November 2011 at 01:39

Yes thats what I tries but when I tried to build it rhough an error about there being duplicate assemblyinfo.cs files in the project.

I excluded the one in the Admin/properties folder and then it built. But when trying to run it it throws an error about multiple routes registered for Admin area.

I wrapped the register route code in a try catch to get past that error and then the public store runs up fine. but when you try to access the admin site it throws a duplicate route exists error.

Ted on 9. December 2011 at 15:32

Awesome article...if you ever get time in the future, a bunch of us Azure Newbs would love to see a full walkthrough of running nop on that platform, what the performance is like, etc.

Thanks!

google android development on 7. February 2012 at 08:28

The full data base access is free, isn't it? Or there is some charge for using it?

James Kinney on 12. March 2012 at 17:19

Thanks so much for this article!! I've gotten nopCommerce 2.40 working in Windows Azure and this post was critical in helping me achieve that. I've noted each of steps I took here in case you're interested.

blog.jamesfkinney.com/.../nopcommerce_azu

Leave a Comment

Name:
Email:
I respect your privacy, so your email is never published.
Web site: