94 lines
3.1 KiB
C#
94 lines
3.1 KiB
C#
using Org.BouncyCastle.Asn1.Ocsp;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using System.Text;
|
|
|
|
namespace Sarand.Net.Standard.Base.Net
|
|
{
|
|
public static class WebUtil
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// H T M L E n c o d i n g
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Converts a string to an HTML-encoded string.</summary>
|
|
public static String HtmlEncode(this String value)
|
|
{
|
|
if (StringUtil.IsEmpty(value)) return value;
|
|
return WebUtility.HtmlEncode(value);
|
|
}
|
|
/// <summary>Converts a string that has been HTML-encoded for HTTP transmission into a decoded string.</summary>
|
|
public static String HtmlDecode(this String value)
|
|
{
|
|
if (StringUtil.IsEmpty(value)) return value;
|
|
return WebUtility.HtmlDecode(value);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// U R L E n c o d i n g
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Converts a string to an HTML-encoded string.</summary>
|
|
public static String UrlEncode(this String value)
|
|
{
|
|
if (StringUtil.IsEmpty(value)) return value;
|
|
return WebUtility.UrlEncode(value);
|
|
}
|
|
/// <summary>Converts a string that has been HTML-encoded for HTTP transmission into a decoded string.</summary>
|
|
public static String UrlDecode(this String value)
|
|
{
|
|
if (StringUtil.IsEmpty(value)) return value;
|
|
return WebUtility.UrlDecode(value);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// URI Builder.
|
|
|
|
/// <summary>
|
|
/// Configure HTTP URI builder.
|
|
/// </summary>
|
|
public static UriBuilder ConfigureUriBuilder(this UriBuilder uriBuilder, String host, String path, String query = null)
|
|
{
|
|
uriBuilder.Scheme = "http";
|
|
uriBuilder.Host = StringUtil.OnBlank(host);
|
|
uriBuilder.Path = StringUtil.OnBlank(path);
|
|
uriBuilder.Query = StringUtil.OnBlank(query);
|
|
return uriBuilder;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create HTTP URI builder.
|
|
/// </summary>
|
|
public static UriBuilder CreateUriBuilder(String host, String path, String query = null)
|
|
{
|
|
UriBuilder uriBuilder = new UriBuilder();
|
|
return uriBuilder.ConfigureUriBuilder(host, path, query);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Configure HTTPS URI builder.
|
|
/// </summary>
|
|
public static UriBuilder ConfigureSslUriBuilder(this UriBuilder uriBuilder, String host, String path, String query = null)
|
|
{
|
|
uriBuilder.Scheme = "https";
|
|
uriBuilder.Port = 443;
|
|
uriBuilder.Host = StringUtil.OnBlank(host);
|
|
uriBuilder.Path = StringUtil.OnBlank(path);
|
|
uriBuilder.Query = StringUtil.OnBlank(query);
|
|
return uriBuilder;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create HTTPS URI builder.
|
|
/// </summary>
|
|
public static UriBuilder CreateSslUriBuilder(String host, String path, String query = null)
|
|
{
|
|
UriBuilder uriBuilder = new UriBuilder();
|
|
return uriBuilder.ConfigureSslUriBuilder(host, path, query);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
}
|