1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Applications
.PestControl
.Web
18 using System
.Web
.Security
;
21 using Castle
.Applications
.PestControl
.Web
.Controllers
.Filters
;
22 using Castle
.Core
.Resource
;
24 using Castle
.Windsor
.Configuration
.Interpreters
;
26 using Castle
.MonoRail
.WindsorExtension
;
28 using Castle
.Applications
.PestControl
.Model
;
29 using Castle
.Applications
.PestControl
.Web
.Controllers
;
32 /// Summary description for PestControlApplication.
34 public class PestControlApplication
: HttpApplication
, IContainerAccessor
36 private static WindsorContainer container
;
38 public void Application_OnStart()
40 container
= new PestControlContainer( new XmlInterpreter(new ConfigResource()) );
42 container
.AddFacility( "rails", new RailsFacility() );
44 AddFiltersAndControllers(container
);
47 private void AddFiltersAndControllers(WindsorContainer container
)
49 container
.AddComponent( "auth.filter", typeof(CheckAuthenticationFilter
) );
50 container
.AddComponent( "home", typeof(HomeController
) );
51 container
.AddComponent( "dashboard", typeof(DashboardController
) );
52 container
.AddComponent( "registration", typeof(RegistrationController
) );
53 container
.AddComponent( "project", typeof(ProjectController
) );
56 public void Application_OnEnd()
61 public void FormsAuthentication_OnAuthenticate(Object sender
, FormsAuthenticationEventArgs e
)
63 HttpCookie cookie
= e
.Context
.Request
.Cookies
[ FormsAuthentication
.FormsCookieName
];
65 if (cookie
== null) return;
67 FormsAuthenticationTicket ticket
= FormsAuthentication
.Decrypt(cookie
.Value
);
69 PestControlModel model
= (PestControlModel
) container
[ typeof(PestControlModel
) ];
71 e
.User
= model
.Users
.FindByEmail( ticket
.Name
);
74 #region IContainerAccessor implementation
76 public IWindsorContainer Container
78 get { return container; }