Get querystring from URLReferrer - asp.net

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)

Related

How to remove characters before a specific character?

I want get the most specific from the current url in visual basic .net.
I've tried several code but it just was the same.
I have this code:
Dim CurrentURL1 As String = Request.Url.PathAndQuery
The code will result like: /FolderName/CurrentUrl.aspx
What I want is, just get the 'CurrentUrl.aspx'.
How to get that?
Have you tried Path.GetFilename ?
http://msdn.microsoft.com/en-us/library/system.io.path.getfilename.aspx
Actually, I think you can use the Uri class, the class is better suited for your needs. It has several properties you can use to get what you want.
http://msdn.microsoft.com/en-us/library/system.uri.aspx

Asp.net request.querystring

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.

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

How do I identify the referrer page in ASP.NET?

In VS2003, I am trying to find out the particular page where the request is coming from. I want to identify the exact aspx page name.
Is there a way to only get the page name or some how strip the page name?
Currently I am using the following instruction...
string referencepage = HttpContext.Current.Request.UrlReferrer.ToString();
and I get the following result...
"http://localhost/MyPage123.aspx?myval1=3333&myval2=4444;
I want to get the result back with out any query string parameters and be able to identify the page MyPage123.aspx accurately...
How do I do that??
Instead of calling .ToString on the Uri, use the AbsolutePath property instead:
string referencepage = HttpContext.Current.Request.UrlReferrer.AbsolutePath;
This should get you "/MyPage123.aspx" in your case.
Edit: Had LocalPath instead of AbsolutePath by mistake
Look at the Segments property of the URI class (which is what HttpContext.Current.Request.UrlReferrer returns).
Something like HttpContext.Current.Request.UrlReferrer.Segments[1] (changing the 1 indexer to get the correct segment you require).

pass data from parent to popup

Apologies if this seems like a duplicate post...
Thomas Warner kindly answeres an earlier post suggesting I use:
Popup.aspx?Data1=Piece_of_data&Data2=Piece_of_data
Just want to ask, if my code is Popup.aspx?Data1=textbox1.text&Data2=textbox2.text
whats the proper way to reference whats in the textboxes?
The way is is above, all that appears in the popup is the actual text 'textbox1.text'
rather than what is actualy in that control.
thanks again
Using asp.net you can litterally write the value straight into the string like:
Popup.aspx?Data1=<%=textbox1.Text%>&Data2=<%=textbox1.Text%>
A more ideal way of doing this would be to build up the URL string in your codebehind so as not to clutter up your HTML and C# code.
That way you could do something like:
String popupUrl = String.Format("Popup.aspx?Data1={0}&Data2={1}",
textbox1.Text,textbox2.Text);
This will also allow you to do any sanitization checks on the values from the textboxes before you start passing those values around.

Resources