分享

HowTo: N2 Cms install : Content management Sy...

 Colin收藏 2011-09-23

HowTo: N2 Cms install

Posted by Ed Nice on 4 May 2009 | 1 Comments

Tags: , , , , ,

At N-Web Design, we love writing really cool applications for our clients.

This is a passion shared by many developers to the extent that they share their work as open source applications, freely available under various open source licenses.

Now as much as we love writing bespoke code, we hate re-inventing the wheel. That's why we like, where possible, to use open source apps and frameworks. It cuts our development time way down, saves our clients money and also offers a stable platform that has little or no ownership issues because of the open source licensing model.

Anyway, enough of the why, let's look at what and how?

N2 Cms (http://www./) is an open source web application framework, written in c#/, which allows you to create content managed websites.

Without going into too much detail (this isn't a review after all) N2 is a content management system that is really simple, powerful, well written and can be easily deployed into new or existing web applications. This makes it the ideal candidate for building an CMS or using as a base system for your own CMS framework. You can apply N2 Cms to Webform or MVC based applications. We are going to use the MVC sample project in this tutorial, but it will work fine with Webform examples too.

Ok, how do we get started and take a look?

This HowTo is aimed at those people who are new to N2, MVC and have limited skills with .net development so if you are an development Ninja, some of the explanations are quite simplistic. If you are a 'beginner' expect it to take about 30 minutes.

There are some pre-requisites for using N2 Cms. You need .NET 3.5, MVC and a development environment. This HowTo also covers adding SQLExpress as the chosen database, but the example we use initially uses SQLLite. This may be enough for you to begin using N2 and is certainly perfect for development and evaluation purposes.

This example is done on Vista Ultimate, with IIS7. If anything, it will be easier on XP so don't worry if that is your flavour of OS.

So you have Visual studio 2008 or web developer, SQLExpess (if required) and MVC? If you don't know anything about MVC or haven't got it installed, you should go to the website (http://www./mvc/) and watch the videos. If you don't have at least a basic understanding of MVC, you'll get a bit confused at the file structure in this example, which may frustrate you and turn you off N2 Cms, which would be a bad thing, as N2 is really cool.

The how bit...

Download the source code from http://n2cms./Release/ProjectReleases.aspx?ReleaseId=29374#ReleaseFiles. Just get it all. We'll tell you which bit to use, so don't worry about how much stuff there is.

Extract 'sources.zip' to your hard drive. It doesn't matter where. We are going to put the right files in wwwroot or wherever you serve IIS from.

Create an empty folder in c:\inetpub\wwwroot (or wherever you like to run sites from) called n2 or similar.

From the extracted files, copy the contents of sources/examples/mvc/wwwroot into the new n2 folder in wwwroot.

Create a new folder called n2 in you VS 2008 projects location (Mine is User\Documents\ Visual Studio 2008\Projects)

Copy the Mvc_Example.sln file from sources/examples/Mvc to the n2 folder in your chosen location for VS projects.

Open the Mvc_Example.sln file from your projects/n3 folder in a text editor like notepad. Don't use a rich editor like word. and edit the value "wwwroot\MvcTest.csproj" on line 4 to the location of your web site, ie: c:\inetpub\wwwroot\n2\MvcTest.csproj. This just tells solution where you have put the application so it knows where to find the files when you run the project.

Open the project in VS 2008. You should get a file list. If not, check the editing in the .sln file and the locations you have used.

Next, click on the 'show all files' icon in the solution explorer, then right click on 'edit', 'bin' and 'obj' respectively and 'select add to project for each'. This will take a few minutes.

Ok, now we will set up IIS. On the desktop, right click on 'My Computer' and select 'Manage'. You'll get some version of MMC popping up. Navigate to 'sevices and applications', then IIS Manager. Open the Default Web Site from the droppy arrow things and find the n2 folder. It will be displayed as a folder icon. We need to make it into an application. To do this, right click on the icon and select 'convert to application'. Just leave the defaults in place and press ok.

Next, click on the n2 application icon, and some options will appear in the panel to the right. At the bottom under IIS, select 'authentication', then under 'Action' in the far right panel, select 'Open Feature' then enable Window Authentication. You may get an alert but just ignore it. You need windows auth to debug and forms auth to use forms based authentication. (There's probably a fix/hack/workaround for the error, but I've never had any problems with it).

Now go back into VS and press F5. You should now see a blue default vanilla MVC web page. That meas it all works. It's installed. Cool...

Go to http://localhost:12345/edit and you should see the N2 login. Use the default login username/password for access (this is written into the web config for this example, but Membership should be easy to add to projects) which are admin/changeme.

If you are logged in ok, then it means everything is fine. You have a simple starting install of N2 inside an MVC application. You should now go and read some more, play with templates and generally feel good about this great app.

Changing the basic install to use SQL Server Express.

Why would you want to do this?

Well, if you use SQL Server Express for live projects, it probably makes sense to make the config work in dev how it will in production. The installation above uses the SQLLite file DB, which is fine for evaluation and testing but it is likely you will want to use SQL Express, so here's how.

This assumes you have the N2 install above working fine and have SQL Server Express installed.

My example is using 2005 Express, but 2008/10 should work the same.

First thing. Open the project in VS 2008 and open the web.config file.

Find the <connectionStrings> node and comment out the active string.

Uncomment the SQL Express connection string. Note it uses the AttachDBFilename parameter and Integrated Security. In this example, we will be using the SQL Server on localhost and a SQL Server login. (Again, this makes deployment to a live box a little easier and safer).

Edit the connection string to be something like:

<add name="N2CMS" connectionString="Data Source=.\SQLEXPRESS;Database=N2;User ID=n2-user;Password=n2user" providerName="System.Data.SqlClient"/>

 

You can use any database name, user and password you like.

We will now set up the DB in SQL Server Express.

Open SQL Management Studio (Remember to run as administrator).

Right click on databases and select 'create new'. Give the database the name you used in the web.config connection string.

Add new login called n2-user (or the name you used in the web config connection string), select SQL Server Authentication and give it your chosen password.

Click on 'User Mapping' and select the new database in the top panel.

In the bottom panel, named Database role membership, select db_owner.

You can micro-manage user permissions a lot in SQL Server but it is out of the scope of this article. If you don't know what selecting db_owner means for your database security, please read some articles about SQL Server roles and permissions.

You can test the login by using it to access SQL Server via management studio, but it should all be fine.

Next, go back to Visual Studio and F5. This runs the app.

You shouldn't get any errors, but if you do, please check the web config settings are correct and that the database and logins are all configured properly.

If all is well, you will be shown a configuration screen with a welcome tab an five step tabs.

Please read all this information carefully, but essentially because we have changed the connection to use a SQL Express db, N2 checks the database, sees it is empty and then helps us to set it up properly with all the tables and stored procs we need.

From the welcome (having read and understood it all of course) select 'start installation'.

Follow the instructions on step 1 and 2. On step 3, read the text and then select 'create tables'.

Step 4 asks about root nodes. For the purpose of this example, just select 'content page' on the 'use one node for both' option. This basically sets up where your site has its home page. It's worth reading about root and content nodes.

Step 5 mentions log-ins and Membership. Please read this and then continue.

You should now be taken to the site home page. If this is displayed correctly, everything is fine. You can navigate to /edit and play with the options and functions there.

I hope this helped you to get started with N2 Cms.

If you have any suggestions, notice any typos or have something to contribute to this article, please add coment.

What to do next?

I'm going to follow this up (yeah, right!) with some other tutorial stuff based on my own experiences that will cover topics such as:

Creating and editing templates
Adding roles and membership
Creating custom controls and content

Thanks for reading.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多