Unable to get the Query String value - vb.net

Whenever I'm hitting this URL getting vToken is nothing. Please assist
Dim vHDR As String = Nothing
If Request.IsLocal Then
Dim vToken = Request.QueryString("approvalToken")
If Not vToken Is Nothing Then
Dim vUser = Helper.ValidateToken(vToken)
If Not vUser Is Nothing Then
vHDR = vUser
End If
End If
End If
URL:
http://localhost:56979/#/modules/Review?ID=20582&approvalToken=SIsJ3swuGjpPidOvWPSzuqfcTJH8IywIlVVEnkmIQU6yE93PUQ

In a URL, everything beginning with the hash sign (#) is called the Fragment Identifier. The fragment identifier section is the last section of the URL and comes after the url arguments.
So for this url from the question:
http://localhost:56979/#/modules/Review?ID=20582&approvalToken=SIsJ3swuGjpPidOvWPSzuqfcTJH8IywIlVVEnkmIQU6yE93PUQ
there is no query string. The section that looks like a query string was pre-empted to be part of a very long fragment identifier. Even the /modules/Review section that looks like part of the Path is actually part of the fragment.
I suspect somewhere in your base/index page you have a link with a blank href value, which is sometimes expressed with a single hash (#). You click that link, which puts the hash sign into the url:
http://localhost:56979/#
After clicking this link, you then redirect, click a new link, or do some other action that appends the relative url /modules/Review (which may already include the query string) to your current location. But now you have the hash sign as part of that existing location, and so you end up with the url in your question, which doesn't mean what you want it to mean.
I'd have to see a lot more code to tell you exactly how to fix this, but in the context of vb.net (asp.net), if this code runs on the server you probably want to change /modules/Review to ~/modules/Review. If this is done in javascript, I'd need to know more about your page.

Related

vb.net how to get value of <strong> using htmlagilitypack

How to get value under using hhtmlagilitypack. by the way there are many<tr><td> from this site, so would be much better if I can get the specific value under this "Social Security Number"
<tr><td><span>Social Security Number</span></td><td><strong>524-23-6748</strong></td></tr>
I tried using this code but no luck
Dim webGet As New HtmlWeb
Dim doc As HtmlDocument = webGet.Load("https://www.fakeaddressgenerator.com/World_Address/get_us_address/city/Chicago")
Dim work As HtmlNodeCollection = doc.DocumentNode.SelectNodes("/html/body/div[1]/div[3]/div[1]/div/div/div[2]/div[1]/div[2]/table/tbody/tr[6]/td[2]/strong")
TextBox1.Text = work.First().Attributes("value").Value
This one is different to the last; the xpath is right except for the tbody. It's important to remember that the document inspector you see in a browser might not reflect the actual source, and the source is what HAP parses
Easiest way I find to debug these is to remove the trailing part of the path and look what I get in the locals window:
In terms of how to know if it's attibute values or inner text etc, that comes from looking at the structure of the HTML:
Yellow highlights are attributes (things between < and > that is in the form name="value" is an attribute name/value pair), red underlines innertexts (anything between > and <)
All in your code is right apart from the TBODY, and that you're trying to select the Value of an attribute called "value" but your strong doesn't have any attributes, it only has an inner text

How can I redirect to the same page multiple times with a different query string?

I have a page that contains a table with a list of data and an icon (on each row) which redirects the user to a new aspx page with a queryString and does some custom logic to then download the file. The user has asked that we make a "download all" button so they don't have to go through and manually click every icon in every row.
My code is close, I feel, but it will hang after the first file is downloaded and will never progress further.
Here is the code I have so far
Protected Sub ibDownloadAll_Click(sender As Object, e As ImageClickEventArgs)
'Get Parameters
'Run stored procedure to get the query string we're going to use
'Fill DataSet
For Each myItem As DataRow In ds.Tables(0).Rows
Response.Redirect("redirectPage?ID=" &myItem.Item("ID")) 'Gets stuck after here
Next
End Sub
I realized if I added the second parameter (Indicates whether execution of the
current page should terminate)
Response.Redirect("redirectPage?ID=" &myItem.Item("ID"), False)
Then it would make it to the end of the function, running through the loop as expected, but then only outputting/downloading the last file.
Is there something I'm missing or an alternative that can be used to effectively redirect multiple times? Unfortunately with the framework I'm using I'm not able to use Response.Write and put custom scripts in that way, nor can I really change the page that we are redirecting to.
You can't redirect to multiple pages (a redirect close the request) and you also can't send multiple files. Your only option would be to have a request that zip all the files together. You can do this with System.IO.Compression.ZipArchive. You don't need to save the zip on disk, you could just send the memory stream.

getting value of attribute to string vb.net

I want to get the value of the src attribute (https://www.google.com) to a string from a web browser HTML elements. The code of element is:
<img src="https://www.google.com" height="500" width="500">
Code I have tried is:
For Each o As HtmlElement In WebBrowser1.Document.GetElementsByTagName("img")
If o.GetAttribute("height") = "500" Then
Dim url As String = o.GetAttribute("src").ToString
Exit For
End If
Next
String url is empty every time I also tried to get url in textbox but its also empty.
problem is that is not a server side control, it is plain html. to make matters worse there are not classes or ID's to make it easier to isolate which control u want to target. Also javascript could be generating that image so that could make it harder.

Generate dynamic web pages and urls in vb.net

New to the whole web programming scene, usually stick to offline applications.
On this page of my site I'm using gridview to pull items from an SQL database.
That's all fine and dandy, but here's where I get confused.
Upon selection of an item I want to navigate to another page which is generated with information from my SQL database, I'm fine here, I have a template for the page that pulls information for the page based on the selected item using a get property for a WHERE itemname= sql command.
However, currently, the site goes like this. http://exampleurl.com/items.aspx
I would like users to be able to link to a specific item. So upon selection it should generate a url for that item.
http://exampleurl.com/items.aspx?=selecteditemname
Never mind.
I'm just being a tard as usual.
Set the column in your gridview to a hyperlink
navigateurl='<%# String.Format("../Default.aspx?id={0}", Eval("ColumnId"))%>'
Open up the code for the page you are redirecting to and set your WHERE in the gridview to
Request.RawUrl.Split("=")(1)
This will get everything after the '=' in your url.
i.e.
http://exampleurl.com/Default.aspx?id=123
Request.RawUrl.Split("=")(1) will return '123'
OR
Dim item As String = Request.Url.Query
Dim query As NameValueCollection = HttpUtility.ParseQueryString(item)
Dim id As String = query["id"]

Visual Basic Web Browser change form when certain webpage content detected

I am trying to make a form on VB.NET that when a certain webpage is loaded into the web browser (in this case its a .txt file with a string of numbers). It will look for those numbers and if it finds them it will close that form and open another. I have tried to do it many times and my latest attempts came out with this code. Any help would be appreciated.
Dim passcontents As String
passcontents = WebBrowser.DocumentText = "test.com/test.txt"
If WebBrowser.DocumentText = "test.com/test.txt" And passcontents Then
ActualGen.Show()
Me.Close()
Else
End If
There are a couple of basic problems with the code you've posted.
1) Are you trying to test passcontents as a boolean or a string? You've defined it as a String, but then you are trying to assign the equality of two other strings to it, as you would a Boolean.
Try setting Option Strict On at the top of your code - it gives a few more helpful pointers to check in this case.
2) The If... Then condition is checking the same data as passcontents (may) already be providing. Are you just trying to check that the correct page is loaded, or do you want to check for certain page contents as well?
You appear to be getting mixed up between the browser's document URL and the loaded document contents.