我试图通过使用以下格式附加查询字符串的文件夹来隐藏用户的文档名称:
http://localhost:53779/s/?x=FF2F60195B21487FA19A8EE7767A206C
当我回发页面时,它会将其定向到物理页面:
http://localhost:53779/s/default.aspx?x=FF2F60195B21487FA19A8EE7767A206C
可以激活回发地址,以便我可以从客户端浏览器中省略default.aspx吗?
答案 0 :(得分:1)
自.Net 2.0(我认为)以来,您可以手动将Form的action属性设置为您想要的任何内容:
<form id="form1" runat="server" action="/">
您也可以在代码隐藏中执行此操作:
form1.Action = "/?" & Request.ServerVariables("QUERY_STRING")
答案 1 :(得分:0)
我正在使用此ControlAdapter将FORM元素的action属性修改为实际url。它对于重写网址也很有用。
public class FormRewriteAdapter : System.Web.UI.Adapters.ControlAdapter
{
[DebuggerStepThrough()]
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(System.IO.TextWriter writer)
: base(writer)
{
base.InnerWriter = writer;
}
public override void WriteAttribute(string name, string value, bool fEncode)
{
if ((name == "action"))
{
System.Web.HttpContext Context = System.Web.HttpContext.Current;
if (Context.Items["ActionAlreadyWritten"] == null)
{
value = Context.Request.RawUrl;
Context.Items["ActionAlreadyWritten"] = true;
}
}
base.WriteAttribute(name, value, fEncode);
}
}
您必须在App_Browsers目录中注册此适配器,如下所示:
<adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="MyNamaspace.FormRewriteAdapter" />