天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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

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

1)在web.config配置文件中添加以下節(jié)點
復制代碼 代碼如下:
<httpModules>
<add name="HttpModule" type="ThreeHegemony.Utility.AutoAddCid"/>
</httpModules>


2)通過繼承IHttpModule來實現(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地址后自動添加(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;
}
}
}
}

AspNet技術asp.net通過HttpModule自動在Url地址上添加參數(shù),轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久亚洲视频 | 光棍天堂在线a | 2020最新国产自产精品 | 国产成人高清视频 | 午夜福利免费0948视频 | 国产精品69人妻无码久久久 | 99久久99久久久精品齐齐鬼色 | 国内久经典AAAAA片 | 欧美又粗又长又大AAAA片 | 欧美阿v在线天堂 | 亚洲AV无码乱码在线观看浪潮 | 免费xxx成年大片 | 国产欧美国产综合第一区 | 99久久精品6在线播放 | 国产精品99久久久久久AV下载 | 粉色视频午夜网站入口 | 国产精品AV色欲蜜臀在线 | 国偷自产视频一区二区99 | 伦理片2499电影伦理片 | 欧美日韩亚洲成人 | 亚洲色 图| 打卡中国各地奋斗第一线 | 泡妞高手在都市完整版视频免费 | 日日摸夜夜嗷嗷叫日日拍 | 好男人在线观看视频观看高清视频免费 | 亚洲第一天堂无码专区 | 99热精品在线视频观看 | 一亲二脱三插 | 性一交一无一伦一精一品 | 果冻传媒在线观看高清完整免费 | 国产99久久久欧美黑人刘玥 | 4438成人情人网站 | 亚洲精品高清中文字幕完整版 | 色即是空 BT | 99久久综合| 娇妻让壮男弄的流白浆 | 内射人妻骚骚骚 | 印度最猛性ⅹxxxxx | 国产精品亚洲AV毛片一区二区三区 | 秋霞电影在线观看午夜伦 | 伊人天天躁夜夜躁狠狠 |