Passing url as parameter to web service method - url

I'm writing a web service which expects one of the parameters (called "hlink") to be a url. Before calling the web service I URLEncode the parameter in question ("hlink"). I then call the web service with an hlink parameter value of 'a.apsx?a=1&b=2. When the request arrives at the web service method I can examine hlink - it has received the url ok, but only as "a.aspx?a=1" - i.e. it has lost the &b=2 part of the parameter. This seems to be asp.net stripping off the &b=2 bit - how can I get the whole parm value passed into my web method?
Thanks very much!

Are you absolutely certain that you are urlencoding the value before placing it in the query string? The query string parser splits on the '&' sign, which should be %26 after it is url encoded. If it remains as an '&' character, it will cause the query string parser to b=2 is another name value pair in the outer query string. I'd take a closer look at what you are sending.
You should see something like this: hlink=a.apsx%3Fa%3D1%26b%3D2

Related

For each in by reference or value

I have the following code:
dim key
for each key in Request.Querystring
'do something
key = sanitized_param(key)
next
My question for you classic-asp connoisseur, does classic-asp, or asp in general, pass the variables as references(memory), or by value? Trying to figure out if I sanitize the key variable and pass it back to itself, is it just "alive" for that loop, or does the new value get passed to the original QueryString?
Request.QueryString retrieves the query string parameters by value from the page headers.
You can only make changes to a query string once its been retrieved via Request.QueryString, but you can't make changes directly to Request.QueryString as it's read-only (If you could make changes you would presumably use Response.QueryString, but this isn't a valid response command).
I'm guessing you're trying to sanitize all your query strings in one go? This isn't really possible or indeed necessary. You would typically sanitize a query string as and when you request it:
Response.Write(sanitized_param(Request.QueryString("myQS")))
Or to assign the query string to a variable first then sanitize it:
Dim myQS
myQS = Request.QueryString("myQS")
myQS = sanitized_param(myQS)
' or
myQS = sanitized_param(Request.QueryString("myQS"))
Once the query string has been assigned to a variable and sanitized you're able to reference that variable as often as you like without having to pass it to your sanitize function again.
Also, your example code doesn't make much sense. The key value in your for each loop is referencing just the names of your query strings and not their values. If Response.QueryString was a valid ASP command you would do:
Response.QueryString(key) = sanitized_param(Request.QueryString(key))
But again, this isn't possible.
EDIT: This solution might be what you're looking for:
Create a dictionary object, call it "QueryString" for example. Loop through all your query strings and add a sanitized version to the dictionary object.
Dim QueryString : Set QueryString = Server.CreateObject("Scripting.Dictionary")
For Each Item In Request.QueryString
QueryString.Add Item,sanitized_param(Request.QueryString(Item))
next
Now, to retrieve a sanitized version of a query string just use:
QueryString.Item("query_string_name")
Or for the original unsanitized version you could still use:
Request.QueryString("query_string_name")
Just like Request.QueryString, the dictionary object is forgiving and won't return an error if you ask for a query string that doesn't exist.
You could also create a function for retrieving sanitized query strings, for example:
Function SanitizedQS(ByVal qsName)
SanitizedQS = sanitized_param(Request.QueryString(qsName))
End Function
And rather than using Request.QueryString("query_string_name") just use SanitizedQS("query_string_name").

Uri class throws error when queryParameters contains a key with a value: false?

I was working through some code, and noticed:
return new Uri(host: server, path: apiPath, query: query, queryParameters: queryParams);
This code is executed regularly throughout the application, and the only difference was queryParams. So i printed it out:
{Id:[1234], enabled:false}
shows it is a key:value set of: Id:List, enabled:boolean.
The stack trace i get is:
which shows the map and then the trace. #6 points to the above line.
It is looking at false... something with iterating false is what breaks this.
When dealing with the URI and query parameters, it is looking for numerics, lists, and strings but not booleans. In order to resolve this and allow it to function correctly, you will need to do:
{"enabled": false.toString()}
// or
{"enabled": "false"}
and the uri class will set the query parameter accordingly.
The Uri class is located in core library for Dart. When we are using it, we are passing in the created Uri object into an action for a client class,
Client client = new BrowserClient();
which accepts the url as a part of the parameters.
While looking at the errors above though, the Uri class ultimately is unable to properly parse a false value to an accepted value.
When looking at the Code Docs for Uri as per the Dart languages: https://api.dartlang.org/dev/1.25.0-dev.7.0/dart-core/Uri/Uri.html
The query component is set through either query or queryParameters. When query is used, the provided string should be a valid URI query, but invalid characters, other than general delimiters, will be escaped if necessary. When queryParameters is used the query is built from the provided map. Each key and value in the map is percent-encoded and joined using equal and ampersand characters. A value in the map must be either a string, or an Iterable of strings, where the latter corresponds to multiple values for the same key.
Which makes sense to say all values must be String or an Iterable of Strings. The only thing which I cant figure out is that in Dartpad, true and false have toString functions, and yet you can also pass numerics in there.
The only conclusion is that while it accepts Strings and Iterables of Strings, it will also parse ints and other numerics because they will explicitly check for that type as it is common to see in URI.
One would think that the URI would understand booleans since those are also common place, but that is yet to be seen since I cant take an explicit look at the source code for dartlang. I did however manage to look at the source code for it and narrowed it down. writeComponent points to _Uri._uriEncode but when looking at that function, there is no code as much as just a definition.
HTH.

Google Spreadsheet CHECKSTRING(url ; string) (new function needed)

I’m really new to programming so first of all I beg your pardon for my my questions.
I would like to create a function to search the webpage of a site in order to find any string is present.
This function could be written like this. Thanks in advance for your precious help. Then How I can activate it to use it in a cell.
Thanks for your precious help.
Seb
--
CHECKSTRING(url ; string)
• url - The URL of the web page to examine, including protocol (e.g. http:// or https://).
The value for url must either be enclosed in quotation marks or be a reference to a cell containing the appropriate text.
• String – The STRING to find in the page source from the URL. The value for String must either be enclosed in quotation marks or be a reference to a cell containing the appropriate text.
This function returns the line number position at which the STRING is first found within URL code source, case-sensitive.
This function returns -1 or FASE when the check answer is negative.
Did you try the FINDfunction ?
=iferror(find(string_to_search, url), false)
or, depending on your locale:
=iferror(find(string_to_search; url); false)
where string or URL can be passed in as string, or as cell references.
NOTE: if you want to do a case-insensitve search, replace the FIND() with SEARCH()

Angular http get returns string in extra quotes

My project is a mixture of AngularJS and ASP.Net MVC.
I am using $http.get to call my api controller, which returns a string. But in the .success function, the data is getting returned like so "/"my string/"" (with the extra quotes around it).
Why are those there, and how can I get rid of them?
I need them gone because I am setting the title attribute of an element to the string that is returned, and this makes the tooltip have quotes around it (ugly).
parse the string value using JSON.parse(variable)

Replace a string with another in request.rawurl not working

I want to replace some string in my url like this
request.RawUrl.ToString().Replace("sometext566666", "othertest")
but it s not working why is it so?
For example, the original url is like
/sometext4554544454.aspx
and I want it like this
/sometext.aspx
I'm guessing that this is .NET. If so, you should be aware the String.Replace() returns a new string containing the result of the replacement (as do all other methods that purport to modify a string).
So you need to assign the result to a variable or field to hold the result. In some circumstances, you might assign the result back to the same place you obtained the original string from. But you're not allowed to overwrite RawUrl (and, it would be potentially confusing for you to do so).
The statement you are using is working, but you are not assigning the result of the replace function, just executing it.
request.RawUrl.ToString().Replace("sometext566666", "othertest")
If you want to keep the result, you will need to assign it to a string.
e.g.
String result = request.RawUrl.ToString().Replace("sometext566666", "othertest");
Otherwise, you can assign it to the same RawURL but I think that is a URI so you'll need to use a new URI, something like:
request.RawUrl = new URI(request.RawUrl.ToString().Replace("sometext566666", "othertest"));
Nevertheless, I'm not sure if you can actually edit that property.

Resources