How do I go about getting a page to restart processing in C#?
-
19-09-2019 - |
Question
I'm working with a CMS which allows you to develop your own custom controls which get dynamically included at runtime. So I have a custom control which alters a datasource (NHibernate cache) and as I'm at a point in the process where the CMS has already read this data from the cache, I need to restart the processing of the page somehow so that the CMS picks up the new cache data.
I know there are probably more elegant ways of doing this, but because I am unable to directly alter the data held by the CMS' core once it has read from the cache and because of the way the control gets loaded by the CMS I am out of alternatives (I think).
I have tried doing a Response.Redirect() to the requested URL, but most browsers will think this is an infinite loop and kill the request. Any other ideas?
Solution
You can do this from your initial page:
Response.Clear ();
Server.Transfer (Request.Url.PathAndQuery, true);
The second argument passes the initial page QueryString and Form values.