/// <summary> /// Gets the permanent URL for the <see cref="WxeFunction"/> of the specified <paramref name="functionType"/> /// and using the <paramref name="urlParameters"/>. /// </summary> /// <include file='..\doc\include\ExecutionEngine\WxeContext.xml' path='WxeContext/GetPermanentUrl/param[@name="functionType" or @name="urlParameters" or @name="useParentPermanentUrl"]' /> public string GetPermanentUrl(Type functionType, NameValueCollection urlParameters, bool useParentPermanentUrl) { ArgumentUtility.CheckNotNull("urlParameters", urlParameters); string permanentUrl = WxeContext.GetPermanentUrl(_httpContext, functionType, urlParameters, true); if (useParentPermanentUrl) { if (urlParameters[WxeHandler.Parameters.ReturnUrl] != null) { throw new ArgumentException("The 'urlParameters' collection must not contain a 'ReturnUrl' parameter when creating a parent permanent URL.", "urlParameters"); } int maxLength = Configuration.WebConfiguration.Current.ExecutionEngine.MaximumUrlLength; string currentFunctionUrl = UrlUtility.AddParameters(_httpContext.Request.Url.AbsolutePath, _queryString, _httpContext.Response.ContentEncoding); StringCollection parentPermanentUrls = ExtractReturnUrls(currentFunctionUrl); int count = GetMergeablePermanentUrlCount(permanentUrl, parentPermanentUrls, maxLength); string parentPermanentUrl = FormatParentPermanentUrl(parentPermanentUrls, count); if (!string.IsNullOrEmpty(parentPermanentUrl)) { permanentUrl = UrlUtility.AddParameter(permanentUrl, WxeHandler.Parameters.ReturnUrl, parentPermanentUrl, _httpContext.Response.ContentEncoding); } } return(permanentUrl); }
public void ExecuteSubFunction_WithPermaUrl_WithParentPermaUrl_DoNotReturnToCaller_GoesToRedirectingToSubFunction () { WxeContext.QueryString.Add ("Key", "NewValue"); WxePermaUrlOptions permaUrlOptions = new WxePermaUrlOptions (true); IExecutionState executionState = CreateExecutionState (permaUrlOptions, WxeReturnOptions.Null); ExecutionStateContextMock.Expect (mock => mock.SetExecutionState (Arg<RedirectingToSubFunctionState>.Is.NotNull)) .WhenCalled ( invocation => { var nextState = CheckExecutionState ((RedirectingToSubFunctionState) invocation.Arguments[0]); Assert.That (nextState.Parameters.SubFunction.ReturnUrl, Is.EqualTo ("DefaultReturn.html")); string destinationUrl = UrlUtility.AddParameters ( "/session/sub.wxe", new NameValueCollection { { "Parameter1", "OtherValue" }, { WxeHandler.Parameters.WxeFunctionToken, SubFunction.FunctionToken }, { WxeHandler.Parameters.ReturnUrl, "/root.wxe?Key=NewValue" } }, Encoding.Default); Assert.That (nextState.Parameters.DestinationUrl, Is.EqualTo (destinationUrl)); }); MockRepository.ReplayAll(); executionState.ExecuteSubFunction (WxeContext); MockRepository.VerifyAll(); }
public void AddParametersToUrl() { string url = "http://localhost/Default.html"; string parameter1 = "Parameter1"; string parameter2 = "Parameter2"; string value1 = "Value1ä#"; string value2 = "Value2"; NameValueCollection queryString = new NameValueCollection(); queryString.Add(parameter1, value1); queryString.Add(parameter2, value2); string expected = string.Format( "{0}?{1}={2}&{3}={4}", url, parameter1, HttpUtility.UrlEncode(value1, _currentEncoding), parameter2, HttpUtility.UrlEncode(value2, _currentEncoding)); string actual = UrlUtility.AddParameters(url, queryString, _currentEncoding); Assert.That(actual, Is.EqualTo(expected)); }
/// <summary> /// Adds the parameters required for selecting the <paramref name="menuTab"/> to the <paramref name="url"/>. /// </summary> /// <param name="url"> The URL. Must not be <see langword="null"/> or empty. </param> /// <param name="menuTab"> /// The <see cref="MenuTab"/> that should be selected by the <paramref name="url"/>. /// Must not be <see langword="null"/>. /// </param> /// <returns> The <paramref name="url"/> extended with the parameters required by this <see cref="TabbedMenu"/>. </returns> public string FormatUrl(string url, MenuTab menuTab) { ArgumentUtility.CheckNotNullOrEmpty("url", url); NameValueCollection urlParameters = GetUrlParameters(menuTab); url = UrlUtility.AddParameters(url, urlParameters); return(url); }
/// <summary> Gets the absolute path to the WXE handler used for the current function. </summary> /// <param name="queryString"> An optional list of URL parameters to be appended to the path. </param> protected internal string GetPath(NameValueCollection queryString) { if (queryString == null) { queryString = new NameValueCollection(); } string path = _httpContext.Response.ApplyAppPathModifier(_httpContext.Request.Url.AbsolutePath); return(UrlUtility.AddParameters(path, queryString, _httpContext.Response.ContentEncoding)); }
public void AddParametersToUrlNoParameters() { string url = "http://localhost/Default.html"; NameValueCollection queryString = new NameValueCollection(); string expected = url; string actual = UrlUtility.AddParameters(url, queryString, _currentEncoding); Assert.That(actual, Is.EqualTo(expected)); }
/// <summary> Creates a <see cref="CommandInfo"/> for the <see cref="HrefCommand"/>. </summary> /// <param name="parameters"> /// The strings inserted into the href attribute using <c>string.Format</c>. /// </param> /// <param name="onClick"> /// The string always rendered in the <c>onClick</c> tag of the anchor element. /// </param> /// <param name="additionalUrlParameters"> /// The <see cref="NameValueCollection"/> containing additional url parameters. /// Must not be <see langword="null"/>. /// </param> /// <param name="includeNavigationUrlParameters"> /// <see langword="true"/> to include URL parameters provided by <see cref="ISmartNavigablePage"/>. /// Defaults to <see langword="true"/>. /// </param> /// <exception cref="InvalidOperationException"> /// If called while the <see cref="Type"/> is not set to <see cref="CommandType.Href"/>. /// </exception> protected virtual CommandInfo GetCommandInfoForHrefCommand( string[] parameters, string onClick, NameValueCollection additionalUrlParameters, bool includeNavigationUrlParameters) { ArgumentUtility.CheckNotNull("parameters", parameters); ArgumentUtility.CheckNotNull("additionalUrlParameters", additionalUrlParameters); if (Type != CommandType.Href) { throw new InvalidOperationException("Call to GetCommandInfoForHrefCommand not allowed unless Type is set to CommandType.Href."); } string href = HrefCommand.FormatHref(parameters); if (includeNavigationUrlParameters) { ISmartNavigablePage page = null; if (OwnerControl != null) { page = OwnerControl.Page as ISmartNavigablePage; } if (page != null) { additionalUrlParameters = additionalUrlParameters.Clone(); NameValueCollectionUtility.Append(additionalUrlParameters, page.GetNavigationUrlParameters()); } } href = UrlUtility.AddParameters(href, additionalUrlParameters); if (OwnerControl != null) { href = OwnerControl.ResolveClientUrl(href); } return(CommandInfo.CreateForLink( StringUtility.EmptyToNull(_toolTip), StringUtility.EmptyToNull(_accessKey), href, StringUtility.EmptyToNull(HrefCommand.Target), StringUtility.EmptyToNull(onClick))); }
/// <summary> Gets the absolute path that resumes the function with specified token. </summary> /// <param name="path"> The path to the <see cref="WxeHandler"/>. Must not be <see langword="null"/> or emtpy. </param> /// <param name="functionToken"> /// The function token of the function to resume. Must not be <see langword="null"/> or emtpy. /// </param> /// <param name="queryString"> An optional list of URL parameters to be appended to the <paramref name="path"/>. </param> private string GetPath(string path, string functionToken, NameValueCollection queryString) { ArgumentUtility.CheckNotNullOrEmpty("path", path); ArgumentUtility.CheckNotNullOrEmpty("functionToken", functionToken); if (path.IndexOf("?") != -1) { throw new ArgumentException("The path must be provided without a query string. Use the query string parameter instead.", "path"); } if (queryString == null) { queryString = new NameValueCollection(); } else { queryString = NameValueCollectionUtility.Clone(queryString); } queryString.Set(WxeHandler.Parameters.WxeFunctionToken, functionToken); path = UrlUtility.GetAbsoluteUrl(_httpContext, path); return(UrlUtility.AddParameters(path, queryString, _httpContext.Response.ContentEncoding)); }
/// <summary> /// Implements <see cref="Remotion.Web.UI.ISmartNavigablePage.AppendNavigationUrlParameters">ISmartNavigablePage.AppendNavigationUrlParameters</see>. /// </summary> public string AppendNavigationUrlParameters(string url) { NameValueCollection urlParameters = GetNavigationUrlParameters(); return(UrlUtility.AddParameters(url, urlParameters)); }