asp.net2.0 URL重寫以及urlMappings問題(2)(2)_.Net教程
推薦:asp.net2.0 URL重寫以及urlMappings問題(1)在asp.net2.0中的urlMappings倒是非常好用,可惜暫不支持正則表達式,不過,好在如果用IHttpModule的話 不管什么樣的請求都會先經(jīng)過IHttpModule這樣就為URL重寫提供了一個好機會:
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
// //傳回完整的客戶端返回數(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)部實現(xiàn)機制是完全不一樣的 Web控件要比Html控件執(zhí)行效率要好 1. 使用起來也相當(dāng)方便,舉個簡單的例子,例如Button
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實例(可帶附件)
- js實現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進度條的實現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實現(xiàn)分頁示例代碼
- 相關(guān)鏈接:
- 教程說明:
.Net教程-asp.net2.0 URL重寫以及urlMappings問題(2)(2)
。