当前位置: 代码迷 >> ASP.NET >> IIRF UrlRewrite PostBack地址有关问题
  详细解决方案

IIRF UrlRewrite PostBack地址有关问题

热度:1792   发布时间:2013-02-25 00:00:00.0
IIRF UrlRewrite PostBack地址问题
跟着老赵的教程做的, 出了些问题。(http://www.cnblogs.com/JeffreyZhao/archive/2008/01/13/Url-Rewrite-3)

就是点提交后就转成.aspx页面的,我想让它还是的, 得不到Request.ServerVariables["HTTP_X_REWRITE_URL"]的值 ,是空的, 不知道错在哪了?

普通Urlrewrite是可以了, 输入register 转到 register.aspx了
规则如下:
RewriteRule ^/nmn/member/(.*?)\ /nmn/member/$1.aspx [I, L, U]

点提交后就不灵了,也按老赵说的做了

C# code
namespace DOTA.Browser {    public class FormRewriterControlAdapter :            System.Web.UI.Adapters.ControlAdapter {        protected override void Render(HtmlTextWriter writer) {            base.Render(new RewriteFormHtmlTextWriter(writer));        }    }    public class RewriteFormHtmlTextWriter : HtmlTextWriter {        public RewriteFormHtmlTextWriter(HtmlTextWriter writer)            : base(writer) {            this.InnerWriter = writer.InnerWriter;        }        public RewriteFormHtmlTextWriter(TextWriter writer)            : base(writer) {            this.InnerWriter = writer;        }        public override void WriteAttribute(string name, string value, bool fEncode) {            if (name == "action") {                HttpContext context = HttpContext.Current;                if (context.Items["ActionAlreadyWritten"] == null) {                    value = context.Request.ServerVariables["HTTP_X_REWRITE_URL"] ?? context.Request.RawUrl;                    context.Response.Write(value);  //这里执行了,源代码里有,是Request.RawUrl的值。 HTTP_X_REWRITE_URL 这个是空的.                    context.Items["ActionAlreadyWritten"] = true;                }            }            base.WriteAttribute(name, value, fEncode);        }    }}


XML code
<browser refID="Default">        <controlAdapters>            <adapter controlType="System.Web.UI.HtmlControls.HtmlForm"                     adapterType="DOTA.Browser.FormRewriterControlAdapter" />        </controlAdapters>    </browser>



开发环境:
window XP sp2 IIS 5.1

vs 2008 .Net 2.0

IsapiRewrite4.dll


各位帮忙看看,谢谢!


------解决方案--------------------------------------------------------
Url重写的完整解决方案
------解决方案--------------------------------------------------------
http://blog.sina.com.cn/s/blog_497dbcd10100e3ay
------解决方案--------------------------------------------------------
...
------解决方案--------------------------------------------------------
为什么一定要用Request.ServerVariables["HTTP_X_REWRITE_URL"]。

试试别的, 比如Page.ReferURL
------解决方案--------------------------------------------------------
帮顶
------解决方案--------------------------------------------------------
帮顶