使用母版页更改 ASP.NET 表单上的 URL
客户要求我们将在其自己的域上运行的网站移动到另一个应用程序的子文件夹中。
我已经使用 ISAPI 重写代理实现了这一点。
然而,有一种表单可以在网站中进行回发。从 ASP.NET 生成的操作 URL 是“/sign-up.aspx?”。这会将回发发送到站点的根目录。
我想将其更改为 "sign-up.aspx?" (无前导斜杠)。如果我不使用母版页,那就没问题,因为我可以获得对表单的引用并更改其操作(这是 .NET 3.5 SP1)。我尝试在我的控件中使用以下代码来获取对表单的引用,但它似乎没有做任何事情。它找到了表单,但操作未设置为该值。
HtmlForm form = ControlLocator.FindControl<HtmlForm>(Page.Master.Master, "form1");
form.Action = "sign-up.aspx?";
这是在 Page_Load 和 ControlLocator.FindControl 中的一个端口 http://www .west-wind.com/Weblog/posts/5127.aspx
有什么想法吗?
干杯, 抢
We've had a requirement from a client to move a site that is running on it's own domain to a subfolder of another app.
I've acheived this using ISAPI rewrite proxying.
However, there is one form that does a post back in the site. The generated url for the action from ASP.NET is "/sign-up.aspx?". This sends the postback to the root of the site.
I want to change this to "sign-up.aspx?" (no leading slash). This would be fine if I wasn't using Master pages as I could get a reference to the form and change it's action (this is .NET 3.5 SP1). I've tried to use the following code in my control to get a reference to the form but it doesn't seem to do anything. It finds the form but the action is not set to the value.
HtmlForm form = ControlLocator.FindControl<HtmlForm>(Page.Master.Master, "form1");
form.Action = "sign-up.aspx?";
This is in Page_Load and ControlLocator.FindControl is a port of this http://www.west-wind.com/Weblog/posts/5127.aspx
Any ideas?
Cheers,
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
很好解决你的问题。
但是对于那些想要更改 aspnetform 的操作 URL 的人,请在 Page_Load 事件中使用这个简单的代码(即使他们有一个母版页)。
Good to solve your problem.
But for whom that wants to change the action URL of aspnetform, use this simple code in the Page_Load event (even they have a master page).
您尝试过在 page_prerender 中执行此操作吗?
可能是所有主内容合并尚未在 page_load 中完成。假设 HtmlForm 是正确的类型,并且该表单实际上称为“form1” - 我确信这是正确的。
have you tried doing it in page_prerender?
It could be that all the master content merging has not yet been done in page_load. Assuming HtmlForm is the correct type and that the form is actually called 'form1' - which I'm sure is correct.
如果注册表单上有按钮,则可以使用
postBackUrl
属性可将回发重定向到不同的 URL。您可以在 “ASP.NET Web 中的跨页发布”下找到更多信息页”。
If you have a button on the signup form you could use the
postBackUrl
attribute of it to redirect the postback to a different URL.You can find more information on this under "Cross-page Posting in ASP.NET Web Pages".
最终发现是 umbraco 的 Form.browser 在我更改后重写了回发 url。 (很抱歉在我原来的问题中没有提到 umbraco 的使用)。
Eventually figured out that it was umbraco's Form.browser that was rewriting the post back url after I had changed it. (Apologies for not mentioning the use of umbraco in my original question).