I was developing a system that used Url Rewriting, when a button was clicked the whole page broke.
I came across a error like
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)
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.
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.