国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問(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
主站蜘蛛池模板: 欧美精品国产日韩综合在线 | 日韩免费高清视频 | 69国产成人综合久久精品 | 欧美激情伊人 | 国产在线看不卡一区二区 | 国内精品久久久久久久久 | 自拍 欧美 在线 综合 另类 | 极品美女国产精品免费一区 | 一区二区三区网站 | 欧美一区二区日韩一区二区 | 在线亚洲欧美日韩 | 国产成人手机在线好好热 | 99久久精品国产一区二区小说 | 亚洲日本乱码中文论理在线电影 | 国产综合精品久久久久成人影 | 一级网站在线观看 | 国产九九热 | 欧美性一区二区三区五区 | 热久久国产 | a黄毛片 | 久久伊人精品一区二区三区 | 在线观看视频国产 | 国产精品天天看大片特色视频 | 日韩三 | 91中文字幕在线观看 | 欧美3p在线观看一区二区三区 | 国产一区二区高清 | 91精品导航 | 国产欧美高清 | 亚洲欧美日韩综合精品网 | 国产va在线观看 | 亚洲va欧美ⅴa国产va影院 | 可以免费看的毛片 | 欧美一区二区三区视频在线观看 | 成人国内精品久久久久影院 | 国产成人h福利小视频在线观看 | 国产高清美女一级a毛片久久 | 精品国产不卡一区二区三区 | 国产网站免费观看 | 国产精品久久久久久久久久免费 | 鸣人x钢手 |