Click here to Skip to main content
Click here to Skip to main content

Tagged as

Url Rewriting Problems with postback

, 28 Jun 2010
Rate this:
Please Sign up or sign in to vote.
I was developing a system that used Url Rewriting, when a button was clicked the whole page broke.



I came across a error like



error



And as the error said something about viewstate and machine keys I tried to work at getting the machine key to work properly with a static machine key, this was never working. So I set “enableEventValidation” to false and this didn’t break when doing the postback. I noticed that I was redirected to the home page as the web.config stated when checking the rules for rewiting that if a page was under the modules folder it needed to check the page and redirected the servers attention to another page (CommandPanelLeft.aspx) which is the parent page for modules. So I said if there is a querystring of modulename then leave the page alone. Now the postback works fine but the url says the path that the server reads (a) with the querystring instead of the rewriten url (b)



(a)


serverUrl



(b)


browserUrl



So I took the code out the Global.asax to ignore pages with the querystring containing moduleName and also took out the “enableEventValidation” in web.config, and on the page_load method on the master page I added a line of code I found



This says to the page that that is the url that it must make the postback on.



Problem



The problem wasn’t the machine key or faulty viewstate it was that in my global.asax I was redirecting to the home page if the page that was in the browser (b) wasn’t found and because when the postback was made the url was now set to (a) in the browser because when it loaded the last time the server read it as (a) because we told it that was the path, it was posting back to that path. By adding the line of code to the master page we were telling the page that “Request.RawUrl” is the pages actual page name and not “CommandPanelLeft.aspx” the postback went to the page that we rewrote the url to.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

gbeeming
Software Developer (Junior) nologo studios
South Africa South Africa
No Biography provided
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140826.1 | Last Updated 28 Jun 2010
Article Copyright 2010 by gbeeming
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid