Multiple URLs and single codebase with ASP.NET MVC - 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

Related

how to implement search engine on existing mvc page

Suppose I have MVC application with some static and dynamic web pages. How to add search feature for such site?
I dont want to create simple page searching for the data contained in database, I want to be able to index whole pages as they are displayed to customer.
Any solution for ASP.NET MVC4/5?
Shell I use existing solution (which?) or create my own one ?
Disclaimer: it's the product of the company I work for.
You can use SearchUnit for indexing/searching MVC web sites. There's a free Community version, and a more powerful paid version.
I don't know the specifics of what you need, but it's easier to use and more rounded (eg. includes spell checking, many document format parsers) than other options such as Lucene (IMHO, let me know if you disagree).
MVC specifics are here.

How to add second application to MVC website

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?}");

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)

Flatpages equivalent for ASP.Net MVC

Django has the Flatpages app, which lets site admins change content on specific pages without changing code. Flatpage content i stored in the database, sort of like in a CMS. Flatpages are typically used for about-pages and such.
Are there any good equivalents for ASP.Net MVC? I.e., a convenient way to manage page-content persisted to a database.
No.
Django seems closer to a CMS then "ASP.NET MVC" which is both a framework and just a general design pattern.
Have a look at http://http://cmsmvc.codeplex.com, it allows you to create pages, and manage content on the page.
The solution is still in early stages, but it could help you out.

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.

Resources