本文整理汇总了C#中UrlBuilder.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# UrlBuilder.ToString方法的具体用法?C# UrlBuilder.ToString怎么用?C# UrlBuilder.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UrlBuilder
的用法示例。
在下文中一共展示了UrlBuilder.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertUrlToExternal
public string ConvertUrlToExternal(PageData pageData = null, PageReference p = null)
{
if (pageData == null && p == null)
{
return string.Empty;
}
var page = pageData ?? _repository.Get<PageData>(p);
var pageUrlBuilder = new UrlBuilder(page.LinkURL);
Global.UrlRewriteProvider.ConvertToExternal(pageUrlBuilder, page.PageLink, Encoding.UTF8);
string pageURL = pageUrlBuilder.ToString();
UriBuilder uriBuilder = new UriBuilder(SiteDefinition.Current.SiteUrl);
uriBuilder.Path = pageURL;
var jj = ServiceLocator.Current.GetInstance<UrlResolver>().GetUrl(p);
if (uriBuilder.Path == "/")
return uriBuilder.Uri.AbsoluteUri;
string[] words = uriBuilder.Uri.AbsoluteUri.Split(new char[] {':', '/', '.'},
StringSplitOptions.RemoveEmptyEntries);
bool reoccurs = words.Count(q => q == "http") > 1;
if (reoccurs)
return uriBuilder.Uri.LocalPath.StartsWith("/") ? uriBuilder.Uri.LocalPath.Remove(0,1) : uriBuilder.Uri.LocalPath;
return uriBuilder.Uri.AbsoluteUri;
}
示例2: Serialize
/// <summary>
/// Serialize to XElement
/// </summary>
/// <returns></returns>
public override XElement Serialize(XNamespace namespaceXForms)
{
var builder = new UrlBuilder(GetFormAction());
if (this.RecipientEmailAddress != null)
{
builder.QueryCollection.Add("to", this.RecipientEmailAddress);
}
if (this.SenderEmailAddress != null)
{
builder.QueryCollection.Add("from", this.SenderEmailAddress);
}
if (this.EmailSubject != null)
{
builder.QueryCollection.Add("subject", this.EmailSubject);
}
var formElement = new XElement(namespaceXForms + "submit",
new XAttribute("action", builder.ToString()),
new XAttribute("method", string.Empty),
new XAttribute("name", "ctl00$FullRegion$FormControl$ctl11"));
var formLabelElement = new XElement(namespaceXForms + "label", this.ButtonText);
formElement.Add(formLabelElement);
return formElement;
}
示例3: GetExternalUrl
/// <summary>
/// Adds scheme and host to a relative url.
/// </summary>
/// <param name="input">Url</param>
/// <returns>String</returns>
public static string GetExternalUrl(this string input)
{
if (string.IsNullOrWhiteSpace(input))
{
return string.Empty;
}
var siteUri = HttpContext.Current != null
? HttpContext.Current.Request.Url
: SiteDefinition.Current.SiteUrl;
if (!input.StartsWith("/"))
{
input = "/" + input;
}
var urlBuilder = new UrlBuilder(input)
{
Scheme = siteUri.Scheme,
Host = siteUri.Host,
Port = siteUri.Port
};
return urlBuilder.ToString();
}
示例4: UrlBuilder_TestUrlShouldRemainTheSame_NoAdditionalQueryParameters
public void UrlBuilder_TestUrlShouldRemainTheSame_NoAdditionalQueryParameters(string url, string expected)
{
//Arrange
//Act
var builder = new UrlBuilder(url);
//Assert
Assert.AreEqual(expected, builder.ToString());
}
示例5: AddToQueryString_AddsCompleteString_ReturnsValueUrl
public void AddToQueryString_AddsCompleteString_ReturnsValueUrl(string url, string expected, string query)
{
//Arrange
var builder = new UrlBuilder(url);
//Act
builder.AddToQueryString(query);
//Assert
Assert.AreEqual(expected, builder.ToString());
}
示例6: GetUrl
/// <exclude />
public static string GetUrl(IMediaFile file, bool isInternal, bool downloadableMedia)
{
string url = MediaUrls.BuildUrl(file, isInternal ? UrlKind.Internal : UrlKind.Public);
if (!downloadableMedia) return url;
var urlBuilder = new UrlBuilder(url);
urlBuilder["download"] = "true";
return urlBuilder.ToString();
}
示例7: it_can_create_with_defaults
public void it_can_create_with_defaults()
{
// Arrange
var connectionString = "http://";
// Act
var builder = new UrlBuilder();
// Assert
Assert.AreEqual(null, builder.Server);
Assert.AreEqual(null, builder.EdgeMartName);
Assert.AreEqual(connectionString, builder.ToString());
}
示例8: it_can_create_with_a_host
public void it_can_create_with_a_host()
{
// Arrange
var connectionString = String.Format("http://{0}:{1}/remote", SERVER_NAME, DEFAULT_PORT.ToString());
// Act
var builder = new UrlBuilder() { Server = new ServerAddress(SERVER_NAME) };
// Assert
Assert.AreEqual(SERVER_NAME, builder.Server.Host);
Assert.AreEqual(DEFAULT_PORT, builder.Server.Port);
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new UrlBuilder(connectionString).ToString());
}
示例9: it_can_create_with_a_host_and_port
public void it_can_create_with_a_host_and_port()
{
// Arrange
Int32 port = 12345;
var connectionString = String.Format("http://{0}:{1}/remote", SERVER_NAME, port.ToString());
// Act
var builder = new UrlBuilder() { Server = new ServerAddress(SERVER_NAME, port) };
// Assert
Assert.AreEqual(SERVER_NAME, builder.Server.Host);
Assert.AreEqual(port, builder.Server.Port);
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new UrlBuilder(connectionString).ToString());
}
示例10: it_can_create_with_a_host_and_port_and_database
public void it_can_create_with_a_host_and_port_and_database()
{
// Arrange
Int32 port = 12345;
var connectionString = String.Format("http://{0}:{1}/remote?edgemart={2}", SERVER_NAME, port.ToString(), EDGEMART_NAME);
// Act
var builder = new UrlBuilder() { Server = new ServerAddress(SERVER_NAME, port), EdgeMartName = EDGEMART_NAME };
// Assert
Assert.AreEqual(SERVER_NAME, builder.Server.Host);
Assert.AreEqual(port, builder.Server.Port);
Assert.AreEqual(EDGEMART_NAME, builder.EdgeMartName);
Assert.AreEqual(connectionString, builder.ToString());
Assert.AreEqual(connectionString, new UrlBuilder(connectionString).ToString());
}
示例11: ExternalURLFromReference
public static string ExternalURLFromReference(this PageReference p)
{
PageData page = DataFactory.Instance.Get<PageData>(p);
UrlBuilder pageURLBuilder = new UrlBuilder(page.LinkURL);
Global.UrlRewriteProvider.ConvertToExternal(pageURLBuilder, page.PageLink, UTF8Encoding.UTF8);
string pageURL = pageURLBuilder.ToString();
UriBuilder uriBuilder = new UriBuilder(EPiServer.Web.SiteDefinition.Current.SiteUrl);
uriBuilder.Path = pageURL;
return uriBuilder.Uri.AbsoluteUri;
}
示例12: GetUrl
public static string GetUrl(this VariationContent variant, ILinksRepository linksRepository, UrlResolver urlResolver)
{
var productLink = variant.GetParentProducts(linksRepository).FirstOrDefault();
if (productLink == null)
{
return string.Empty;
}
var urlBuilder = new UrlBuilder(urlResolver.GetUrl(productLink));
if (variant.Code != null)
{
urlBuilder.QueryCollection.Add("variationCode", variant.Code);
}
return urlBuilder.ToString();
}
示例13: GetHtmlBodyForMail
public string GetHtmlBodyForMail(ContentReference mailReference, NameValueCollection nameValueCollection, string language)
{
var urlBuilder = new UrlBuilder(_urlResolver.GetUrl(mailReference, language))
{
QueryCollection = nameValueCollection
};
var basePath = _httpContextBase.Request.Url.GetLeftPart(UriPartial.Authority);
var relativePath = urlBuilder.ToString();
if (relativePath.StartsWith(basePath))
{
relativePath = relativePath.Substring(basePath.Length);
}
return _htmlDownloader.Download(basePath, relativePath);
}
示例14: CreateTransform
public TransformResult CreateTransform(CreateTransformParams parameters)
{
UrlBuilder urlBuilder = new UrlBuilder(
m_api.ApiUrlV.
ResourceType("transformations").
Add(parameters.Name).
BuildUrl());
urlBuilder.QueryString["transformation"] = parameters.Transform.Generate();
using (HttpWebResponse response = m_api.Call(
HttpMethod.POST, urlBuilder.ToString(), null, null))
{
TransformResult result = TransformResult.Parse(response);
return result;
}
}
示例15: GenerateUrl
public static string GenerateUrl(string controller, string action,
object[] parameters, List<KeyValuePair<string, string>> urlParam)
{
string appPath = HttpContextHandler.Instance.ApplicationPath.ToLower();
var url = new StringBuilder();
url.Append(appPath);
if (!string.IsNullOrEmpty(appPath) && !appPath.EndsWith("/"))
{
url.Append("/");
}
url.Append(controller.ToLower()).Append("/");
if (!string.IsNullOrEmpty(action))
{
url.Append(action.ToLower()).Append("/");
}
if (parameters != null)
{
foreach (var o in parameters)
{
if (o != null)
{
AppendParameter(url, o);
}
}
}
url.Length--;
if (WebSettings.MvcPostfix != "")
{
url.Append(WebSettings.MvcPostfix);
}
var s = url.ToString();
if(urlParam != null)
{
var ub = new UrlBuilder(s, Encoding.UTF8);
foreach (var kv in urlParam)
{
ub.Add(kv.Key, kv.Value);
}
return ub.ToString();
}
return s;
}