Asp.net request.querystring - asp.net

I am using request.querystring just to access a parameter which I am passing from one page to other.
It is giving me an error.
Non-invocable member 'System.Web.HttpRequest.QueryString' cannot be
used like a method.
I am using C#.
Any help would be appreciated!

It sounds like you're writing:
Request.QueryString("Param");
When you want:
Request.QueryString["Param"];
Note the square brackets.

Related

A couple ASP questions

Can anyone tell me what each of these are doing?
<%call buildBanner()%>
What I think this one is doing is calling a Method But I'm not that familiar with ASP.
Dim nInstallID : nInstallID = getParam("InstallID")
This I'm not quite sure, But from What I gathered it's a string. But I'm not sure what the ":" does or is doing.
The "call buildBanner()" is calling a function from somewhere else in your code. The function could be on the same page or it could be in an "include" file.
The ":" is just a way to separate commands on the same line. Normally you would put the two parts on two separate lines, but this is a shortcut way to use one line. Some people like to declare and initialize the variable on the same line - something you can't do in a single statement in Classic ASP.

ASP.Net - Function output shown before function called

I have the following line of code in ASP.Net (VB)
Response.Write("<td class=""tblRow""><strong>" & ITServiceRow.NAME & " </strong><br>" & funcRAGColour(ITServiceRow.RAGSTATUS) & Environment.NewLine)
This should output the Name from ITServiceRow.NAME followed by the result of the function funcRAGColour.
However this is not the case. ASP.Net is outputting the value of the function funcRAGColour. first followed by the value of ITServiceRow.NAME.
Just trying to understand why this might be happening? If I replace the function with static text it executes fine, but when I put the function in it outputs the function result immediately before the name.
The image here, in yellow shows the full output that comes from the function, it is shown before everything else?
Am I missing something obvious here?
Try using String.Format instead to guarantee placement.
Response.Write(string.Format("<td class=""tblRow""><strong>{0}</strong><br />{1}{2}</td>",funcRAGColour(ITServiceRow.RAGSTATUS),Environment.NewLine))
Always do whatever you can to avoid string concatenation. String concatenation is tough on a system and uses much more memory and resources to be garbage collected than you think because it's actually far more complicated. String.Format and StringBuilder help get around this.
I am very suspect of the function funcRAGColour() itself though and think that is the problem. My guess is the function is not returning the output as a string, but instead is using Response.Write() to output it's result. That would cause it's value to appear first since it is called while the string is being assembled.
Keep in mind, Response.Write is NOT the way to do things in ASP.Net. It was need in classic ASP, but ASP.Net has HtmlTextWriters that can be used during the rendering process, controls for result placement, etc.. It's the old school, non object-oriented way of doing things that can get into trouble.

Get querystring from URLReferrer

I am trying to get the QueryString value like this Request.QueryString("SYSTEM") from a UrlReferrer. I see i can use this Request.UrlReferrer.Query() but it doesn't allow me to specify the exact parameter
I could parse the Query() value, but I want to know if it is possible to do something like this Request.UrlReferrer.QueryString("SYSTEM")
You could do
HttpUtility.ParseQueryString(Request.UrlReferrer.Query)["SYSTEM"]
That is c# in vb is is probably something like
HttpUtility.ParseQueryString(Request.UrlReferrer.Query())("SYSTEM")
In VB.NET, one way to get the value of "SYSTEM" from the UrlReferrer is:
HttpUtility.ParseQueryString(Request.UrlReferrer.Query).GetValues("SYSTEM")(0)

asp Server.Transfer put parameter

i googled many samples, all show such code
Server.Transfer("/default.asp?p=news")
but i get error -An invalid character was specified in the Path parameter for the MapPath method.
can you help me?
Server.Transfer method actually doesn't support any kind of querystring specified in the path. You can try to store the query parameter in a session value instead.
Some discussions:
http://classicasp.aspfaq.com/general/why-won-t-querystring-values-work-with-server-execute/server-transfer.html
The following might be a work around to using server.transfer or response.redirect.
Response.Write "<script language=javascript>window.location.href = '/default.asp?p=news';</script>"
You would have to include your querystring on the page that does the server transfer.
Ie:
page.asp?p=news would include:
Server.Transfer("default.asp")
default.asp would include:
sParam = Request("p") '<-- Your querystring value from page.asp
This should work, or if your app isn't flexible to do this, you can use Session to pass the value. It says here which methods are allowed for passing variables using Server.Transfer: http://msdn.microsoft.com/en-us/library/ms525800%28v=vs.90%29.aspx

Ampersands in URLRewriter Query Strings

I have a query string parameter value that contains an ampersand. For example, a valid value for the parameter may be:
a & b
When I generate the URL that contains the parameter, I'm using System.Web.HTTPUtility.UrlEncode() to make each element URL-friendly. It's (correctly) giving me a URL like:
http://example.com/foo?bar=a+%26b
The problem is that ASP.NET's Request object is interpreting the (encoded) ampersand as a Query String parameter delimiter, and is thus splitting my value into 2 parts (the first has "bar" as the parameter name; the second has a null name).
It appears that ASP.NET is URL-decoding the URL first and then using that when parsing the query string.
What's the best way to work around this?
UPDATE: The problem hinges on URLRewriter (a third-party plugin) and not ASP.NET itself. I've changed the title to reflect this, but I'll leave the rest of the question text as-is until I find out more about the problem.
man,
i am with you in the same boat, i have spent like hours and hours trying to figure out what is the problem, and as you said it is a bug in both, as normal links that contain weird characters or UTF-8 code characters are parsed fine by asp.net.
i think we have to switch to MVC.routing
Update: man you wont believe it, i have found the problem it is so strange, it is with IIS,
try to launch your page from visual studio Dev server and Unicode characters will be parsed just fine, but if you launch the page from IIS 7 it will give you the ???? characters.
hope some body will shade some light here
I would have thought that %26 and '&' mean exactly the same thing to the web server, so its the expected behavior. Urlencode is for encoding URLs, not encoding query strings.
... hang on ...
Try searching for abc&def in google, you'll get:
http://www.google.com.au/search?q=abc%26def
So your query string is correct, %26 is a literal ampersand. Hmm you're right, sounds like a bug. How do you go with an & instead of the %26 ?
Interesting reading:
http://www.stylusstudio.com/xsllist/200104/post11060.html
Switching to UrlRewritingNet.UrlRewrite did not help, as it apparently has the same bug. I'm thinking it might have something to do with ASP.NET after all.
I think URLRewriter has a problem with nameless parameters (null name).
I had a similar problem. When I gave my nameless parameter a (dummy) name, everything worked as expected.

Resources