温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:UrlReWrite(Url重写或伪静态)完美示例源码
当前文件:
UrlReWriter/UrlRewriter/URLRewriter.Form.cs[2K,2009-6-12 11:57:50],打开代码结构图
UrlReWriter/UrlRewriter/URLRewriter.Form.cs[2K,2009-6-12 11:57:50],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Web; 5
using System.Web.Security; 6
using System.Web.UI; 7
using System.Web.UI.WebControls; 8
using System.Web.UI.WebControls.WebParts; 9
using System.Web.UI.HtmlControls; 10
11
/// <summary> 12
/// FormRewriter 的摘要说明 13
/// </summary> 14
namespace URLRewriter.Form 15
{ 16
public class FormRewriterControlAdapter : System.Web.UI.Adapters.ControlAdapter 17
{ 18
public FormRewriterControlAdapter() 19
{ 20
} 21
22
protected override void Render(HtmlTextWriter writer) 23
{ 24
base.Render(new RewriteFormHtmlTextWriter(writer)); 25
} 26
} 27
28
public class RewriteFormHtmlTextWriter : HtmlTextWriter 29
{ 30
public RewriteFormHtmlTextWriter(HtmlTextWriter writer) 31
: base(writer) 32
{ 33
base.InnerWriter = writer.InnerWriter; 34
} 35
public RewriteFormHtmlTextWriter(System.IO.TextWriter writer) 36
: base(writer) 37
{ 38
base.InnerWriter = writer; 39
} 40
41
public override void WriteAttribute(string name, string value, bool fEncode) 42
{ 43
//If the attribute we are writing is the "action" attribute, and we are not on a sub-control, 44
//then replace the value to write with the raw URL of the request - which ensures that we'll 45
//preserve the PathInfo value on postback scenarios 46
if (name == "action") 47
{ 48
HttpContext context = HttpContext.Current; 49
if (context.Items["ActionAlreadyWritten"] == null) 50
{ 51
//We will use the Request.RawUrl property within ASP.NET to retrieve the origional 52
//URL before it was re-written. 53
value = context.Request.RawUrl; 54
//Indicate that we've already rewritten the <form>'s action attribute to prevent 55
//us from rewriting a sub-control under the <form> control 56
context.Items["ActionAlreadyWritten"] = true; 57
} 58
} 59
base.WriteAttribute(name, value, fEncode); 60
} 61
} 62
63
}








}