public XNode AsXNode(HttpResponseBase response) { return(new XElement("Skin", new XElement("Name", this.Name), new XElement("Banner", this.Banner), new XElement("PngFixSelector", this.PngFixSelector), new XElement("StyleSheets", from s in this.Stylesheets select new XElement("StyleSheet", response.ApplyAppPathModifier(s))), new XElement("Scripts", from s in this.Scripts select new XElement("Script", response.ApplyAppPathModifier(s))))); }
public static string GetWebUrl(HttpRequestBase request, HttpResponseBase response) { var appPath = request.ApplicationPath + (request.ApplicationPath.EndsWith("/") ? "" : "/"); if (!request.RequestContext.HttpContext.Session.IsCookieless) { return(appPath); } return(response.ApplyAppPathModifier(appPath)); }
public static string Create(HttpResponseBase response, byte[] hash, int size, ExportImageFormat format, IdenticonStyle style) { var parameters = new IdenticonRequest { Hash = hash, Size = size, Style = style, Format = format }; // Percent-encoding not needed as IdenticonRequest generates query string safe strings. return(response.ApplyAppPathModifier($"~/identicon.axd?{parameters}")); }
public void MyTestInitialize() { _mocks = new MockRepository(); _loggingService = _mocks.Stub <ILoggingService>(); _subscriptionListener = _mocks.StrictMock <IHubSubscriptionListener>(); _subscriptionService = _mocks.StrictMock <IHubSubscriptionService>(); _subscriptionPersistenceService = _mocks.StrictMock <IHubSubscriptionPersistenceService>(); MvcApplication.LoggingService = _loggingService; MvcApplication.Container = new WindsorContainer(); MvcApplication.Container.Kernel.AddComponentInstance <ILoggingService>(_loggingService); MvcApplication.Container.Kernel.AddComponentInstance <IHubSubscriptionListener>(_subscriptionListener); MvcApplication.Container.Kernel.AddComponentInstance <IHubSubscriptionService>(_subscriptionService); MvcApplication.Container.Kernel.AddComponentInstance <IHubSubscriptionPersistenceService>(_subscriptionPersistenceService); var routes = new RouteCollection(); MvcApplication.RegisterRoutes(routes); _request = _mocks.Stub <HttpRequestBase>(); SetupResult.For(_request.ApplicationPath).Return("/"); SetupResult.For(_request.Url).Return(new Uri("http://localhost/a", UriKind.Absolute)); SetupResult.For(_request.ServerVariables).Return(new System.Collections.Specialized.NameValueCollection()); SetupResult.For(_request.Params).Return(new System.Collections.Specialized.NameValueCollection()); _response = _mocks.Stub <HttpResponseBase>(); SetupResult.For(_response.ApplyAppPathModifier("/post1")).Return("http://localhost/post1"); var context = _mocks.Stub <HttpContextBase>(); var session = _mocks.Stub <HttpSessionStateBase>(); SetupResult.For(context.Request).Return(_request); SetupResult.For(context.Response).Return(_response); SetupResult.For(context.Session).Return(session); _controller = new HubSubscriptionController(_loggingService); _controller.ControllerContext = new ControllerContext(context, new RouteData(), _controller); _controller.Url = new UrlHelper(new RequestContext(context, new RouteData()), routes); }
public override string ApplyAppPathModifier(string virtualPath) { return(_httpResponseBase.ApplyAppPathModifier(virtualPath)); }
/// <summary> /// Gets any URI for the specified request that ensures it is being accessed by the proper protocol, if a match is found in the settings. /// </summary> /// <param name="request">The request to ensure proper access for.</param> /// <param name="response">The response to use if a redirection or other output is necessary.</param> /// <param name="security">The security setting to match.</param> /// <param name="settings">The settings used for any redirection.</param> /// <returns>A URL that ensures the requested resources matches the specified security; or null if the current request already does.</returns> public string GetUriForMatchedSecurityRequest(HttpRequestBase request, HttpResponseBase response, RequestSecurity security, Settings settings) { string targetUrl = null; // Evaluate the request's security. Logger.Log("Determining if the connection is secure."); bool isSecureConnection = _securityEvaluator.IsSecureConnection(request, settings); if (security == RequestSecurity.Secure && !isSecureConnection || security == RequestSecurity.Insecure && isSecureConnection) { Logger.Log("Calculating the target URI to switch to."); // Determine the target protocol and get any base target URL from the settings. string targetProtocolScheme; string baseTargetUrl; if (security == RequestSecurity.Secure) { targetProtocolScheme = Uri.UriSchemeHttps; baseTargetUrl = settings.BaseSecureUri; } else { targetProtocolScheme = Uri.UriSchemeHttp; baseTargetUrl = settings.BaseInsecureUri; } if (string.IsNullOrEmpty(baseTargetUrl)) { // If there is no base target URI, just switch the protocol scheme of the current request's URI. // * Account for cookie-less sessions by applying the application modifier. targetUrl = targetProtocolScheme + Uri.SchemeDelimiter + request.Url.Authority + response.ApplyAppPathModifier(request.RawUrl); } else { // Build the appropriate URI based on the specified target URL. var uri = new StringBuilder(baseTargetUrl); // - Use the full request path, but remove any sub-application path. uri.Append(request.RawUrl); if (request.ApplicationPath.Length > 1) { uri.Remove(baseTargetUrl.Length, request.ApplicationPath.Length); } // Normalize the URI. uri.Replace("//", "/", baseTargetUrl.Length - 1, uri.Length - baseTargetUrl.Length); targetUrl = uri.ToString(); } } return(targetUrl); }
public void SendConfirmationEmail(string email, HttpRequestBase request, HttpResponseBase response) { if (String.IsNullOrEmpty(email)) { throw new ArgumentNullException("email"); } MailAddress from = new MailAddress("*****@*****.**"); try { from = new MailAddress(this.Config.AdminEmail); } catch { } MailAddress to; try { to = new MailAddress(email); } catch { return; } using (var message = new MailMessage(from, to)) { String body = this.Config.ConfirmEmailText; String subject = this.Config.ConfirmEmailSubject; EmailConfirm confirm = new EmailConfirm { Email = email, Key = Guid.NewGuid() }; this.Db.EmailConfirms.InsertOnSubmit(confirm); this.Db.SubmitChanges(); String Link = request.Url.Scheme + Uri.SchemeDelimiter + request.Url.Authority + response.ApplyAppPathModifier("~/Account/Confirm?key=" + confirm.Key); try { message.Subject = subject; message.Body = String.Format(body, Link); message.IsBodyHtml = true; } catch (FormatException) { return; } try { using (var client = new SmtpClient(this.Config.SmtpHost, this.Config.SmtpPort)) { client.Send(message); } } catch { } } }
public override string ApplyAppPathModifier(string virtualPath) { return(proxiedResponse.ApplyAppPathModifier(virtualPath)); }