views:

56

answers:

1

Is there any template based system available for .net? I have several domains i want to handle them using a single system. Each domain can have different design. But all will be manage through a single management system.

+1  A: 

Assuming that you mean that you want your app to select it's CSS and images folder dynamically based on the host name (domain name) in the request in order to skin your app based on the domain name, you could try something like this:

public static class Skin
{
   public static string Url(string assetPath)
   {
      var host = System.Web.HttpContext.Current.Request.Url.Host;
      switch (host)
      {
         case "www.myfirstsite.com":
            return UrlPath("~/Content/myfirst/" + assetPath.TrimStart('/'));
         case "www.theothersite.com/":
            return UrlPath("~/Content/theother/" + assetPath.TrimStart('/'));
         default:
            return UrlPath("~/Content/default/" + assetPath.TrimStart('/'));
      }
   }

   private static string UrlPath(string virtualPath) 
   {
      return VirtualPathUtility.ToAbsolute(virtualPath);
   }
}

Which would make all your views look something like this when referencing CSS and images:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
   <title>My Page</title>
   <link rel="stylesheet" type="text/css" href="<%= Skin.Url("css/master.css") %>" />
</head>
<body>
   <img src="<%= Skin.Url("images/myimg.gif") %>" alt="myimg" />
</body>
</html>
Tyler Jensen
Tyler's answer will work. The problem I have with it is that it's manageable only if you are expecting very few clients ( or additional domains) over a period of time. On the other hand if you expect a huge uptake of clients, the `switch` statement may become a burden to manage.
Ahmad
Try a more "dynamic" approach like LESS for .NET: http://www.dotlesscss.com/
queen3
I dont want to do this manually in my code. Is there already any CMS for managing such situation?
coure06
Yes, the switch can get ugly quickly. If you are managing a library of domains, you will surely want a database driven list of domains cached on the server. Refactor the code to pull from that cached collection, perhaps a key/value pair collection such as a Dictionary<string, string>.
Tyler Jensen