开发者

Any Asp.net or Asp.net MVC template based system?

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 w开发者_JS百科ill be manage through a single management system.


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">
<html xmlns="http://www.w3.org/1999/xhtml">
<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜