We are using Request.ServerVariables to read a specific header value added by a proxy in the request header.
We can get and read the searched value using
Request.ServerVariables.Get(myKey)
// or
Request.ServerVariables[myKey]
but we notice that when we loop over the keys with
foreach (string key in Request.ServerVariables.AllKeys)
...
we don't get the searched key !
Inside the documentation we can read :
The ServerVariables collection retrieves the values of predetermined
environment variables and request header information.
So is this correct to say that Request.ServerVariables.AllKeys does not contain all the keys and that we have to use the indexer or the get method to test if the key exists ?
The full list of variables can be found here. If you know the specific variables you're after, it would be more efficient to simply request these that enumerate the full collection anyway.
If you just debug in your web application, you will see the full list, and you can't add to this list in code (easily) as far as I know.
I thing you miss Name attribute of input element
for example
you con't get the value of bellow control using Request.ServerVariables.Get(myKey);
<input type='text' value='Indian' />
you use <input name ='country' type='text' value='Indian' /> and
Request.ServerVariables.Get('country');
Related
Via a hidden input field I want to send a value from Site 1 to Site 2.
But at Site 2 it says the value is null.
I guess this is because it is local value. But it has to be local and I'm not sure.
Here is my code where I declare the value (page 1):
string stringproductid = Request.QueryString["id"].tostring();
int productid = stringproductid.AsInt();
Here I send it via a hidden field inside a form (page 1):
<input type="hidden" id="#productid" value="#productid" name="#productid">
Here I try to receive it (at page 2):
string idstring = Request.Form["productid"].ToString(); //error
It should be name="productid" . The # you're using there is making Razor put the value of productID into that attribute. So if you look at your raw generated HTML it is going to be something like name="346".
That belongs in the "value" attribute, which you did correctly, but what you need to be putting in the "name" is the name of the field, so that the browser posts it back correctly with that field name. :-)
On your 2nd page, you should use
string idstring = Request.Form["#productid"].ToString(); //error
On a side note, both Request.QueryString[] and Request.Form[] are always strings, so you don't need to include the .ToString(). I understand it may be defensive coding, but you are just adding CPU cycles. They add up over time.
Trying to query the RETs database to only show CONDOs. There is a lookup field in the METADATA-LOOKUP_TYPE of TYPEOFPROP, but I'm unable to pull the value. Query below:
http://connectmls-rets.mredllc.com/rets/server/search?SearchType=Property&Class=ResidentialProperty&QueryType=DMQL2&Format=COMPACT&StandardNames=0&Query=(LP=300000%2B)&Count=1&Limit=2
Using system names, filter on TPC. You can then add "&select=tpc" to the querystring and add the filter ",(TPC=C)".
Since its a look up, you need to use "|" symbol in the query.
Check this example,
Perform a query:
http://retsgw.flexmls.com/rets2_1/Search?SearchType=Property&Class=A&QueryType=DMQL2&Query=(LIST_15=|OV61GOJ13C0)&Count=0&Format=COMPACT-DECODED&StandardNames=0&RestrictedIndicator=****&Limit=50
The response will contain the records you requested (limited to 50 due to the Limit argument given at the end). The COLUMNS line indicates the field names of the records returned and all DATA rows represent the records with field values in the same order as shown by the COLUMN row. If you’re only interested in receiving certain fields back, you can add a “&Select=” parameter to the end of the URL. For example, if you only want to retrieve back the KeyName field (noted as “LIST_1”) and the Listing Status field (noted as “LIST_15”), add “&Select=LIST_1,LIST_15” to the end of that URL. Note a few ‘LIST_1’ values for the next example.
For further reference, check this flex documentation
I want to write a key and multiple values in app.config, so that depending on the value a method is run.
for example:
let the key be "syncMode" and values to be kept are "syncAll"/"syncYest"
If the value is set as syncAll, complete data sync should happen in the main program and if syncYest is set, then only yesterday's data should be sync.
How can i write this in App.config?
Based on your requirement this looks like a simple case of single name and single value.If you want "Complete data sync in the main program" set value of key syncMode = "syncAll".Otherwise if you want "yesterdays data to sync" use syncMode = "syncYest"
You can create a custom configuration section for this. There is already a SO Post related to this. Additionally, you can also read the official MSDN page.
i just want to get full querystring from url.
Request.QueryString
Request.ServerVariables["QUERY_STRING"]
Can i use any one of these?
which way is preferred?
Thanks
Request.ServerVariables["QUERY_STRING"] contains the entire query string, that is everything after the question mark but before the fragment identifier #
http://msdn.microsoft.com/en-us/library/ms525396(v=vs.90).aspx
Request.QueryString Contains a collection allowing you to get individual elements.
Using following syntax:
Request.QueryString(variable)[(index)|.Count]
This collection is generated from the ServerVariables collection. The values in this collection are automaticly UrlDecoded.
So if you call Request.QueryString.ToString(), it is inherently the same as Request.ServerVariables["QUERY_STRING"], but with UrlDecoding.
So you should use this as it is safer.
Request.QueryString(variable)[(index)|.Count]
http://msdn.microsoft.com/en-us/library/ms524784(v=vs.90).aspx
http://msdn.microsoft.com/en-us/library/ms524784(v=vs.90).aspx
The QueryString collection is a parsed version of the QUERY_STRING variable in the ServerVariables collection. It enables you to retrieve the QUERY_STRING variable by name. The value of Request.QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING. You can determine the number of values of a parameter by calling Request.QueryString(parameter).Count. If a variable does not have multiple data sets associated with it, the count is 1. If the variable is not found, the count is 0.
To reference a QueryString variable in one of multiple data sets, you specify a value for index. The index parameter can be any value between 1 and Request.QueryString(variable).Count. If you reference one of multiple QueryString variables without specifying a value for index, the data is returned as a comma-delimited string.
When you use parameters with Request.QueryString, the server parses the parameters sent to the request and returns the specified data. If your application requires unparsed QueryString data, you can retrieve it by calling Request.QueryString without any parameters.
If you call Request.QueryString["Whatever"] than UrlDecode is automatically executed. See does Request.Querystring automatically url decode a string? . So be careful with your spaces, %20, ampersands etc.
Regards,
Michael
I stucked at a condition , where i need to share values between the pages. I want to share value from Codebehind via little or no javascript. I already have a question here on SO , but using JS. Still did'nt got any result so another approach i am asking.
So I want to know can i pass any .net object in query string. SO that i can unbox it on other end conveniently.
Update
Or is there any JavaScript approach, by passing it to windows modal dialog. or something like that.
What I am doing
What i was doing is that on my parent page load. I am extracting the properties from my class that has values fetched from db. and put it in a Session["mySession"]. Some thing like this.
Session["mySession"] = myClass.myStatus which is List<int>;
Now on one my event that checkbox click event from client side, i am opening a popup. and on its page load, extracting the list and filling the checkbox list on the child page.
Now from here user can modify its selection and close this page. Close is done via a button called save , on which i am iterating through the checked items and again sending it in Session["mySession"].
But the problem is here , when ever i again click on radio button to view the updated values , it displays the previous one. That is , If my total count of list is 3 from the db, and after modification it is 1. After reopening it still displays 3 instead of 1.
Yes, you could but you would have to serialize that value so that it could be encoded as a string. I think a much better approach would be to put the object in session rather than on the URL.
I would so something like this.
var stringNumbers = intNumbers.Select(i => i.ToString()).ToArray();
var qsValue = string.Join(",", stringNumbers);
Request.Redirect("Page.aspx?numbers=" + sqValue);
Keep in mind that if there are too many numbers the query string is not the best option. Also remember that anyone can see the query string so if this data needs to be secure do not use the query string. Keep in mind the suggestions of other posters.
Note
If you are using .NET 4 you can simplify the above code:
var qsValue = string.Join(",", intNumbers);
Make the object serializable and store it in an out-of-process session.
All pages on your web application will then be able to access the object.
you could serialize it and make it printable but you shouldn't
really, you shouldn't
The specification does not dictate a minimum or maximum URL length, but implementation varies by browser and version. For example, Internet Explorer does not support URLs that have more than 2083 characters.[6][7] There is no limit on the number of parameters in a URL; only the raw (as opposed to URL encoded) character length of the URL matters. Web servers may also impose limits on the length of the query string, depending on how the URL and query string is stored. If the URL is too long, the web server fails with the 414 Request-URI Too Long HTTP status code.
I would probably use a cookie to store the object.