Multitenancy in asp.net web forms

核能气质少年 提交于 2020-01-02 23:13:38

问题


i have created a new web forms application in visual studio 2010 with just two pages Default.aspxand About.aspx. what i want is that when i debug the app in visual studio development server it and enter http://company1.localhost:1023 it should just display Default page with message This is default page for company1. How can i do it with just playing with url routing as opposed to doing settings in IIS
Note: I understand that multi-tenancy is a big word and should not be used for such a simple scenario but my requirements are simple. i would just run same instance of the application for each company with no extension points. This question could also be stated as how can i create subdomains programmatically.


回答1:


You have to configure IIS (and perhaps DNS) correctly for this work. For example, all your sub-domains should handle by the designated web-site in IIS. Typically, you may configure IIS to handle all host-headers if there are only single web site but in case of multiple web-sites, IIS is typically configured to differ by host header. So getting this configuration right is the important part for you.

Once you reach to the correct web-site, resource handling will be done by IIS meta-base. So in this case, it would re-direct to configured default resource for the site. If resource-name is present then extension (htm, aspx) will decide the handling. Aspx extensions will handled by ASP.NET and then all you need to do is to look up current host header and take a decision accordingly. For example,

protected void Page_Load(object sender, EventArgs e)
{
    if (request.Url.HostNameType == UriHostNameType.Dns)
    {
       var hostParts = Request.Url.Host.Split('.');
       // you may validate if sub-domain name is present or not
       lblMessage.Text = "This is default page for " + hostParts[0];
    }  
}


来源:https://stackoverflow.com/questions/9565961/multitenancy-in-asp-net-web-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!