I need to clear the queryString so I implemented an httpmodule
public void Init(HttpApplication context)
{
context.PostRequestHandlerExecute += newEventHandler(OnEndRequest);
}
and this is the method :
public void OnEndRequest(Object sender, EventArgs e)
{
HttpApplication context = (HttpApplication)sender;
if (HttpContext.Current.Request.QueryString != null && HttpContext.Current.Request.QueryString.Count != 0)
{ HttpContext.Current.Request.QueryString.Clear(); }
}
but it's giving an exception :
System.NotSupportedException was unhandled by user code
HResult=-2146233067
Message=Collection is read-only.
the purpuse is to hide the parameters shown in the adress bar , in order to make it impossible to the user to change the values of the parameters , I can't use post method , because , it's the problem of a whole application , so i can't go back to all pages and changes all the code . to understand ; I want that the request MyPage.aspx?Param1=1 be processed and the response returned to the client but the addres bar must show MyPage.aspx instead of MyPage.aspx?Param1=1
The best and simple way to get this feature ( clear the request parameters ) is using a client side method :
this code will update the url shown in the adress bar without refreshing the page ( for browsers using html5 )
var urlElts = document.documentURI.split('?');
var newUrl = urlElts[0];
window.history.replaceState("object or string", "Title", newUrl);