zoukankan      html  css  js  c++  java
  • 重写跳转

    public static string ResolveUrl2(string relativeUrl)
    {
    if (relativeUrl == null) throw new ArgumentNullException("relativeUrl");

    if (relativeUrl.Length == 0 || relativeUrl[0] == '/' ||
    relativeUrl[0] == '\') return relativeUrl;

    int idxOfScheme =
    relativeUrl.IndexOf(@"://", StringComparison.Ordinal);
    if (idxOfScheme != -1)
    {
    int idxOfQM = relativeUrl.IndexOf('?');
    if (idxOfQM == -1 || idxOfQM > idxOfScheme) return relativeUrl;
    }

    StringBuilder sbUrl = new StringBuilder();
    sbUrl.Append(HttpRuntime.AppDomainAppVirtualPath);
    if (sbUrl.Length == 0 || sbUrl[sbUrl.Length - 1] != '/') sbUrl.Append('/');

    // found question mark already? query string, do not touch!
    bool foundQM = false;
    bool foundSlash; // the latest char was a slash?
    if (relativeUrl.Length > 1
    && relativeUrl[0] == '~'
    && (relativeUrl[1] == '/' || relativeUrl[1] == '\'))
    {
    relativeUrl = relativeUrl.Substring(2);
    foundSlash = true;
    }
    else foundSlash = false;
    foreach (char c in relativeUrl)
    {
    if (!foundQM)
    {
    if (c == '?') foundQM = true;
    else
    {
    if (c == '/' || c == '\')
    {
    if (foundSlash) continue;
    else
    {
    sbUrl.Append('/');
    foundSlash = true;
    continue;
    }
    }
    else if (foundSlash) foundSlash = false;
    }
    }
    sbUrl.Append(c);
    }

    return sbUrl.ToString();
    }

    人生匆匆几十年,BeYourself...
  • 相关阅读:
    获取浏览器类型和版本
    js 防抖、节流
    判断数据类型
    一个函数判断数据类型
    面试题3道
    如何处理循环的异步操作
    this的原理以及几种使用场景
    v-model原理解析
    小程序setData数据量过大时候会对渲染有影响吗?
    js中in关键字的使用方法
  • 原文地址:https://www.cnblogs.com/huagege/p/3564684.html
Copyright © 2011-2022 走看看