当前位置: 代码迷 >> ASP.NET >> URL重写后,提交的有关问题
  详细解决方案

URL重写后,提交的有关问题

热度:7815   发布时间:2013-02-25 00:00:00.0
URL重写后,提交的问题!
我原来的页面是   company/Csynopsis.aspx
重写后   为   0002/companyshow.aspx
提交后会提交到   0002/Csynopsis.aspx?id=0002
改怎么解决这种页面提交的问题?



------解决方案--------------------------------------------------------
使用Adapter
<browsers>
<browser refID= "Default ">
<controlAdapters>
<adapter controlType= "System.Web.UI.HtmlControls.HtmlForm "
adapterType= "AspxBoy.DotNetJobs.Adapters.HtmlFormAdapter " />
</controlAdapters>
</browser>
</browsers>

//------------------------------------------------------------------------------
// <copyright company= "Meibo Wu www.AspxBoy.com ">
// Copyright (c) www.AspxBoy.com All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Reflection;
using System.IO;

namespace AspxBoy.DotNetJobs.Adapters
{
public class HtmlFormAdapter : System.Web.UI.Adapters.ControlAdapter
{

protected override void Render( System.Web.UI.HtmlTextWriter writer )
{
base.Render( new FormRewriteTextWriter( writer ) );
}

}

internal class FormRewriteTextWriter : HtmlTextWriter
{
private static readonly string alreadyRewirteKey = "AspxBoy.DotNetJobsCn.FormActionAlreadyRewrote ";
public FormRewriteTextWriter( TextWriter writer )
: base( writer )
{
if ( writer is HtmlTextWriter )
{
this.InnerWriter = ( writer as HtmlTextWriter ).InnerWriter;
}
else
{
this.InnerWriter = writer;
}
}

public override void WriteAttribute( string name , string value , bool fEncode )
{
HttpContext context = HttpContext.Current;
if ( name == "action " && context.Items[ alreadyRewirteKey ] == null )
{
value = context.Request.RawUrl;
context.Items[ alreadyRewirteKey ] = true;
}
base.WriteAttribute( name , value , fEncode );
}
}

}

------解决方案--------------------------------------------------------
UrlReWrite(Url重写或伪静态)完美示例源码,已利用ActionlessForm解决原始地址form回传的问题

http://www.51aspx.com/CV/UrlReWriter/
  相关解决方案