Get the parameter from the url of site using asp with vbscript - asp-classic

I have the code of Jquery for link to the asp page as below:
Jquery code:
var url = "script_right2.asp?soc="+societe+"&phoneNum="+phoneNumber+"&seleDro="+sedro+"&desc="+des;
I want to get the value of societe,phoneNumber,seleDro,desc to the page script_right2.asp
But the problem is that I do not know how to get these data in asp page using vbscript.

I'm not sure what the question is so I'll answer it twice!
To replicate what you have using VBScript:
dim stringUrl
stringUrl = "script_right2.asp?soc=" & societe & "&phoneNum=" & phoneNumber & "&seleDro=" & sedro & "&desc=" & des;
Or, if you want to get the value of the variables from the query string you could do
dim soc
dim phone
dim sedro
dim desc
soc = Request.QueryString("soc")
phone = Request.QueryString("phoneNum")
sedro = Request.QueryString("seleDro")
desc = Request.QueryString("desc")

Related

double quote in text to create href doesn't work on vb.net

I have a problem to add the href into the Literal control. I spend an hour and didn't work on escape double quot. It shows the text instead of href. Would someone show me how to correct it.
There is my code:
dim id as integer=Cint(txtID.text.tostring())
dim href1 as string
Dim href1 As String = "<a target='_blank' class='body'" & "href='#'"
href = href & " onclick=""openWin('OrderForm/pop.aspx'?cId=" & id & "','',500,270);return false;"">" & Link & "</a>"
Dim ltLink As New Literal
ltLink.Text = href1
pnlLink.Controls.Add(ltLink)
Thanks in advance
Ideally, if you want to create markup at server-side, you want to use server control. It is less error prone than creating them manually.
Dim id As Integer = Convert.ToInt32(txtID.text.tostring())
Dim hyperLink = New HyperLink()
hyperLink.Target = "_blank"
hyperLink.CssClass = "body"
hyperLink.NavigateUrl = "~/OrderForm/pop.aspx?cId=" + id
hyperLink.Text = "Open Window"
hyperLink.Attributes("onclick") = "window.open(this.href, 'targetWindow', 'width=500,height=270');return false;"
pnlLink.Controls.Add(hyperLink)
I don't know what is openWin. I just assume you want to open a new windows. If it is a custom fuction, you can just replace mine with yours.

How to get my params value with a & in the URL?

www.myurl.com?param1=123&param2=456 OK
www.myurl.com?param1=123&param2=456 NOT OK
In my vb code behind, with the second URL, I get the value of param1 only.
Me.Page.Request("param1") : value OK
Me.Page.Request("param2") : value 0
Firstly, I would advise rethinking how your URL is built with a view to removing the need for an & it will be far easier for you.
If this is not possible for whatever reason, you will need to extract the parameter values from the querystring yourself.
One possible solution:
Dim url As String = Request.RawUrl
Dim urlParams As String() = url.Split("?"C)
If urlParams.Length > 1 Then
Dim parameters As String() = urlParams(1).Split(New String() {"&"}, StringSplitOptions.None)
For Each param As var In parameters
' will give you the paramater value
Dim value As String = param.Split("="C)(1)
Next
End If

Danish character not supported

I am working on a site thath has to also support Danish characters (the supported languages will increase in the future).
I am using a database table - lets call it Strings - where I create a record for each string I display on my site. For example, the greeting message in the login page is entered in the database like this:
ID | Description | Text | Lang_code
1 | login | Log In | en
This is the code that pulls the lang_code from the database:
Public Shared Function GetLanguageCodeFromBrowser()
Dim language_code As String
Dim databaseConnection As New DBConnectionAdapter
Dim DataReader, DataReader1 As MySqlDataReader
Dim serverVar As String = HttpContext.Current.Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
language_code = LCase(serverVar)
Dim Query As String = "SELECT language_code FROM languages WHERE language_code = '" & LCase(language_code) & "' AND disabled = 0"
Dim Query1 As String = "SELECT language_code FROM languages WHERE language_code = '" & LCase(Left(language_code, 2)) & "' AND disabled = 0"
Dim cmdSelect As New MySqlCommand(Query, databaseConnection.connectionWebServices)
Dim cmdSelect1 As New MySqlCommand(Query1, databaseConnection.connectionWebServices)
Try
databaseConnection.OpenWebServices()
DataReader = cmdSelect.ExecuteReader
If Not DataReader.Read Then
DataReader.Dispose()
DataReader1 = cmdSelect1.ExecuteReader
If Not DataReader1.Read Then
DataReader1.Dispose()
Return language_code = "en"
Else
Return DataReader1("language_code")
End If
DataReader1 = Nothing
DataReader1.Dispose()
Else
Return DataReader("language_code")
End If
DataReader = Nothing
DataReader.Dispose()
Catch ex As Exception
' TODO Error handling
HttpContext.Current.Response.Write(ex.Message)
Finally
databaseConnection.CloseWebServices()
End Try
databaseConnection = Nothing
End Function
And I use it in the MasterPage's Page_Init event like this:
Session("language_code") = Language_from_Browser.GetLanguageCodeFromBrowser
Everything works fine in English, but when it comes to Danish, some characters are mangled.
I have tried changing this in web.config:
<globalization
fileEncoding="ISO-8859-1"
requestEncoding="ISO-8859-1"
responseEncoding="ISO-8859-1"
culture="auto"
/>
Still not working properly.
Please note that I have a default.aspx page in each one of my folders, so I dont have to bother with URL rewriting (that's how I see it a least)

How to pass the entire contents of Classic ASP session to .net code?

I know the drill about how to call .net code from a Classic ASP site (Server.CreateObject, gacutil, and all the rest). I'm talking about invoking a .net DLL from VBScript code. (This has nothing to do with ASP.net)
What I would like to know is, how can I pass the contents of the entire Classic ASP session to the .net code. I think that I would like to pass Session.Contents to the .net code, but I don't know how to write an interface that would accept that object.
Bonus points if you can also tell me how to pass the entire contents of Request.Form as well as ASPError objects.
Assuming you mean Set invokedNetDLL = CreateObject("MyNamespace.MyType") when you say "invoking a .net DLL from VBScript code", I'd try the following:
<%
Dim key
Dim serializedSession
Dim invokedNetDLL
For Each key in Session
serializedSession = key & "=" & Session(key) & "&"
Next
'Trim last &
serializedSession = Left(serializedSession, Len(serializedSession) - 1)
Set invokedNetDLL = CreateObject("MyNamespace.MyType")
invokedNetDLL.MyMethod(serializedSession)
%>
As far as Request.Form goes, same the method can be applied:
<%
Dim key
Dim serializedSession
Dim serializedRequestForm
Dim invokedNetDLL
For Each key in Request.Form
serializedRequestForm = key & "=" & Request.Form(key) & "&"
Next
'Trim last &
serializedRequestForm = Left(serializedRequestForm, Len(serializedRequestForm) - 1)
For Each key in Session
serializedSession = key & "=" & Session(key) & "&"
Next
'Trim last &
serializedSession = Left(serializedSession, Len(serializedSession) - 1)
Set invokedNetDLL = CreateObject("MyNamespace.MyType")
invokedNetDLL.MyMethod(serializedRequestForm, serializedSession)
%>
I haven't tested this code, but this is where I'd start.

Flickr get latest photos ASP using API

Hey I am currently using the following code
Dim flickr As New Flickr("apikey")
Dim test As New Photos
test = flickr.PhotosGetRecent(5, 5)
For Each [Photo] As FlickrNet.Photo In test.PhotoCollection
Response.Write([Photo].ThumbnailUrl)
Response.Write("<br>")
Next
But this only returns the Most Recent photos uploaded to flick in General, I only want my own ones. Is this possible ?
Thanks
Yes. You have you use PhotosSearch instead, and sort by DateUploaded.
Dim flickr As New Flickr("apikey")
Dim options As New PhotoSearchOptions()
options.UserId = "myuserid#n01"
o.SortOrder = PhotoSearchSortOrder.DatePostedDescending
o.PerPage = 5
o.Page = 1
Dim test As Photos = flickr.PhotosSearch(options)
... etc

Resources