Even if it's a bit hacked, there is a way to change the value of the POST variable.
We can use Reflection to mark the collection Request.Formas non-readonly, change the value to what we want, and mark it again as read-only (so that other people cannot change the values). Use the following function:
protected void SetFormValue(string key, string value)
{
var collection = HttpContext.Current.Request.Form;
var propInfo = collection.GetType().GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
propInfo.SetValue(collection, false, new object[] { });
collection[key] = value;
propInfo.SetValue(collection, true, new object[] { });
}
I tested the code on my machine and it works great. However, I cannot give any guarantees of performance or portability.
source
share