0

I am writing multitenant based application and I want to load custom view from storage base on url(tenant).

I type https://corporate.myapp.local/ in browser but in FileExistsmethod HttpContext.Current.Request.Url give me http://127.0.0.1/ it does not tell me which domain is this so i can get file base on domain and resolve tenantid

public class ViewPathProvider : VirtualPathProvider, ICustomVirtualPathProvider
    {
        VirtualPathProvider ICustomVirtualPathProvider.Instance => this;

        private readonly ILogger _logger;
        private readonly IThemeService _themeService;
        private readonly ISellutionSession _sellutionSession;

        public ViewPathProvider(ILogger logger, IThemeService themeService, ISellutionSession sellutionSession)
        {
            _logger = logger;
            _themeService = themeService;
            _sellutionSession = sellutionSession;
        }

        public override bool FileExists(string virtualPath)
        {

            _logger.Log($"CurrentCompanyId: {_sellutionSession.GetCurrentCompany(HttpContext.Current.Request.Url).CompanyId}");

            var isViewExist = Pages.IsExistByVirtualPath(virtualPath);
            return isViewExist || Previous.FileExists(virtualPath);
        }
SOF User
  • 7,590
  • 22
  • 75
  • 121
  • I have done something similar to this, however in the controller, just get the URL.Authority and use it to infer tenant identification – Saravanan Oct 29 '16 at 11:20

1 Answers1

0

You need to set up your Development environment to be able to accept sub domains, This can be accomplished by editing the applicationHost.config file and the host file on the machine.

need to change how IIS Express runs your development environment.

In Visual Studio 2015, right-click on the solution file.

Select 'Open Folder in File Explorer'

Go to the containing folder and look for a .vs folder.

Inside, there will be a config folder containing an applicationhost.config file.

Open it in your favorite text editor (I use Notepad++)

Under the Configuration/system.applicationHost/Sites, you should see your site in bindings with a port and localhost.

<binding protocol="http" bindingInformation="*:38254:localhost" />

Duplicate this line and add your subdomain to this binding.

<binding protocol="http" bindingInformation="*:38254:m.localhost" />

Save this file and reload your project.

Host File need to head to our Hosts file to modify that as well.

Go to C:\Windows\System32\Drivers\Etc in File Explorer. Open the HOSTS file (it has no extension) At the bottom of the hosts file, add the following two lines.

127.0.0.1    localhost
127.0.0.2    m.localhost

Save the file.

you need to give Visual Studio 2015 Administrative rights to use subdomains.

Now we can run our Visual Studio and see our subdomain actually run.st:3892

Here is a link to help you.

pool pro
  • 2,084
  • 12
  • 21