404 Error with Postback

Topics: Developer Forum
Apr 8, 2010 at 4:29 PM

My current site is using ASP.net 3.5.  I have implemented IIRF in a test environment and most things appear to be working.  However there are a couple of issues I have this is the main one.

I have a rewrite rule that is taking /Products/Engine/Pistons/XYZ.aspx and correctly rewriting it to /ProdDet.aspx?1=Engine&Name=Piston&PN=XYZ.

On this page I have a button that onclick adds XYZ to the users cart. 

On Click the page posts back to /Products/Engines/Pistions/ProdDet.aspx?1=Engine&Name=Piston&PN=XYZ not /ProdDet.aspx?1=Engine&Name=Piston&PN=XYZ and I return a 404 error.

I have read the posts about how to get the postback to go to the same url and I will try those.  However, I would like to just get it working first.

Thanks in advance

Apr 9, 2010 at 12:57 AM

Can you set your log level to at least 4 and post the IIRF log showing the postback sequence?  Also, post your iirf.ini file.

Coordinator
Apr 9, 2010 at 5:59 AM

Your postback URL should have a leading slash.  The file ProdDet.aspx is probably using an action of "ProdDet.aspx", which is resolving to a relative URL.  You want an absolute URL, eg "/ProdDet.aspx".  I think you can set the property PostBackUrl on ASP.NET controls to get what you want.   If not that, then something similar.

 

Apr 9, 2010 at 12:29 PM

RSWITT,

Here is my INI file


RewriteLog  c:\temp\iirfLog.out
RewriteLogLevel 4

MaxMatchCount 10

StatusUrl /iirfStatus

RewriteRule ^/Products/([^/]+)/$  /Products.aspx?Name=$1
RewriteRule ^/Products/([^/]+)/([^/]+)/$  /Products.aspx?1=$1&Name=$2
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/$  /Products.aspx?1=$1&2=$2&Name=$3
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$  /Products.aspx?1=$1&2=$2&3=$3&Name=$4
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$  /Products.aspx?1=$1&2=$2&3=$3&4=$4&Name=$5

RewriteRule ^/Products/([^/]+)/([^/]+).aspx$  /ProdDet.aspx?PN=$2
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+).aspx$  /ProdDet.aspx?PN=$3
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/([^/]+).aspx$  /ProdDet.aspx?PN=$4
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+).aspx$  /ProdDet.aspx?PN=$5
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+).aspx$  /ProdDet.aspx?PN=$6

RewriteRule ^/Categories/([^/]+)/$  /Categories.aspx?Name=$1
RewriteRule ^/Categories/([^/]+)/([^/]+)/$  /Categories.aspx?1=$1&Name=$2
RewriteRule ^/Categories/([^/]+)/([^/]+)/([^/]+)/$  /Categories.aspx?1=$1&2=$2&Name=$3
RewriteRule ^/Categories/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$  /Categories.aspx?1=$1&2=$2&3=$3&Name=$4
RewriteRule ^/Content/([^/]+).aspx$  /Content.aspx?Content=$1


My log file is to long to post so here is a link http://www.cvproducts.com/upfiles/IIRFLOG.txt


Chesso,

My ASP.net button does not have a PostbackUrl specified because the controls are on a master page in a master/content situation (button appears on multiple urls Products.aspx, ProdDet.aspx, Categories.aspx, etc. .  I think I need to leave it blank to post back to the url that it was sent from.

I hope this helps, thanks for the quick response.

Apr 10, 2010 at 12:24 AM

Yikes, I'd think there's got to be a more elegant way of doing that!  I didn't see in your log anywhere where an actual rule was matched.  Can you post a a *portion* of the log where your postback is processed?  That'll show what url is getting passed to IIRF.

 

Apr 12, 2010 at 1:16 PM

rswitt

Here is an example of one from that log that post correctly


Thu Apr 08 12:12:15 -  2588 - DoRewrites: Url (decoded): '/Categories/CV Clearance/'
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: depth=0
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 1 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 2 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 3 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 4 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 5 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 6 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 7 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 8 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 9 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 10 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 11 : 2 matches
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Result (length 34): /Categories.aspx?Name=CV Clearance
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: depth=1
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 1 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 2 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 3 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 4 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 5 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 6 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 7 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 8 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 9 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 10 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 11 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 12 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 13 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 14 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: Rule 15 : -1 (No match)
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: returning 0
Thu Apr 08 12:12:15 -  2588 - EvaluateRules: returning 1
Thu Apr 08 12:12:15 -  2588 - DoRewrites: Rewrite Url to: '/Categories.aspx?Name=CV Clearance'


Here is what i believe is the postback that goes into left field. 


Thu Apr 08 12:12:55 -  2588 - HttpFilterProc: SF_NOTIFY_LOG
Thu Apr 08 12:13:03 -  2588 - HttpFilterProc: SF_NOTIFY_URL_MAP
Thu Apr 08 12:13:03 -  2588 - HttpFilterProc: cfg= 0x01D04220
Thu Apr 08 12:13:03 -  2588 - HttpFilterProc: SF_NOTIFY_AUTH_COMPLETE
Thu Apr 08 12:13:03 -  2588 - DoRewrites
Thu Apr 08 12:13:03 -  2588 - DoRewrites: Url (decoded): '/Categories/CV Clearance/Categories.aspx?Name=CV+Clearance'
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: depth=0
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 1 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 2 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 3 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 4 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 5 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 6 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 7 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 8 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 9 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 10 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 11 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 12 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 13 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 14 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: Rule 15 : -1 (No match)
Thu Apr 08 12:13:03 -  2588 - EvaluateRules: returning 0
Thu Apr 08 12:13:03 -  2588 - DoRewrites: No Rewrite


Here again the root issue I believe is the page is posting back to a directory structure that is not there and is only used with the IIRF for rewrite.

'/Categories/CV Clearance/' rewrites to '/Categories.aspx?Name=CV Clearance'

but when action post from '/Categories.aspx?Name=CV Clearance' (URL seen in browser is '/Categories/CV Clearance/').  The requested URL is '/Categories/CV Clearance/Categories.aspx?Name=CV+Clearance' not '/Categories.aspx?Name=CV Clearance'

Apr 12, 2010 at 6:13 PM

I Believe I have found a work around but I dont really like it (will ultimately add 20+rules to manage).  However I will use it if no one has a better idea.

basically it involves creating additional rewrite rules to change the url for postbacks i.e.

RewriteRule ^/Products/([^/]+)/Products.aspx([^/]+)$ /Products.aspx$2
RewriteRule ^/Products/([^/]+)/([^/]+)/Products.aspx([^/]+)$ /Products.aspx$3
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/Products.aspx([^/]+)$ /Products.aspx$4
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/([^/]+)/Products.aspx([^/]+)$ /Products.aspx$5

any thoughts or more elegant way of writing these 4 rules as 1?

Thanks in advance.

Coordinator
Apr 12, 2010 at 8:55 PM

I'm sure there's a way to resolve your problem with the use of the postback Url, as I suggested earlier.

See also, this writeup:  http://ruslany.net/2008/10/aspnet-postbacks-and-url-rewriting/

 

Apr 12, 2010 at 9:36 PM

Right, your issue is being caused by the postback behavior, prior to IIRF ever getting it.  The only way to resolve it is to either change the postback behavior (as Cheeso has noted) or catch the malformed URL with a different set of rules (which you've done just prior to Cheeso's note).

As for elegance, I'm not the most proficient regex user, but couldn't

RewriteRule ^/Products/([^/]+)/Products.aspx([^/]+)$ /Products.aspx$2
RewriteRule ^/Products/([^/]+)/([^/]+)/Products.aspx([^/]+)$ /Products.aspx$3
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/Products.aspx([^/]+)$ /Products.aspx$4
RewriteRule ^/Products/([^/]+)/([^/]+)/([^/]+)/([^/]+)/Products.aspx([^/]+)$ /Products.aspx$5

be rewritten simply

RewriteRule Products.aspx(.*)$ /Products.aspx$1

I mean, all you need is the last set of text, who cares what the preceding stuff was?  You don't have to start at the beginning of every string.

You can basically do the same thing for your ProdDet rules.  The Categories and Products rules seem ungainly because of the way the URL's are constructed, do you really need every URL path as an argument?  Seems to me that if you had a URL like:

/Products/Engine/Pistons/XYZ.aspx

all you care about is the XYZ (and why do you even have the .aspx in there, when you're adding it in IIRF anyway?), do you really need Engine and Pistons?  I figure you'd look it up just by the Part Number (PN) and use

RewriteRule ^/Products.*/(.*)\.aspx$ /Products.aspx?Name=$1

I can understand why you'd have the other items in the URL for drilling down purposes, but do you really need them in the part lookup internally?