[英]ASP.NET - Who can use one web application and “host” many sites
I've a personal project, and the logic layer and database is equal, but I've two domains that the only thing that changes is the URL, and the master page. 我有一个个人项目,逻辑层和数据库是相等的,但是我有两个域,唯一更改的是URL和母版页。
What I need is a simple system to recognize the URL and show the correct site master, because I what use the same database with the configuration of ASP.NET tables, stored procedure and so one. 我需要一个简单的系统来识别URL并显示正确的网站主站点,因为我使用的是同一个数据库以及ASP.NET表,存储过程等的配置。
The most similar thing I've saw, it's the DNN portal system, but I don't need all the features, like separate login system. 我看到的最相似的东西是DNN门户系统,但是我不需要所有功能,例如单独的登录系统。
Thanks in advance. 提前致谢。
You could make the master page dynamic. 您可以使母版页动态化。 The host name can be found in:
主机名可以在以下位置找到:
HttpContext.Current.Request.ServerVariables["SERVER_NAME"]
You can use this inside the master page to change its output. 您可以在母版页中使用它来更改其输出。
I think something along these lines will get you what you need: 我认为遵循这些思路的东西可以满足您的需求:
In IIS, point both URLs to the same virtual directory, so they are both being served from the same place - 在IIS中,将两个URL都指向同一个虚拟目录,因此它们都是从同一位置提供的-
Add a PreInit
event to read the URL then load a MasterPage accordingly: 添加一个
PreInit
事件以读取URL,然后相应地加载一个MasterPage:
void Page_PreInit(Object sender, EventArgs e)
{
if(Request.Url.AbsoluteUri.Contains("mysite.com"))
{
this.MasterPageFile = "master page file goes here";
}
}
Hope that gets you in the right direction! 希望您能朝正确的方向前进!
我将更进一步,将所有不同的东西抽象化,然后使用依赖注入来解决您需要的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.