| 1234567891011121314151617181920212223242526272829 |
- using Microsoft.AspNetCore.Rewrite;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace NcGamesWebView.Extensions
- {
- public class RewriteSubdomainRule : IRule
- {
- public void ApplyRule(RewriteContext context)
- {
- var request = context.HttpContext.Request;
- var host = request.Host.Host;
- // Check if the host is subdomain.domain.com or subdomain.localhost for debugging
- if (Regex.IsMatch(host, @"^[A-Za-z\d]+\.(?:[A-Za-z\d]+\.[A-Za-z\d]+|localhost)$"))
- {
- string subdomain = host.Split('.')[0];
- //modifying the request path to let the routing catch the subdomain
- context.HttpContext.Request.Path = "/subdomain/" + subdomain + context.HttpContext.Request.Path;
- context.Result = RuleResult.ContinueRules;
- return;
- }
- context.Result = RuleResult.ContinueRules;
- return;
- }
- }
- }
|