0

I'm currently working on some ajax polling stuff and I don't want do pass through all the process if nothing has changed in the xml file I'm using for my asynchronous process.

However after each polling I want to set the value DateTime.Now, but cannot do it with

Request.Form[ "lastPoll" ] = DateTime.Now.ToUniversalTime().ToString();

because this is read only.

This is how i get the last polled datetime:

DateTime lastPoll = Convert.ToDateTime(Request.Form[ "lastPoll" ]).ToUniversalTime();

Thanks for your help.

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by PierlucSS
1

I found some ninja thing, but if you have anything else, it would be appreciated.

NameValueCollection oQuery = Request.QueryString;
oQuery = (NameValueCollection)Request.GetType().GetField("_queryString",BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Request);
PropertyInfo oReadable = oQuery .GetType().GetProperty("IsReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
oReadable.SetValue(oQuery, false, null);
oQuery["lastPoll"] = DateTime.Now.ToString();
oReadable.SetValue(oQuery, true, null);

Edited by PierlucSS: n/a

Votes + Comments
Informative.
0

Request form collection is read-only so, we cannot directly modify it but reflection api will do that.

MethodInfo WritableMethod;
        MethodInfo ReadOnlyMethod;
        BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;

        WritableMethod = Request.Form.GetType().GetMethod("MakeReadWrite", Flags);
        ReadOnlyMethod = Request.Form.GetType().GetMethod("MakeReadOnly", Flags);

        FieldInfo FormField = Request.GetType().GetField("_form", Flags);

        WritableMethod.Invoke(Request.Form, null);

        Request.Form["no"] = "100";

        FormField.SetValue(Request, Request.Form);
        ReadOnlyMethod.Invoke(Request.Form, null);

        Response.Write("<br/>" + Request.Form["no"]);
0

Thanks for the answer, however, it's not completly working. If I am simply adding a Request.Form["lastPoll"]; I'll get the correct value. However, if I alert right after the the previous code has ran, I'mgetting a null value.

This is my jQuery. ScriptToCheckTheFile is where I am setting the Date with the method you provided me.

The last function is only executed after ScriptTocheckTheFile.aspx has ran, so lastPoll should have changed.

Last poll is currently defined globally as null and is not used elsewhere.

function Poll2() {  $("#scripts").load("Ajax/ScriptToCheckTheFile.aspx", { 
projectId: $("#projectId").val(), 
lang: ($("#projectId").val().charAt(0) == "E") ? "eng" : "fra", 
lastPoll: lastPoll,
projectName: $("#projectId option:selected").text() }, 

function(result) {   

alert(lastPoll);

}

Edited by PierlucSS: n/a

0

Thanks for the answer, however, it's not completly working. If I am simply adding a Request.Form["lastPoll"]; I'll get the correct value. However, if I alert right after the the previous code has ran, I'mgetting a null value.

This is my jQuery. ScriptToCheckTheFile is where I am setting the Date with the method you provided me.

The last function is only executed after ScriptTocheckTheFile.aspx has ran, so lastPoll should have changed.

Last poll is currently defined globally as null and is not used elsewhere.

function Poll2() {  $("#scripts").load("Ajax/ScriptToCheckTheFile.aspx", { 
projectId: $("#projectId").val(), 
lang: ($("#projectId").val().charAt(0) == "E") ? "eng" : "fra", 
lastPoll: lastPoll,
projectName: $("#projectId option:selected").text() }, 

function(result) {   

alert(lastPoll);

}

I am not affecting the global lastPoll var, I'm only affecting the dataname, and when we get out of the curly brackets, it's gone. I'd name a way to put it public or to set directly the variable.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.