• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
    當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

    asp.net通過(guò)HttpModule自動(dòng)在Url地址上添加參數(shù)

    來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:43:32
    文檔

    asp.net通過(guò)HttpModule自動(dòng)在Url地址上添加參數(shù)

    asp.net通過(guò)HttpModule自動(dòng)在Url地址上添加參數(shù):然而手機(jī)客戶端又不支持Session和Cookie傳值,其他方法給頁(yè)面賦值再傳值顯得太麻煩了,而且還不易維護(hù),容易弄丟出錯(cuò),于是想到了用HttpModule來(lái)把cid參數(shù)賦在Url地址上,讓url把cid參數(shù)每頁(yè)自動(dòng)傳遞下去,需要用cid時(shí)只要通過(guò)Requet[cid]獲取
    推薦度:
    導(dǎo)讀asp.net通過(guò)HttpModule自動(dòng)在Url地址上添加參數(shù):然而手機(jī)客戶端又不支持Session和Cookie傳值,其他方法給頁(yè)面賦值再傳值顯得太麻煩了,而且還不易維護(hù),容易弄丟出錯(cuò),于是想到了用HttpModule來(lái)把cid參數(shù)賦在Url地址上,讓url把cid參數(shù)每頁(yè)自動(dòng)傳遞下去,需要用cid時(shí)只要通過(guò)Requet[cid]獲取

    然而手機(jī)客戶端又不支持Session和Cookie傳值,其他方法給頁(yè)面賦值再傳值顯得太麻煩了,而且還不易維護(hù),容易弄丟出錯(cuò),于是想到了用HttpModule來(lái)把cid參數(shù)賦在Url地址上,讓url把cid參數(shù)每頁(yè)自動(dòng)傳遞下去,需要用cid時(shí)只要通過(guò)Requet["cid"]獲取,這樣就不用為傳值而煩惱了。
    以下是配置方法和源碼。

    1)在web.config配置文件中添加以下節(jié)點(diǎn)
    代碼如下:


    <httpModules>
    <add name="HttpModule" type="ThreeHegemony.Utility.AutoAddCid"/>
    </httpModules>

    2)通過(guò)繼承IHttpModule來(lái)實(shí)現(xiàn)url傳值。

    代碼
    代碼如下:


    using System;
    using System.Text;
    using System.Web;
    using System.IO;
    using System.Text.RegularExpressions;
    namespace ThreeHegemony.Utility
    {
    /// <summary>
    /// Auther: Jess.zou
    /// Create data: 2009-08-06
    /// Description: 該類作用在Url地址后自動(dòng)添加(cid)
    /// </summary>
    public class AutoAddCid : System.Web.IHttpModule
    {
    public void Init(HttpApplication context)
    {
    context.PostRequestHandlerExecute += new EventHandler(this.OnPreSendRequestContent);
    }
    protected void OnPreSendRequestContent(Object sender, EventArgs e)
    {
    System.Web.HttpApplication myContext = (System.Web.HttpApplication)sender;
    myContext.Response.Filter = new AppendSIDFilter(myContext.Response.Filter);
    }
    private void ReUrl_BeginRequest(object sender, EventArgs e)
    {
    string cid = "";
    string url = "";
    HttpContext context = ((HttpApplication)sender).Context;
    if (string.IsNullOrEmpty(context.Request.QueryString["cid"]))
    {
    if (context.Request.QueryString.Count == 0)
    {
    url = string.Format("{0}?cid={1}", context.Request.RawUrl, cid);
    }
    else
    {
    url = string.Format("{0}&cid={1}", context.Request.RawUrl, cid);
    }
    }
    context.RewritePath(url);
    }
    public void Dispose() { }
    public class AppendSIDFilter : Stream
    {
    private Stream Sink { get; set; }
    private long _position;
    private System.Text.StringBuilder oOutput = new StringBuilder();
    public AppendSIDFilter(Stream sink)
    {
    Sink = sink;
    }
    public override bool CanRead
    {
    get { return true; }
    }
    public override bool CanSeek
    {
    get { return true; }
    }
    public override bool CanWrite
    {
    get { return true; }
    }
    public override long Length
    {
    get { return 0; }
    }
    public override long Position
    {
    get { return _position; }
    set { _position = value; }
    }
    public override long Seek(long offset, System.IO.SeekOrigin direction)
    {
    return Sink.Seek(offset, direction);
    }
    public override void SetLength(long length)
    {
    Sink.SetLength(length);
    }
    public override void Close()
    {
    Sink.Close();
    }
    public override void Flush()
    {
    Sink.Flush();
    }
    public override int Read(byte[] buffer, int offset, int count)
    {
    return Sink.Read(buffer, offset, count);
    }
    public override void Write(byte[] buffer, int offset, int count)
    {
    if (string.IsNullOrEmpty(HttpContext.Current.Request["cid"]))
    {
    Sink.Write(buffer, 0, buffer.Length);
    return;
    }
    string content = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);
    Regex regex = new Regex(RegexResource.HREF, RegexOptions.IgnoreCase);
    Regex action_regex = new Regex(RegexResource.ACTION, RegexOptions.IgnoreCase);
    if (regex.IsMatch(content))
    {
    content = Regex.Replace(content, RegexResource.HREF, new MatchEvaluator(ReplaceSID), RegexOptions.Compiled | RegexOptions.IgnoreCase);
    }
    if (action_regex.IsMatch(content))
    {
    content = Regex.Replace(content, RegexResource.ACTION, new MatchEvaluator(ReplaceSID), RegexOptions.Compiled | RegexOptions.IgnoreCase);
    }
    byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(content);
    Sink.Write(data, 0, data.Length);
    }
    public static string ReplaceSID(Match match)
    {
    if (match.Value.IndexOf("cid=") != -1)
    {
    return match.Value;
    }
    string result;
    if (match.Value.IndexOf('?') == -1)
    {
    result = match.Value.Insert(match.Value.Length - 1, "?cid=" + HttpContext.Current.Request["cid"]);
    }
    else
    {
    result = match.Value.Insert(match.Value.Length - 1, "&cid=" + HttpContext.Current.Request["cid"]);
    }
    return result;
    }
    }
    }
    }

    聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    asp.net通過(guò)HttpModule自動(dòng)在Url地址上添加參數(shù)

    asp.net通過(guò)HttpModule自動(dòng)在Url地址上添加參數(shù):然而手機(jī)客戶端又不支持Session和Cookie傳值,其他方法給頁(yè)面賦值再傳值顯得太麻煩了,而且還不易維護(hù),容易弄丟出錯(cuò),于是想到了用HttpModule來(lái)把cid參數(shù)賦在Url地址上,讓url把cid參數(shù)每頁(yè)自動(dòng)傳遞下去,需要用cid時(shí)只要通過(guò)Requet[cid]獲取
    推薦度:
    • 熱門焦點(diǎn)

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 精品一区二区三区四区| 亚洲国产精品18久久久久久| 亚洲日韩国产精品第一页一区| www亚洲欲色成人久久精品| 欧美精品福利视频| 久久精品国产免费| 一区二区国产精品 | 中文字幕精品无码久久久久久3D日动漫| 911亚洲精品国产自产| 亚洲精品久久久www| 国产精品9999久久久久| 亚洲一区无码精品色| 国产精品中文字幕在线观看| 国产高清在线精品一区二区三区| 亚洲精品无码永久在线观看 | 欧美日韩精品一区二区视频| 国产精品亚洲аv无码播放| 国内精品久久久久久久久电影网| 亚洲AV乱码久久精品蜜桃| 成人精品一区二区久久久| 国内精品久久久久影院一蜜桃| 老年人精品视频在线| 一区二区三区日韩精品| 国产精品亚洲欧美一区麻豆| 精品三级AV无码一区| 亚洲一区二区三区国产精品| 少妇亚洲免费精品| 日韩人妻无码精品无码中文字幕| 国产成人精品怡红院在线观看| 国产韩国精品一区二区三区久久| 日本VA欧美VA精品发布| 亚洲国产成人一区二区精品区| 无码人妻精品一区二区| 无码精品视频一区二区三区| 亚洲精品无码久久一线| 亚洲高清国产拍精品青青草原 | 久久国产精品77777| 杨幂国产精品福利在线观看| 国产久热精品无码激情| 国产精品无码一区二区三区电影| 精品国产污污免费网站入口在线|