How to add second application to MVC website - asp.net-mvc

Say I've got an MVC website, www.codesmurf.com for example, set up with default ASP.NET MVC routing, nothing fancy. So my BlogController can be found at www.codesmurf.com/blog, and my FAQ similarly at www.codesmurf.com/faq.
Now if I also have a small survey project, currently in a different solution, how would I achieve to access this survey at www.codesmurf.com/survey?
What changes would I have to make to my routing and/or project structure to achieve this? So the entire survey project would be at the controller level of the main website, judging by the uri.
Do I have to achieve this using Areas? Do I need to create a SurveyController on the main site to redirect internally? Do I need to host this website separately and redirect externally? Any IIS configurations? How do I make sure my old routing isn't messed up?
This seemed like an easy task in my head at first, but I really have no clue what the best way to achieve this would be, and questions keep popping up in my head the more I think about it.
Note that the survey site is also an MVC project with its own controllers etc..
I haven't had much experience with changing the MVC routes, but would like to understand what I'm doing as well, so context/explanation would be greatly appreciated.

I personally would add the survey functionality as a service reference to your current MVC project.
Add Areas/Survey to your current MVC project and then start using the code from the service reference as you build up the Survey area.
When adding areas, all you will need to do is add some more rules to your map routes.
routes.MapRoute("areaRoute", "{area:exists}/{controller=Home}/{action=Index}/{id?}");

Related

Integrate Umbraco in an MVC and not the other way round

I have little to no experience in Umbraco, but it has been suggested to me as I have been asked to integrate a CMS system within my existing application. I have gone through some videos how to use Umbraco and done well so far. The problem is as follows. I have an existing MVC application with custom routing but both use the same database and dll. Example: www.ngomalta.com and animalguardians.ngomalta.com
Both have same interface, but with custom routing I can load some pages on a subdomain but not in the other. I would like to implement the same 'logic' using Umbraco. That is, I want both sites to have access to umbraco but they would have different content. Please note that it may be that I would have other sub domains in the future such as tomasina.ngomalta.com, and thus I would like scalability.
I have had a look on the net and other answers. However the solutions that I found are vice versa! What I mean is, that solutions given assume that you have an Umbraco site and you want to add an MVC controller. My situation is the opposite, I have the MVC and would like to add Umbraco views. Thus I want to make Umbraco compatabile with MVC and not design an MVC solution to be compatible/integrated with Umbraco.
Currently I have implemented a class that Inherits UmbracoApplication + WebBootManagerand and which overrides the Complete function. I have also tried to use my existing custom routing class (that inherits from [RouteBase]). It looks as if they work.. but the CSS styles and javascripts are not sort of routed or I don't know. They just aren't sent to the client. hence only the HTML is sent for both Umbraco page and my existing MVC views
First of all, is my idea with Umbraco possible?
If yes, can someone guide me some site that implements Umbraco in an existing (LIVE) MVC application and not the other way round? many of the tutorials that exist always start from a blank MVC application and build on that. I don't want such tutorials. I need a tutorial, that shows how an existing MVC application with already-existing-controllers that tries to integrate Umbraco.
Thanks for reading people..
!

MVC 3 Domain Routing

I would like to know if the following is possible. I have a website called www.myweb.com. This website could be a directory of say football teams. The list of teams could be found here
www.myweb.com/home/teamlist
On selecting a team one would be take to
www.myweb.com/teams/teama or
www.myweb.com/teams/teamb etc
the content under the teams area would be related to them e.g.
www.myweb.com/teams/teama/fixtures
www.myweb.com/teams/teama/news
i have the above working but would like to know if it is even remotely possible to have a separate website for each team which still uses the current models, views and controllers e.g.
www.teama.com
would go to display the data from
www.myweb.com/teams/teama
where 'teams' is the controller and 'teama' is a parameter for a 'details' action. Also doing
www.teama.com/fixtures
www.teama.com/news
would display the same stuff as
www.myweb.com/teams/teama/fixtures
www.myweb.com/teams/teama/news
many thanks and hope i have worded it ok.
Rudy
I would consider using IIS URL Rewriting in that case.
Have a look at MVC Domain Routing, I'm still researching it myself as I have a similar required as yourself but I think that should do what you need.
The following links might be handy:
ASP.Net MVC Domain Routing
Bolt on multi-tenancy in ASP.Net MVC Part I (link to Part II is on the page)

Multiple URLs and single codebase with ASP.NET MVC

I'm pretty new to ASP.NET MVC and I just want ask of this scenario is possible and, if so, could anybody provide any resource links on how to implement it.
Say I have a site that can be accessed from www.mysite.com, can I also have the same site load up through www.mysite2com, www.mysite3.com and so on? effectively providing the ability to run multiple sites from a single code base?
The idea is to have the site content and style sheet change depending on site visited but keep the structure the same.
thank you very much for any help you can provide :)
Kris
Yes, this is possible
http://web.archive.org/web/20100119084358/http://just3ws.wordpress.com/2010/01/03/skinning-your-asp-net-mvc-application-based-on-your-sub-domain
This example uses subdomains of the same domain but nothing stops you from using the same logic and have different images/CSS/paths etc generated based on full HOST/domain name

Asp.Net MVC Identify Site via Url

I have an application that will support multiple sites. The site will be determined based on the url.
For example
http://myapp/site/abc123/...
and
http://myapp/site/xyz123/...
The site code will drive a lot of the functionality for example themes, available modules, etc...
Questions:
1-)I need to validate the site code is valid and if it isn't, it should direct the user to an info page. I was looking at using IRouteConstraint, is this appropriate? Are there other/better options?
2-)Any gotchas with this approach (using url to identify site)? Is there are better approach?
Solution
I ended up creating a Custom ActionFilter and check the sitecode in the OnActionExecuting event. That seems to work well and fit better than the IRouteConstraint.
The system I have implemented uses Urls to identify unique page content within a single site and the routing process is pretty straightforward. That being said, you may want to consider making use of Areas in your MVC application. With Areas you can have multiple sections to your website that all have their own MVC structure which can run semi-independently.
Essentially, you will have one base routing definition that lays out some defaults and then the rest of the "sites" will define their own routes pointing to controllers and views in a separate location. It's pretty easy to set up, you'll just need to make sure you're using version 2.0 of ASP.NET MVC. Here's a decent looking tutorial on ASP.NET MVC Areas and Routes. In the current model which MVC 2.0 supports you'll have a single Web project for each area, but that is not necessarily a requirement. Phil Haacked has some code for ASP.NET MVC Single Project Areas if you're looking for another example of the technique, although you, personally, will probably benefit more from the first article.
So long as you define good routes that have clear and measurable constraints, you shouldn't have too much trouble laying out the website you've described.
I ended up creating a Custom ActionFilter and check the sitecode in the OnActionExecuting event. That seems to work well and fit better than the IRouteConstraint.

asp.net mvc - subfolders

How does the new Microsoft asp.net mvc implementation handle partitioning your application - for example:
--index.aspx
--about.aspx
--contact.aspx
--/feature1
--/feature1/subfeature/action
--/feature2/subfeature/action
I guess what I am trying to say is that it seems everything has to go into the root of the views/controllers folders which could get unwieldy when working on a project that if built with web forms might have lots and lots of folders and sub-folders to partition the application.
I think I get the MVC model and I like the look of it compared to web forms but still getting my head round how you would build a large project in practice.
There isn't any issues with organizing your controllers. You just need to setup the routes to take the organization into consideration. The problem you will run into is finding the view for the controller, since you changed the convention. There isn't any built in functionality for it yet, but it is easy to create a work around yourself with a ActionFilterAttribute and a custom view locator that inherits off ViewLocator. Then when creating your controller, you just specify what ViewLocator to use, so the controller knows how to find the view. I can post some code if needed.
This method kind of goes along with some advice I gave another person for separating their views out for a portal using ASP.NET MVC. Here is the link to the question as a reference.
In terms of how you arrange your views, you can put your views in subfolders if you'd like and create your own view structure. All views can always be referenced by their full path using the ~syntax. So if you put Index.aspx in \Views\Feature1\Home then you could reference that view using ~/Views/Feature1/Home/Index.aspx.
Here's two good blog posts that I found that may help other readers:
http://stephenwalther.com/blog/archive/2008/07/23/asp-net-mvc-tip-24-retrieve-views-from-different-folders.aspx
This one talks a little more in-depth about what Haacked described above.
http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx
This is a nice alternative for grouping your site into "areas."

Resources