Sunday, 2 November 2008

ASP.NET MVC and Rhino Tools sample application

It was on my planning already for a long time but this weekend I took a couple of hours to create an ASP.NET MVC sample application. The application itself is for the moment very, very basic, but the idea is to add features to add that demonstrate how you can use ASP.NET MVC in combination with Rhino Tools, NHibernate, Nhibernate Search, Migrator.NET, Windsor, Binsor, ExtJS grid, and probably even some others.

I did not have that much inspiration, so the idea is to create an ASP.NET MVC version of the WineCellarManager, which is built with Castle Monorail.

This first version contains the following:

  1. Integration with Windsor: the Controllers are created via Windsor and the configuration of Windsor is done using Binsor.
  2. Integration with Rhino.Security:
    1. I have a base "WineCellarController" that has an "AuthorizationAttribute". That means that every controller that derives from WineCellarController will pass the authorization module. This attribute was created by a colleague on my project. It uses the IAuthorizationService from Rhino.Security to verify whether the logged in user is allowed to perform the requested action.
    2. There is also a PermissionController with a Generate action that you can use to generate permissions for all actions of all controllers. On our project we have the intention to use an attribute on Controller Actions to allow you to group actions in one security operation or to not add a Controller action as an operation, but that is not entirely finished yet.
  3. Use of Migrator.NET to create the database schema: there is a project in the solution: WineCellar.Migrator that is used to add database migrations. You execute the migrations using the Migrator.Console.exe which is included in the libs. In the first migration is a comment that tells you which parameters to add to the console application.
  4. Integration with Rhino.Commons by using the UnitOfWorkApplication of Rhino.Commons.
  5. Console application for Rhino.Security setup: there is also a small console application included that I used to create the database schema for Rhino.Security. I added that afterwards to the migrations, but you can still have a look to see how it's done.

Next steps:

  1. Demonstate how you can use an extension method on HtmlHelper to add security on field level.
  2. Integration of NHibernate.Search
  3. Integration of ExtJs grid using HtmlHelpers.

I almost forgot to tell you where to get the source. It is here: https://winecellarmanager.googlecode.com/svn/trunk/WineCellarManagerOnASPNETMVC

UPDATE: I noticed you need a password to check out the code on the link above. You should be able to get it without password in the following way:

svn checkout http://winecellarmanager.googlecode.com/svn/trunk/ winecellarmanager-read-only

15 comments:

Jen said...

The blog is helpfull...
visit also asp.net [c#]

Michael said...

Hi,

I'm just starting to have a look at this. First impressions are that it is really impressive...

oh, and THANK YOU, for not doing another blog or Northwind sample! :-)

Bart said...

@Michael,

Thanks. I hope to have some time to add some new stuff pretty soon...

asafdav2 said...

i'm having a bit of a trouble running this.
when i finished the build and migration, and tried to debug,
i got a dialog with "There is no source code available for the current location."
pressing ok, i'm getting the following NHibernateException: "Unable to initialize: Wine.0"
the inner exception is:
+ InnerException {"Index directory does not exists: C:\\Documents and Settings\\Asaf\\My Documents\\Visual Studio 2008\\Projects\\ASP.NET MVC\\WineCellarManagerOnASPNETMVC\\WineCellarManager\\/Index"} System.Exception {NHibernate.HibernateException}

what seems to be the problem is the /Index at the end of the path (bolded), i think it should just be Index, but i dont know where did this slash came from

Bart said...

I think I might have used an adapted version of Rhino Commons which is not a good idea of course. I have done it properly now.
Please do an SVN Update first and check the CaptureConfiguration class in WineCellar.Core.Nhibernate.
cfg.SetProperty("hibernate.search.default.indexBase", "Index");

Lennard said...

I managed to get it work by creating a index directory and setting the absolute path:

cfg.SetProperty("hibernate.search.default.indexBase", @"C:\WineCellarManagerOnASPNETMVC\Index");

Anonymous said...

HI i tried downloading the svn code but cud nt as it told me abt authentication .
svn: Server sent unexpected return value (407 Proxy Authentication Required ( Th
e ISA Server requires authorization to fulfill the request. Access to the Web Pr
oxy filter is denied. )) in response to OPTIONS request for 'http://winecellarm
anager.googlecode.com/svn/trunk'


I ran the svn command in command prompt !

Kindly assist in downloading else send the code as zip

gfh said...

I link Wow Power Leveling and wow power leveling wow power leveling

Anonymous said...

hi
>
> Do we need to add tables in the rhino security schema for
> each and every entity we want to add to entity group ??? or
> the entities would be picked from application schema only
> ???? How does the rhino security interact with the entities
> present in application schema(say in sharparch . core )?
> The examples given always show a coding line as
>
> Account account =
> Repository (Account).FindFirst();
>
> User user = Repository(User).FindFirst();
> var auth =
> container.Resolve(IAuthorizationService)();
> Console.WriteLine(auth.IsAllowed(user,
> account, "/Account/Delete"));
> Console.WriteLine(auth.GetAuthorizationInformation(user,
> account, "/Account/Delete"));
>
> Now where is this "Accounts " table ? is it in application
> schema or rhino schema ? n what is the use of
> Repository (Account).FindFirst(); ???
>
> Can u pls send a demo on functionalities like adding
> entities to entity groups ,IEntityInformationextractor
> ? as the data on these things are not very
> elaborartive on the forums ?

Humberto said...

First off I would like to say thanks for taking the time to develop this example to help us newbies understand Rhino Security.

I'm having some problem starting the example, I have run the migrator and successfully created the wines db with the script provided. But now when I try to run the site and authenticate with a username and passwd i receive the following error: "Cannot open database "Parker" requested by the login. The login failed." I understand this has to do with me not having the parker db created but when I look through the parker code under "WineCellarManagerOnASPNETMVC\Tenants\Parker" I am unable to find a script to create the db. Also when I have the winecellarmanager site running and I click on the login form I get the following error: "No component for key accountcontroller was found" I have included the stack trace below. I would really appreciate it if you could point me in the right direction in order to get this working, much appreciated it.

[ComponentNotFoundException: No component for key accountcontroller was found]
Castle.MicroKernel.DefaultKernel.get_Item(String key) +192
Castle.Windsor.WindsorContainer.Resolve(String key) +70
Rhino.Commons.RhinoContainer.Resolve(String key) +75
Rhino.Commons.IoC.Resolve(String serviceName) +72
WineCellar.Web.Helpers.ControllerFactory.CreateController(RequestContext requestContext, String controllerName) +98
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +128
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Bart said...

Can you the tenantname in the web.config from Parker to Core and see what happens then?

Humberto said...

Made the suggested change to the web.config and I'm still receiving the DB error when I try to log in, I also get the same stack trace when I click on the login link on the top right corner of the app.

Bart said...

I'm getting a fresh copy of the source from google code and I'll check what's wrong.

Bart said...

If you do a svn:update it should work. I runs ok now on my machine at least. I am running it in IIS btw, and not in Casini but that should not change much.

Bugs fixed:
1) Logout went to the wrong controller
2) The returnUrl after a login was not correct.
3) The wrong hibernate config was taken in case of the Core. The system always took the Parker hibernate configuration.
4) I had some issues with JS files not being found which caused the grid not being displayed correctly.

Anonymous said...

we provide a world of warcraft power leveling and 2moons gold and2moons power leveling wow power leveling cd keys andKnight Golda buy aoc gold or last chaos gold wow power levelinglast chaos gold oraoc gold hope archlord power leveling you Aion kina ask LOTRO Gold thanks luna gold