asp.net2.0 URL重寫以及urlMappings問題(2)(2)_.Net教程
推薦:asp.net2.0 URL重寫以及urlMappings問題(1)在asp.net2.0中的urlMappings倒是非常好用,可惜暫不支持正則表達(dá)式,不過,好在如果用IHttpModule的話 不管什么樣的請(qǐng)求都會(huì)先經(jīng)過IHttpModule這樣就為URL重寫提供了一個(gè)好機(jī)會(huì):
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);
}
// The Write method actually does the filtering.
public override void Write(byte[] buffer, int offset, int count)
{
string szBuffer = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);
string ap = "action=\"";
int pos = -1;
if ((pos = szBuffer.IndexOf(ap)) != -1)
{
int epos = szBuffer.IndexOf("\"", pos ap.Length 1);
if (epos != -1)
{
szBuffer = szBuffer.Remove(pos ap.Length, epos - pos - ap.Length);
}
szBuffer = szBuffer.Insert(pos ap.Length, this.str);
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(szBuffer);
_sink.Write(data, 0, data.Length);
}
else
{
oOutput.Append(szBuffer);
}
//下面的這一段可以用來修改之間的內(nèi)容;
//Regex oEndFile = new Regex("", RegexOptions.IgnoreCase|RegexOptions.Compiled);
//if (oEndFile.IsMatch(szBuffer))
//{
// //Append the last buffer of data
// //附加上緩沖區(qū)中的最后一部分?jǐn)?shù)據(jù)
// oOutput.Append(szBuffer);
// //Get back the complete response for the client
// //傳回完整的客戶端返回?cái)?shù)據(jù)
// string szCompleteBuffer = oOutput.ToString().ToLower();
// int ipos = szCompleteBuffer.IndexOf("",ipos 7);
// string sp = szCompleteBuffer.Substring(ipos 7, epos - ipos );
// szCompleteBuffer = szCompleteBuffer.Remove(ipos 7,sp.Length-7);
// szCompleteBuffer = szCompleteBuffer.Insert(ipos 7, "dhz");
// // szCompleteBuffer = szCompleteBuffer.Replace(sp, "dhz");
// //No match, so write out original data
// //沒有匹配,因此寫入源代碼
// byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(szCompleteBuffer);
// _sink.Write(data, 0, data.Length);
//}
//else
//{
// oOutput.Append(szBuffer);
//}
}
}
分享:談?wù)凥tmlControl與WebControl的區(qū)別與用途Web控件和Html控件雖然好多功能相同并且長得很像 但是它們的內(nèi)部實(shí)現(xiàn)機(jī)制是完全不一樣的 Web控件要比Html控件執(zhí)行效率要好 1. 使用起來也相當(dāng)方便,舉個(gè)簡單的例子,例如Button
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實(shí)例(可帶附件)
- js實(shí)現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報(bào)表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實(shí)例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲(chǔ)過程實(shí)現(xiàn)分頁示例代碼
- 相關(guān)鏈接:
- 教程說明:
.Net教程-asp.net2.0 URL重寫以及urlMappings問題(2)(2)
。