which means that after a postback (caused by a user control in the page), the URL in the address bar has changed to
/campaign.aspx?campaign=Testcampaign.
Everything works, so this is not a major problem, but to my eyes, it looks weird since I do think that the URL should stay the same since the URL rewriting module should modify the action URL on the form. I have used the urlrewriting.net module in non-umbraco sites without problems.
I'm having an additional issue where paths are being resolved incorrectly on the re-written pages too. But I assume when one is fixed the other will be sorted too.
I know it has been a while, but i'm clutching at straws. Did you manage to find a solution to this problem?
Actually, I've just found a solution to this, to remove the action tag altogether - then nothing seems to be changed further down the lifecycle... Obviously this will only be workable if you only ever have pages that postback to themselves
I read somewhere that it is dodgy to remove the action attribute as the behaviour is unspecified in the html spec so some browsers might break if you leave it blank, so I made it work like first example where it uses the RawUrl. I also changed it a little for .NET 4 so it wouldn't mess with any other stuff that the .NET form control does (the RenderAttributes function does quite a lot if you look at it in reflector):
public class UrlRewriteForm : System.Web.UI.HtmlControls.HtmlForm
{
protected override void RenderAttributes(HtmlTextWriter writer)
{
// Render attributes normally to a string
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
base.RenderAttributes(hw);
string s = sb.ToString();
// Replace action with custom action
string newAction = "action=\"" + HttpUtility.HtmlEncode(Context.Request.RawUrl) + "\"";
s = System.Text.RegularExpressions.Regex.Replace(s, "action=\".*?\"", newAction);
// Write the new attributes
writer.Write(s);
}
}
It's not particularly great, but it works OK for me :-)
Problems with url rewriting after user control postback
Hello all,
I am using url rewiriting to have nice looking URL in a campaign part of a new site:
I would like the URL /campaign/campaignname.aspx be rewritten to /campaign-aspx?campaign=campaignname .
I do this by adding
<add name="campaignrewrite"
virtualUrl="^~/campaign/(.*).aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/campaign.aspx?campaign=$1"
ignoreCase="true" />
in /config/UrlRewriting.config (I am using umbraco 4.0.2.1).
The rewriting works correctly, but in the generated HTML for the page /campaign/Testcampaign.aspx , I see that the form is defined as follows:
<form id="aspnetForm" action="/campaign.aspx?campaign=Testcampaign" method="post">
which means that after a postback (caused by a user control in the page), the URL in the address bar has changed to
/campaign.aspx?campaign=Testcampaign.
Everything works, so this is not a major problem, but to my eyes, it looks weird since I do think that the URL should stay the same since the URL rewriting module should modify the action URL on the form. I have used the urlrewriting.net module in non-umbraco sites without problems.
Does anyone have any ideas?
Regards,
Andreas Paulsson
Hello,
I'm new to umbraco, and have stumbled across exaclty the same issue. I posted about it here: http://our.umbraco.org/forum/developers/api-questions/12095-Url-Rewriting-tilda-no-longer-finding-site-root
I'm having an additional issue where paths are being resolved incorrectly on the re-written pages too. But I assume when one is fixed the other will be sorted too.
I know it has been a while, but i'm clutching at straws. Did you manage to find a solution to this problem?
Regards
Dean
I'm still looking for a solution to this, too...
In a traditional asp.net app, I'd have an overridden form control (pre 3.5 SP1), such as:
or with > 3.5 SP1, as simple as
Form1.Action = Context.Request.RawUrl
But that seems to be overridden somewhere in Umbraco 4.6... Is there something obvious I'm missing?
Many thanks,
Kev.
Actually, I've just found a solution to this, to remove the action tag altogether - then nothing seems to be changed further down the lifecycle... Obviously this will only be workable if you only ever have pages that postback to themselves
In the web.config
Now my URLs stay rewritten. Happy days :)
Thanks, that worked.
I read somewhere that it is dodgy to remove the action attribute as the behaviour is unspecified in the html spec so some browsers might break if you leave it blank, so I made it work like first example where it uses the RawUrl. I also changed it a little for .NET 4 so it wouldn't mess with any other stuff that the .NET form control does (the RenderAttributes function does quite a lot if you look at it in reflector):
It's not particularly great, but it works OK for me :-)
is working on a reply...