本文整理汇总了C#中UriBuilder类的典型用法代码示例。如果您正苦于以下问题:C# UriBuilder类的具体用法?C# UriBuilder怎么用?C# UriBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UriBuilder类属于命名空间,在下文中一共展示了UriBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnApply_Click
/// <summary>
/// Apply the changes and remain on this page
/// </summary>
public void btnApply_Click(object sender, System.EventArgs e)
{
if (SaveData())
{
//
// Redirect back to this page in Edit mode
//
if (DataEntryMode == PageDataEntryMode.AddRow)
{
UriBuilder EditUri = new UriBuilder(Request.Url);
EditUri.Query += string.Format("{0}={1}", "szh_id", m_szh_idCurrent);
//
// Redirect back to this page
// with the primary key information in the query string
//
Response.Redirect(EditUri.ToString());
}
else
{
lblMessage.Text = "Sazeh saved";
LoadData();
}
}
else
{
lblMessage.Text = "Error saving Sazeh";
DataEntryMode = PageDataEntryMode.ErrorOccurred;
}
}
示例2: MsiHackExtension
public MsiHackExtension()
{
/* Figure out where we are. */
string strCodeBase = Assembly.GetExecutingAssembly().CodeBase;
//Console.WriteLine("MsiHackExtension: strCodeBase={0}", strCodeBase);
UriBuilder uri = new UriBuilder(strCodeBase);
string strPath = Uri.UnescapeDataString(uri.Path);
//Console.WriteLine("MsiHackExtension: strPath={0}", strPath);
string strDir = Path.GetDirectoryName(strPath);
//Console.WriteLine("MsiHackExtension: strDir={0}", strDir);
string strHackDll = strDir + "\\MsiHack.dll";
//Console.WriteLine("strHackDll={0}", strHackDll);
try
{
IntPtr hHackDll = NativeMethods.LoadLibrary(strHackDll);
Console.WriteLine("MsiHackExtension: Loaded {0} at {1}!", strHackDll, hHackDll.ToString("X"));
}
catch (Exception Xcpt)
{
Console.WriteLine("MsiHackExtension: Exception loading {0}: {1}", strHackDll, Xcpt);
}
}
示例3: UriBuilder_Ctor_NullParameter_ThrowsArgumentException
public void UriBuilder_Ctor_NullParameter_ThrowsArgumentException()
{
Assert.Throws<ArgumentNullException>(() =>
{
UriBuilder builder = new UriBuilder((Uri)null);
});
}
示例4: TryReadQueryAsSucceeds
public void TryReadQueryAsSucceeds()
{
object value;
UriBuilder address = new UriBuilder("http://some.host");
address.Query = "a=2";
Assert.True(address.Uri.TryReadQueryAs(typeof(SimpleObject1), out value), "Expected 'true' reading valid data");
SimpleObject1 so1 = (SimpleObject1)value;
Assert.NotNull(so1);
Assert.Equal(2, so1.a);
address.Query = "b=true";
Assert.True(address.Uri.TryReadQueryAs(typeof(SimpleObject2), out value), "Expected 'true' reading valid data");
SimpleObject2 so2 = (SimpleObject2)value;
Assert.NotNull(so2);
Assert.True(so2.b, "Value should have been true");
address.Query = "c=hello";
Assert.True(address.Uri.TryReadQueryAs(typeof(SimpleObject3), out value), "Expected 'true' reading valid data");
SimpleObject3 so3 = (SimpleObject3)value;
Assert.NotNull(so3);
Assert.Equal("hello", so3.c);
address.Query = "c=";
Assert.True(address.Uri.TryReadQueryAs(typeof(SimpleObject3), out value), "Expected 'true' reading valid data");
so3 = (SimpleObject3)value;
Assert.NotNull(so3);
Assert.Equal("", so3.c);
address.Query = "c=null";
Assert.True(address.Uri.TryReadQueryAs(typeof(SimpleObject3), out value), "Expected 'true' reading valid data");
so3 = (SimpleObject3)value;
Assert.NotNull(so3);
Assert.Equal("null", so3.c);
}
示例5: OnActionExecuting
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var httpsPort = Convert.ToInt32(ConfigurationManager.AppSettings["httpsPort"]);
var httpPort = Convert.ToInt32(ConfigurationManager.AppSettings["httpPort"]);
var request = filterContext.HttpContext.Request;
var response = filterContext.HttpContext.Response;
if (httpsPort > 0 && RequireSecure)
{
string url = null;
if (httpsPort > 0)
{
url = "https://" + request.Url.Host + request.RawUrl;
if (httpsPort != 443)
{
var builder = new UriBuilder(url) { Port = httpsPort };
url = builder.Uri.ToString();
}
}
if (httpsPort != request.Url.Port)
{
filterContext.Result = new RedirectResult(url);
}
}
// se for uma conexao segura e não está requerendo um SSL, retira o ssl e volta para http.
else if (filterContext.HttpContext.Request.IsSecureConnection && !RequireSecure)
{
filterContext.Result = new RedirectResult(filterContext.HttpContext.Request.Url.ToString().Replace("https:", "http:").Replace(httpsPort.ToString(), httpPort.ToString()));
filterContext.Result.ExecuteResult(filterContext);
}
base.OnActionExecuting(filterContext);
}
示例6: page_command
protected void page_command(object sender, CommandEventArgs e)
{
int page = 1;
switch (e.CommandName) {
case "first": page = 1; break;
case "prev": page = Convert.ToInt32(Request.QueryString["page"]) - 1; break;
case "page": page = Convert.ToInt32(e.CommandArgument); break;
case "next": page = Convert.ToInt32(Request.QueryString["page"]) + 1; break;
case "last":
int count = global::User.FindUsers(Request.QueryString["name"]).Count;
page = Convert.ToInt32(Math.Ceiling((double)(count - 1) / (double)RESULTS));
break;
}
UriBuilder u = new UriBuilder(Request.Url);
NameValueCollection nv = new NameValueCollection(Request.QueryString);
nv["page"] = page.ToString();
StringBuilder sb = new StringBuilder();
foreach (string k in nv.Keys)
sb.AppendFormat("&{0}={1}", k, nv[k]);
u.Query = sb.ToString();
Response.Redirect(u.Uri.ToString());
}
示例7: GetDomain
public static void GetDomain(string fromUrl, out string domain, out string subDomain)
{
domain = "";
subDomain = "";
try
{
if (fromUrl.IndexOf("����Ƭ") > -1)
{
subDomain = fromUrl;
domain = "��Ƭ";
return;
}
UriBuilder builder = new UriBuilder(fromUrl);
fromUrl = builder.ToString();
Uri u = new Uri(fromUrl);
if (u.IsWellFormedOriginalString())
{
if (u.IsFile)
{
subDomain = domain = "�ͻ��˱����ļ�·��";
}
else
{
string Authority = u.Authority;
string[] ss = u.Authority.Split('.');
if (ss.Length == 2)
{
Authority = "www." + Authority;
}
int index = Authority.IndexOf('.', 0);
domain = Authority.Substring(index + 1, Authority.Length - index - 1).Replace("comhttp","com");
subDomain = Authority.Replace("comhttp", "com");
if (ss.Length < 2)
{
domain = "����·��";
subDomain = "����·��";
}
}
}
else
{
if (u.IsFile)
{
subDomain = domain = "�ͻ��˱����ļ�·��";
}
else
{
subDomain = domain = "����·��";
}
}
}
catch
{
subDomain = domain = "����·��";
}
}
示例8: GetCodeBaseDirectory
/// <summary>
/// Gets the assembly's location, i.e. containing directory.
/// </summary>
/// <param name="assembly">The assembly whose location to return.</param>
/// <returns><see cref="System.String" /> representing the assembly location.</returns>
public static string GetCodeBaseDirectory(this Assembly assembly)
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
示例9: Start
/// <summary>
/// Start the Uri with the base uri
/// </summary>
/// <param name="etsyContext">the etsy context</param>
/// <returns>the Uri builder</returns>
public static UriBuilder Start(EtsyContext etsyContext)
{
UriBuilder instance = new UriBuilder(etsyContext);
instance.Append(etsyContext.BaseUrl);
return instance;
}
示例10: Main
static void Main(string[] args)
{
Console.WriteLine("---------------------------------------------------------");
Console.WriteLine("Preparing nServer...");
// prepare primary endpoint URL
UriBuilder uriBuilder = new UriBuilder("http",
Server.Configurations.Server.Host,
Server.Configurations.Server.Port);
Console.WriteLine(String.Format("Setting up to listen for commands on {0}...", uriBuilder.Uri.ToString()));
// register controllers
Console.WriteLine("Registering all controllers...");
Server.Controllers.ControllerManager.RegisterAllControllers();
// start it up
nServer server = new nServer(uriBuilder.Uri);
nServer.CurrentInstance = server;
server.IncomingRequest += RequestHandler.HandleIncomingRequest;
server.Start();
// ping to test it's alive and ready
Console.WriteLine("Pinging to confirm success...");
uriBuilder.Path = "server/ping";
WebRequest request = WebRequest.Create(uriBuilder.Uri);
WebResponse response = request.GetResponse();
response.Close();
Console.WriteLine("nServer ready to accept requests...");
Console.WriteLine("---------------------------------------------------------");
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!YZAuthHelper.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
return;
}
UriBuilder uriBuilder = new UriBuilder(this.Request.Url);
string host = this.Request.Headers["host"];
if (!String.IsNullOrEmpty(host))
{
int index = host.LastIndexOf(':');
if (index != -1)
{
string port = host.Substring(index + 1);
uriBuilder.Port = Int32.Parse(port);
}
}
Uri uri = uriBuilder.Uri;
string url = uri.GetLeftPart(UriPartial.Authority);
string virtualPath = HttpRuntime.AppDomainAppVirtualPath;
if (virtualPath == "/")
virtualPath = String.Empty;
url = url + virtualPath + "/";
string jscode = String.Format("var rootUrl='{0}';\n var userAccount = '{1}';", url, YZAuthHelper.LoginUserAccount);
HtmlGenericControl js = new HtmlGenericControl("script");
js.Attributes["type"] = "text/javascript";
js.InnerHtml = jscode;
// this.Page.Header.Controls.AddAt(0, js);
}
示例12: Uri
public Uri(UriBuilder builder)
{
scheme = builder.getScheme();
authority = builder.getAuthority();
path = builder.getPath();
query = builder.getQuery();
fragment = builder.getFragment();
queryParameters = new Dictionary<string,List<string>>(builder.getQueryParameters());
StringBuilder _out = new StringBuilder();
if (!String.IsNullOrEmpty(scheme))
{
_out.Append(scheme).Append(':');
}
if (!String.IsNullOrEmpty(authority))
{
_out.Append("//").Append(authority);
}
if (!String.IsNullOrEmpty(path))
{
_out.Append(path);
}
if (!String.IsNullOrEmpty(query))
{
_out.Append('?').Append(query);
}
if (!String.IsNullOrEmpty(fragment))
{
_out.Append('#').Append(fragment);
}
text = _out.ToString();
}
示例13: FixIpv6Hostname
// Originally: TcpChannelListener.FixIpv6Hostname
private static void FixIpv6Hostname(UriBuilder uriBuilder, Uri originalUri)
{
if (originalUri.HostNameType == UriHostNameType.IPv6)
{
string ipv6Host = originalUri.DnsSafeHost;
uriBuilder.Host = string.Concat("[", ipv6Host, "]");
}
}
示例14: AssemblyLocation
static AssemblyLocation()
{
var assembly = typeof(AssemblyLocation).Assembly;
var uri = new UriBuilder(assembly.CodeBase);
var currentAssemblyPath = Uri.UnescapeDataString(uri.Path);
CurrentDirectory = Path.GetDirectoryName(currentAssemblyPath);
ExeFileName = Path.GetFileNameWithoutExtension(currentAssemblyPath);
}
示例15: CurrentDirectory
public static string CurrentDirectory()
{
var assembly = typeof(AssemblyLocation).Assembly;
var uri = new UriBuilder(assembly.CodeBase);
var path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}