Multiproject areas in ASP.Net MVC 3 - asp.net-mvc

Does any one have any idea about multiproject area support in asp.net mvc 3? As it was degraded to future status in mvc 2. If it is still not included then should we look forward for ASP.Net MVC Portable Areas via MvcContrib. Can you share your expreriences?
What are the recommended way for managing a large application? I read about MEF. In what scenarios MEF is recommended?

I'm the development lead on ASP.NET MVC at Microsoft.
There are no plans to include multi-project areas in ASP.NET MVC 3. However, it's definitely an area that we plan to revisit in the future.
In the meantime MvcContrib's solutions are probably the best bet. The MVC Futures download still includes an old (and perhaps only semi-functional) version of the original multi-project areas feature. Because the full source code for it is also available, you might be able to construct a solution that is customized to your needs.

I need to have the same structure so I have figured out how to have areas as separate projects. There are no code changes needed, just a bit of configuration work you have to do.
I am going to create a blog entry on this but here are the basic steps.
Let's assume you have a single MVC application project and this will be your "shell" app.
right click on the shell project and "Add Area...". Type in the area name. This will create an Areas folder with your area in it. (This is not 100% needed but you do need the "Areas" folder and you can steal the XXXXAreaRegistration class for your application.)
Create a new MVC3 empty project in your solution to match your area. Move the XXXXAreaRegistration.cs file to the new project and adjust the namespace as applicable.
Delete the folder under the areas folder that the template wizard added.
Modify the web.config of the new project and take out the connection strings and the authentication, membership, profile, rolemanger sections. You don't really need the web.config but the razor intellisense doesn't work without it.
Create a virtual directory in the "Areas" folder of the shell project with the name of your area as the alias and point it to your "area" project. You will need to use IIS or IIS Express for this. I use IIS. In IIS express you have to modify the config file. I think ScottGu had a blog entry on how to do this.
Create a post-build event on your "area" project to copy the dll to the "shell" projects bin folder. My build event is: copy $(TargetDir)\$(TargetFileName) $(SolutionDir)\ShellProjectName\bin\$(TargetFileName)
In the shell web.config add the "area" project into the System.Web/Assemblies section.
Instead of 6/7 you can just reference the "area" project with the "shell" project and it works just as well. But, then you have to deploy all the "area" dlls every time. I am probably going to do some type of probing code to add the "area" assemblies to the app domain at app start up using reflection or MEF.
You might also want to edit your routing and add the namespace filter to it in both the shell app and the area app. This way you don't have to worry about duplicate controller names conflicting between the sell app and the area apps.
That's about it. Once I get a formal blog entry posted up I will try to remember to add a link to it here.
I blogged how I am doing this at http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects if anyone is interested.

Related

Phased migration - running ASP.NET 4 alongside ASP.NET 5

We have MVC ASP.NET Web Applications written within the ASP.NET 4.* scope that we would like to phase across to ASP.NET 5. While we transition (as well as client-side JavaScript scripts/libraries, CSS, etc) we'd like the old app (which obviously contains Views, Controllers, Helpers, Utilities, Attributes, etc) to co-exist in an MVC/Web-Application ASP.NET 5 project, with the new (ASP.NET 5) codebase.
Firstly is this possible with minimal changes ? I have been doing some testing and a lot of reading - for the client-side libraries I should be able to handle the co-existence by copying the existing content into the wwwroot area via Gulp. My question is mostly around the server-side artifacts - for example I am using a framework (as specified in project.json) of "dnx46" (which seems to be the most appropriate for this purpose), but I am getting a number of conflicts (around missing assemblies) around simple things like Project references, ActionFilterAttribute & AuthorizeAttribute [eg. The type or namespace name 'AuthorizeAttribute' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?)] (because they no longer exist in the System.Web.Mvc namespace), HttpContextBase, security (OWIN, etc) etc - note that I'm aware of including References which are reflected within the project.json file (and some that finish up inside the appropriate 'wrap' folder location)
If there is a preferred approach - some possibilities are
create a new WebApplication ASP.NET 5 project which among other things contains out of the box Bower, npm, Gulp, CodeFirst Migrations, Controller/Views, etc ready to go then copy your legacy project artefacts in
create a blank ASP.NET 5 project and start everything from the ground up (as per http://aspnetmvc.readthedocs.org/projects/mvc/en/latest/migration/migratingfrommvc5.html) then again copy your legacy project artefacts in
create a new WebApplication ASP.NET 5 project, then with a post-build event copy your new and legacy artifacts into a third vanilla project. In this way the old and new projects live in isolation and only get merged in at deployment time
separate concerns like Helpers, Utilities, Attributes, etc that are used within the UI project into a traditional Class Library project and only keep the bare minimum (Views, Controller, scripts, css, etc) within the UI (ASP.NET 5) project
Any ideas would be greatly appreciated.
I don't know that how your MVC 4 project is structured, I would prefer to create it from scratch using Blank ASP.NET 5 Template targeting dnx451. The thing I don't understand is previous .NET stuff like Authorize attribute are not found as they are available and I'm using it. Here are some stuff that might be help to you while migrating:-
Your EF Context and security classes should be considered as middlewares in ASP.NET 5 and should be configured in Startup.cs class which is not found in MVC 4.
Put all your CSS\JS files in wwwroot and make a reference _Layout.cshtml as root as normally (use gulp task runner for better performance.)
Must target dnx451, because dnx50 does not contain all of the libraries and it is about immensely in ASP.NET Core RC2 and RTM. (If you can't wait for RC 2).
If you're using Identity for Authorization, note that there is now a big change in Authorization Policy as can be found Here
It is a little bit difficult but it will optimize your team working and will make your project flow faster than before.

change webforms to mvc in visualstudio 2010

i created a blank webforms project instead of an MVC 3 project in visual studio, everything runs fine but i dont have my menues
for example when i right click on the Controllers folder i dont get "Add a controller" option.
does anyone know without starting a new project how to change the type of project into an MVC one so that i get the correct menus.
thanks
It's not that you don't have the menu options, it's that it's a completely different type of [web] application and works in different ways. e.g. Webforms has no concept of controllers so even if you did have a menu option it wouldn't get included in the project as you're expecting.
Because webForms and MVC are so different there could never be a 100% reliable conversion utility.
Just create a new project and copy the files already created. I can't imagine you've written that much code before realising that you're in WebForms, not MVC.
If you have got lots of WebForms code you could always just include this in the MVC project until you can convert it (if necessary) at a later time.
Edit:
If you just want to change the project type you can edit the csproj file of the webforms project and add the following ProjectTypeGuid {F85E285D-A4E0-4152-9332-AB1D724D3325};.
You'll need to update references, files, etc. for this to work but it may be quicker than creating a new project and copying content over. (Especially if you already have the project in source control.)
Note that I've only tested this going from WebForms 4 to MVC2.
Try updating a MVC to ASP.NET Fall Update Release Candidate. There is a link .

Can you convert an ASP.NET MVC Application to a Web Site using ASP.NET MVC and what problems might you run into?

I would like to use a WebSite project instead of a Web Application project for an MVC project.
What is the best way to accomplish this and are there signifigant problems that I might run into?
(as a side note, my reasoning for wanting this is because I have graphic designers who put files into SVN but they don't get added to the "project" and don't show up on deployment or deployment testing. My thought was that switching to a Web Site project might prevent this)
You don't need to do anything special if you are not using CodeBehind files (if you're using them, it'll be more complex but anyway, it's an MVC app. If you're using them, don't!). Just take an MVC Web app project and put all source files (*.cs) under App_Code directory of the Web site. That said, I fail to see any advantage for it.
The application project allows you to use the Models folder to embed classes into. This would then be compiled for that web project. A web site does not provide for this directly. It would require that you use an assembly project to maintain all of your classes. Rather than converting from one project type to another (which I am not sure how you wold go about doing that) you can simply attach an assembly project to your web application and not store any classes in the model folder of your application.
Having said this, you should keep your web project as an application as there usually are view specific classes that are required such as a your view model classes that belong in the web project.

Modular Architecture - ASP.NET MVC

I've searched (google and SO) about this topic and couldn't find a thorough answer to my question(s).
I'm building an ASP.NET MVC 2 application that will be distributed to other people (with source code). These people will need to create modules/plugins that use the application's base.
The base is a simple ASP.NET MVC Application with Linq-To-Sql file, repositories, authorization/membership.
Is it possible to create a plugin that would work by simply adding a .DLL file in a folder?
Right now, you can create a "plugin" by opening the source project of the base application, creating a few controllers/views that do somethings, using the base application's authorization/membership and repositories. You would also be required to edit the Linq-to-Sql file and add in any tables that you need.
However, to "install" this plugin, I would need to copy the controllers/views for this plugin into my base application and edit the Linq-to-Sql class to include the tables necessary for this plugin, then build the solution. Is there a simpler method?
I read of .DLL plugins, but how would someone build a plugin like this starting from the base application.
If the 'plugin' creates tables with foreign keys of the "User" table in the main application, how does one separate those tables/relationships in a separate file and have the base application recognize those relationships?
As you can tell, I'm asking multiple questions that are kind of all over the place. This is a new topic/issue for me and I have no idea where to start. Theme mere concept of having my application interact with a separate .DLL file is foreign to me.
Any help/links would be greatly apprecaited.
Does this answer the same question: Plug-in architecture for ASP.NET MVC?
I think this could be applied to mvc too: http://msdn.microsoft.com/en-us/library/ms972962.aspx

How do you activate the MVC templates in VS2008 from a WebForms App

I'm in the process of adding ASP.NET MVC to a WebForms app. One of the neat features of an ASP.NET MVC solution that you create from scratch is that a right click on the solution explorer and Add > New Item... will give a list of templates which include the MVC templates. However, in a WebForms app these templates don't appear.
I thought that there might be a setting in the .sln solution file that indicated that one was an ASP.NET MVC app but I couldn't find anything that that stuck out.
EDIT: To expand the question, how does Visual Studio know to add a "Controller..." menu item on to the "Add" menu when you right click on the Controllers folder in the Solution Explorer of an MVC app? Likewise it adds a "View..." menu item to the "Add" menu when you right click on the Views folder. Where does Visual Studio get this info from and how can I add those 2 folders to another web app and get the same functionality?
Ideas?
I believe that the logic for that is contained in the dll
Microsoft.VisualStudio.Web.ExtensionsUI
Which is registered in the Project template used when you create a new ASP.NET MVC project:
<WizardExtension>
<Assembly>
Microsoft.VisualStudio.Web.Extensions,
Version=9.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35
</Assembly>
<FullClassName>
Microsoft.VisualStudio.Web.Mvc.TemplateWizard
</FullClassName>
</WizardExtension>
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033\MvcWebApplicationProjectTemplatev1.cs.zip
You could probably also mess around with the Project Type Guids in your .xxproj file:
<ProjectTypeGuids>
{603c0e0b-db56-11dc-be95-000d561079b0};
{349c5851-65df-11da-9384-00065b846f21};
{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
Seem to be the default ones for an ASP.NET MVC project, compare those with the ones in your web application, and go from there.
However, in a lot of these circumstances I'd agree with gisresearch: it's often easier to create the more complex project (the MVC one) first, and then move the origininal into it.
Also, there's nothing to stop you having multiple projects hosted in the same web application - pull the common logic from the web application into a shared class library, and then reference that from a clean MVC app, with a slightly different namespace, and then merge the two sites within IIS, drop the dlls into a shared bin folder (or strongly name them and put them in the global assembly cache), share the images/scripts, and away you go - you just need to take care with the Global.asax, which would be common to both.
How about the other way around. Create an asp.net mvc project firstly, and then add your web form code over.
Here is an example of hybrid app by Scott Hanselman.
You may also consider to create one default asp.net mvc application and asp.net web form application, and then do a text compare of two projects to see what is the difference.
Like Zhaph mentioned, adding the ProjectTypeGuid worked for me. Unload the web project, edit, and add in the extra ProjectTypeGuid to the existing list.
{603c0e0b-db56-11dc-be95-000d561079b0};

Resources