我有一个网站,它有一个自定义控件适配器,用于重写表单上的操作。(这是我们从另一个机构继承的站点)当以调试模式在 localhost 上运行时,一切正常。但是,一旦我将站点发布到我们的 QA 环境中的服务器,自定义适配器就会停止触发。
我已经发布了调试符号并附加到 w3wp 进程。单步执行页面加载过程和自定义控件适配器中设置的断点永远不会被命中。当您在本地主机上调试时,它们会在每次页面加载时触发。生产代码在同一台服务器上运行,生产中的自定义控制适配器正在工作。但是,我们需要对生产进行更新,我们担心会破坏生产站点。
有谁知道为什么自定义控制适配器不会在服务器上触发?我以前从未使用过自定义适配器,除了将适配器放入 App_Code 文件夹和 App_Browser 文件夹中的 .browser 文件中的条目之外,还有什么需要做的吗?
App_Code 文件夹中的适配器代码:
public class FormRewriterControlAdapter : System.Web.UI.Adapters.ControlAdapter {
protected override void Render(System.Web.UI.HtmlTextWriter writer) {
base.Render(new RewriteFormHtmlTextWriter(writer));
}
}
public class RewriteFormHtmlTextWriter : HtmlTextWriter {
public RewriteFormHtmlTextWriter(HtmlTextWriter writer)
: base(writer) {
InnerWriter = writer.InnerWriter;
}
public RewriteFormHtmlTextWriter(TextWriter writer)
: base(writer) {
InnerWriter = writer;
}
public override void WriteAttribute(string name, string value, bool fEncode) {
// if the attribute we are writing is the "action" attribute, and we are not on a sub-control,
// then replace the value to write with the raw URL of the request - which ensures that we//ll
// preserve the PathInfo value on postback scenarios
if (name == "action") {
HttpContext Context = HttpContext.Current;
if (Context.Items["ActionAlreadyWritten"] == null) {
// Because we are using the UrlRewriting.net HttpModule, we will use the
// Request.RawUrl property within ASP.NET to retrieve the origional URL
// before it was re-written. You//ll want to change the line of code below
// if you use a different URL rewriting implementation.
value = Context.Request.RawUrl;
// Indicate that we//ve already rewritten the <form>//s action attribute to prevent
// us from rewriting a sub-control under the <form> control
Context.Items["ActionAlreadyWritten"] = true;
}
}
base.WriteAttribute(name, value, fEncode);
}
}
还有我在 App_Browser 文件夹中的 .browser 文件:
<browsers>
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="FormRewriterControlAdapter" />
<!--<adapter controlType="System.Web.UI.HtmlControls.HtmlLink" adapterType="LinkRewriterControlAdapter" />-->
</controlAdapters>
</browser>
</browsers>