ASP.NET MVC project structure with multiple subdomains? - asp.net-mvc

I have task to create site that contains some subsites. This subsites will use same database and will have relations. Their domain names should differ. For example, domain is www.mysite.com. Subsites are
www.books.mysite.com
www.blog.mysite.com
www.sport.mysite.com
I need a help about a project structure to start this application. Can anyone give me any idea? Can I create some MVC4 projects in one solution? or can I do this with Domain Routing?

This has been answered elsewhere, but not in great detail, so I'll collate the relevant points here.
A Visual Studio solution has no actual relation to the deployment of the site; it's just a container for various projects. When you deploy these projects, you can define bindings for them in IIS. This is a relatively straightforward process; if you're doing it the simple way from the UI you'll get something like this:
which lets you define which addresses point to where. During development, you'll need similar bindings in your host file to play the part of these IIS bindings for your local machine.

Related

having multiple mvc projects under same url

I was wondering if it's possible to create an mvc project with layers inside or even multiple projects using the same web address.
Like if I have a website called mysite.com which have a website project doing sine stuff.
But then I have a webproject which I'm doing some experimentational code on which I whould like to find via the url "mysite.com/test". This whold be a dufferent mvc project. Is that even possible?
It is possible, what you actually need to is create a new project and define it inside a virtual directory.
MVC is based on global.asax and web.config configurations and you can't have 2 separate projects inside the same application. In the scenario you described, it sounds like you need to create a "Virtual Directory" in IIS for the second application instead of making just a "Sub Folder".
The Virtual Directory will allow you to declare a new web.config and global.asax where you set the new routings and configurations method for your second application and this will also give you the freedom for independent updates without affecting your main project.
For a full walkthrough on how you can perform this please refer to this site:
http://msdn.microsoft.com/en-us/library/vstudio/bb763173(v=vs.100).aspx

following iterative and agile in asp.net MVC

ok, i know there are a lot of posts online that specify how to do iterations with MVC.
my question is slightly different. when i used to do iterations using WebForms, i was creating one thing only and finishing that one thing till the end which was including the deployment on production.
for example, i was creating a webpage and deploying it, then i create the second page and deploy it. so .dll files were added to my bin folder while the previous dlls remain untouched. at the other hand, when i was making a change latter on, there was this one file that needed to be replaced on production.
now here is the question, how can i acheive the same thing in mvc? beause it just doesn't deploy each page into an individual dll. each time that i add something i have to redeploy the application dll which is not really wise! i played around with deployment options in visual studio but no luck!
There is nothing preventing you from putting controllers and other code in separate assemblies and dropping them in an existing application. Like any ASP.NET based application an MVC application will automatically restart if you add or modify any file in the bin folder or modify web.config.
If you're using Razor you can use RazorGenerator to generate code for your views and compile them into the same assembly.
You may need to write some additional logic though to get routes, model binders etc. wired up correctly.
For a more structures approach to compose the application of separate modules, you may want to look into portable areas. This is an extension to ASP.NET MVC that allows you to package the entire module (including views, css, js etc.) into a single assembly.
First thing, you have to work on the title of the post, it does not match the content of the post.
In asp.net mvc u can choose to deploy only what changed. I.e. If you only changed the .cshtml file, then you can just replace it with the file in production. However if you change any controller class (C#/Vb code), then you will have to upload the web project dll file too so that this new changes are available in the production env

How to seperate MVC project to several smaller MVC projects

I have an MVC 3 app that has some core functionality (most important is autorisation) but mainly serves as a portal to different areas or modules. I want to organize thit to different modules that with minor changes also can be deployed as their own website.
The project consists of a Forum, Blog engine, Messaging between users + 4-5 upcoming modules.
I looked at ScottGu's blog about MVC 2 and found something that seemed perfect:
Depending og what the customer need I want to only give them the exact modules they can use. It is also easier from a maintainence view to be able to work and update referencd assemblies in each project and just do a full update for the customers that have that spesific module on their server.
But in MVC 3 there is no apparent way to use Areas this way, do you know how?
Status
I will try to add MVCContrib Portable areas to my existing solution and convert my areas ower and will post back the results. If it works I will mark it as the accepted solution.
MVCContrib has portable areas.
http://mvccontrib.codeplex.com/wikipage?title=Creating%20a%20Portable%20Area&referringTitle=Documentation
This is possible in MVC3:
From:
http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects
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 from the shell mvc project to the new project and adjust the namespace as applicable. (Or you can manually create an area registration class, it's a pretty simple class. Just use the Add area template generated one as an example.)
Edit the routes in the AreaRegistration folder as needed.
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 will not need to deploy this web.config but the razor intellisense doesn't work without it during dev time.
Delete the global.asax file from the area's project or you will get extra default routes.
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. For IIS Express you can use the appcmd.exe in the IIS Express folder or you can edit the applciationhost.config file.

Where to put Entity Framework Data Model in MVC application?

Lets consider default ASP.NET MVC application folder structure, so it's looks like this:
-App_data
-Content
-Controllers
HomeController.cs
-Models
AccountModels.cs
-Scripts
-Views
My question is: Where is the best place to put Entity Framework Data Model (EDMX) file? Is it Models folder? Yes - we know that good solution is to introduce new Project and reference it to MVC application, but lets forget about this now.
For a small project, it should be part of the Model. For a larger product, the repository and the associated model could be in a separate assembly.
Well this is debatable, but i'd vote +1 for the Models folder.
The only other candidate would be App_Data, but this is generally for file-based databases (SQL Server CE .MDF, for example) and files you don't want served by IIS.
As the EDMX is an abstraction of the database, it should go into the Models folder.
If the project gets bigger, you should definetely move your EF Model into another project. To future-proof yourself from this, make your Controllers access the EDMX via Repository/Interfaces, so when you move the DAL over to another project, all you'll have to do is add the reference and add in the using statements.
I would put the EF-model (aka physical model) always in its own assembly or in a "core" assembly outside of main MVC application. The same applies for your business-logic / domain-logic / domain-services / etc. Separate the non-web stuff from the MVC-Web-Application.
This will help you re-use the core part of your app. For example when you need to expose it as a service, a command-line tool, migration-tool, etc.
Because storing this in its own assembly is so easy and takes you a few minutes I highly recommend doing this for each and every tiny app too.
My opinion is that you should create
a separate project for domain objects, datacontracts etc. etc...
Like MyProject.Infrastructure including many folders like
DataContracts, Model, Exceptions etc.
a separate project for DataAccess wich contains the DBContexts and the Repositories, this way you can easily manage migrations later on

ASP.NET deployment - How to share BIN across multiple WebApp Projects?

What is the best practice for sharing the assemblies of a bin folder across multiple ASP.net websites in IIS 7?
I've got several sites, each with slightly different HTML front ends, but all with the same middle tier logic and DB. I don't want to redploy the same dlls to each of the many site's bin folders everytime I make a change.
Thanks.
Yes, actually, you do want to deploy them individually. That's how it works.
If this truly offends you, then consider whether this common code should be in a WCF service called by all those sites.
Another option is to make your .Net code smart enough so that it can load the correct HTML front end based on the URL. That way you could deploy your code to one location, then have multiple virtual directories use the same code.
You could possibly try putting them in a common folder location and then change the assembly probing paths to look in that location.

Resources