Click here to Skip to main content
15,883,901 members
Articles / Web Development / ASP.NET
Tip/Trick

Url Rewriting Problems with postback

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
28 Jun 2010CPOL2 min read 10.8K   1  
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)


Written By
Software Developer (Junior) nologo studios
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --