Reputation: 378
I'm currently working on a content managed multi-tenant application which will have an admin accessible set of pages and a public facing set of pages. I'm not worried too much about the admin accessible pages as I'm going to have a single admin URL all users use to log in to the admin area. The question I have concerns the public facing pages.
If we imagine that the admin pages allow you to create and manage content for a set of college websites, grouped by schools, and the public facing pages simply display that content.
I have set up the following route to handle accessing the public facing pages:
routes.MapRoute(
name: "Site",
url: "{schoolName}/{collegeName}/{controller}/{action}/{id}",
defaults: new { schoolName = "Oxford", collegeName = "Balliol", controller = "Home", action = "Index", id = UrlParameter.Optional }
);
This works fine, and calls the following controller action without issue:
public class HomeController
{
public ActionResult Index(string schoolName, string collegeName)
{
return View();
}
}
However I was wondering if there were a way to get this to work without having to always accept schoolName
and collegeName
as parameters in my controller action? I can see it becoming an issue if I always have to accept these parameters in every action I create for the public facing pages.
I was thinking of creating a PublicFacingController
which all public facing pages inherit from which contains properties for school name and college name. But I'm not sure how I'd go about populating them for use in the derived controllers without passing them as parameters to the action.
Upvotes: 1
Views: 105
Reputation: 46008
You can access Controller.Request property in your base controller to get values for the school and college.
Upvotes: 2