简体   繁体   English

从.NET Web应用程序(MVC 3)自动绑定到IIS 7.5中的自定义域

[英]Automatically binding to custom domains in IIS 7.5 from .NET Web Application (MVC 3)

I am building a web application in which there will be a core library and database that is shared by many instances. 我正在构建一个Web应用程序,其中将有一个由许多实例共享的核心库和数据库。 To give a more concrete example lets say I have a blogging engine and users can sign up to their own blog which will act independently of the others on the system. 举一个更具体的例子,假设我有一个博客引擎,用户可以注册自己的博客,该博客将独立于系统中的其他博客而工作。

Each instance must have their own subdomain eg: http://john.extremeblogging.tld/ and also have the option to have their own domain mapped to it eg: http://jonnyblogger.tld/ 每个实例必须具有自己的子域,例如: http://john.extremeblogging.tld/ ,还可以选择将自己的域映射到它的域,例如: http://jonnyblogger.tld/

The problem I have is not knowing how to notify IIS 7.5 what to do when requests come in from either of those domains. 我遇到的问题是不知道如何从这些域中的任何一个域发出请求时通知IIS 7.5怎么办。 Is it as simple as setting this web application to the default site within IIS and the application can use the request headers to take the appropriate action? 将这个Web应用程序设置为IIS中的默认站点是否简单,并且该应用程序可以使用请求标头采取适当的操作?

It strikes me that this should be a pretty common task so I don't anticipate this to be too difficult to solve but at the moment I am not sure how to approach it. 令我吃惊的是,这应该是一个非常常见的任务,因此我认为这很难解决,但是目前我不确定该如何解决。

Any guidance is appreciated. 任何指导表示赞赏。

Thanks 谢谢

id ID

Its been very long this question was asked, but still answering it so it might be helpful to others in need. 这个问题被问了很长时间,但仍在回答,因此对有需要的人可能会有帮助。

I happened to work on a big SaaS based multi-tenant project which involved unique subdomains for each of the users site. 我碰巧在一个大型的基于SaaS的多租户项目上工作,该项目涉及每个用户站点的唯一子域。 User could design and manage the content on his own site. 用户可以在自己的网站上设计和管理内容。

On the registration of a tenant/user we can add domain binding with the IIS using C# following this link- 在租户/用户注册后,我们可以使用C#通过此链接添加与IIS的域绑定-

http://amitpatelit.com/2013/03/12/enter-iis-binding-entry-by-c-code/ http://amitpatelit.com/2013/03/12/enter-iis-binding-entry-by-c-code/

Alongside we need to check the host name from the request headers and get the subdomain name to fetch the subdomain specific data and interface etc. 同时,我们需要从请求标头中检查主机名,并获取子域名以获取子域特定的数据和接口等。

protected override void OnAuthorization(AuthorizationContext filter_context)
{
    var url = Request.Headers["HOST"];
    var index = url.IndexOf(".");
    if(index > 0)
    {
    var sub = url.Split('.')[0];
    FrontSiteData = CommonService.GetSiteData(sub);
    }
}

Please let me know if you require more information. 如果您需要更多信息,请告诉我。

Regards, 问候,

Manik 马尼克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM