Zen Pak
Zen Pak

Reputation: 578

Issues with ASP.NET url rewrite and using an ASP.NET button with submit behaviour

I have issues with performing an ASP.NET URL rewrite when doing a form post using ASP.NET button submit behaviour. I am not sure what is wrong. When using GET method, my rewrite rules work fine but when i do a button click, the page maintains the rewritten url and appends the query string to it. I need to post from a page with rewritten url to another page without a rewrite. Below are my rewrite rules:

<rewrite>
            <rules>
                <rule name="Imported Rule 1">
                    <match url="^[a-zA-Z0-9|&amp;+-]+-([0-9]+)/?$" ignoreCase="false" />
                    <action type="Rewrite" url="products.aspx?Category={R:1}" appendQueryString="false" />
                </rule>
                <rule name="Imported Rule 2">
                    <match url="^[a-zA-Z0-9|&amp;+-]+-([0-9]+)/[a-zA-Z0-9|&amp;+-]+-([0-9]+)-([0-9]+)/?$" ignoreCase="false" />
                    <action type="Rewrite" url="productdetails.aspx?Product={R:3}&amp;Type={R:2}" appendQueryString="false" />
                </rule>
                <rule name="Imported Rule 3" stopProcessing="true">
                    <match url="^default\.aspx$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{THE_REQUEST}" pattern="^[A-Z]{3,9}\ /default\.aspx\ HTTP/" ignoreCase="false" />
                    </conditions>
                    <action type="Redirect" url="http://www.domain.com/" redirectType="Permanent" />
                </rule>
                <rule name="Imported Rule 4" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/default.aspx" />
                </rule>
                <rule name="Imported Rule 5" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^domain.com" />
                    </conditions>
                    <action type="Redirect" url="http://www.domain.com/{R:1}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>

When i click the "add to cart" button on say the "productdetails.aspx" page, the page just postbacks to itself although i have defined a postbackurl of "[fullurl]/addtocart.aspx" on the button with submit behaviour.

Any help would be appreciated.

Upvotes: 0

Views: 558

Answers (1)

Matthew Wong
Matthew Wong

Reputation: 284

I think the issue is that the Get method you use is an asynchronous call. While the asp.net button click does a full post back to the page. The .net lifecycle loads the page before firing the events of the buttons. See http://msdn.microsoft.com/en-us/library/ms178472.aspx

I hope this helps

Upvotes: 1

Related Questions