private static Tuple <string, string> GetSchemeHost(this IProvider prov, bool externalip = false) { Request req = prov?.Nancy?.Request; string host = req?.Url.HostName ?? WebOperationContext.Current?.IncomingRequest?.UriTemplateMatch ?.RequestUri.Host; string scheme = req?.Url.Scheme ?? WebOperationContext.Current?.IncomingRequest?.UriTemplateMatch ?.RequestUri.Scheme; if (host == null) { var context = System.ServiceModel.OperationContext.Current; if (context != null && context.IncomingMessageHeaders?.To != null) { Uri ur = context.IncomingMessageHeaders?.To; host = ur.Host; scheme = ur.Scheme; } } if (string.IsNullOrEmpty(host) || string.IsNullOrEmpty(scheme)) { return(null); } if (externalip) { IPAddress ip = NAT.GetExternalAddress(); if (ip != null) { host = ip.ToString(); } } return(new Tuple <string, string>(scheme, host)); }
private static Tuple <string, string> GetSchemeHost(this IProvider prov, bool externalip = false) { var req = prov?.HttpContext?.Request; string host = req?.Host.Host; string scheme = req?.Scheme; if (string.IsNullOrEmpty(host) || string.IsNullOrEmpty(scheme)) { return(null); } if (externalip) { IPAddress ip = NAT.GetExternalAddress(); if (ip != null) { host = ip.ToString(); } } return(new Tuple <string, string>(scheme, host)); }