global.asax and ASP.NET MVC solution Organization
I am refering to this article from Jimmy Bogard
He is suggesting 开发者_C百科two projects to organize your ASP.NET MVC solution.
Basically, one project for the code and another for the rendering
My concern is about global.asax file.
Jimmy suggested separating global.asax from global.asax.cs and put them in two differents projects
When I did this, I could not compile my solution.
I got this error : Could not load type 'MyProject.Web.Global'.
Can someone help and show me how to solve this?
Thanks
Without seeing your code it is hard to guess what exactly the problem is. When you create an MVC project the Global.asax markup has something like the following:
<%@ Application Codebehind="Global.asax.cs" Inherits="MyApp.MvcApplication" Language="C#" %>
To put the Global.asax.cs in another project, you probably want to remove the CodeBehind="..." declaration from Global.asax and you have to change the Inherits="..." declaration to reference the correct namespace and classname as it is defined in Global.asax.cs.
It is so easy to reproduce the issue
- Create a new MVC2 application :Web.UI
- Add to the solution, a new class library type project : Web.Code
- Move from Web.UI to Web.Code the following:
- Controllers
- Models
- Global.asax.cs
- In this second project, add a reference to
- System.Configuration
- System.Web
- System.Web.Mvc
- System.Web.ApplicationSewrvices
- System.ComponentModel.DataAnnotations
- System.Web.Routing
Compile and run
UPDATE
I found what was wrong
in global.asax file, I was not indicating the new namespace in the "inherits" attribute
<%@ Application Inherits="Project2.Global" Language="C#" %>
精彩评论