简体   繁体   English

ASP.NET-谁可以使用一个Web应用程序并“托管”许多站点

[英]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.

相关问题 ASP.NET 使用 Web.Config 控制端口号来托管 Web 应用程序项目 - ASP.NET Use Web.Config to control Port Number to host Web Application Project 如何在ASP.NET Web应用程序中托管多个Silverlight用户控件? - How To Host More Than One Silverlight User Controls In ASP.NET Web Application? 将ASP.NET MVC Core应用程序的[部分]发布到Web主机 - Publishing [part] of ASP.NET MVC Core application to web host ASP.Net Web应用程序连接到主机SQL数据库 - ASP.Net web application connect to host SQL DataBase 使用ASP.NET构建多语言网站 - Building Multilingual Web Sites with ASP.NET 如何使用服务器端文件来跟踪必须彼此交互的用户? ASP.NET/C# - How can I use server side file to track users who must interact with one another? ASP.NET/C# 自主ASP.NET Web API和自主信号R一起使用Windows服务应用程序 - Self-host ASP.NET Web API and Self-host SignalR together windows service application 检索浏览我的asp.net Web应用程序的客户端的Windows用户名 - Retrieve windows user name of client who browses my asp.net web application 我可以在ASP.NET Web应用程序中使用未编译的C ++代码吗? - Can I use uncompiled C++ code in ASP.NET web application? Asp.net 5(MVC 6)Web应用程序-不能使用电子邮件作为用户名 - Asp.net 5 (MVC 6) web application - can not use email as user name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM