Jun 10 2021

ASP: web config http to https redirection


                <clear />
                <rule name="Redirect to https" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>

source: https://stackoverflow.com/questions/9823010/how-to-force-https-using-a-web-config-file


Mar 17 2020

ASP: web.config redirect to another domain with no rules – v2


<rewrite>
  <rules>
    <rule name="redirect" enabled="true">
      <match url="(.*)" />
      <action type="Redirect" url="http://www.example.com/" appendQueryString="true" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

Oct 31 2019

ASP: web.config redirect


<system.webServer>

<httpRedirect enabled="true" destination="http://www.google.com/" />

</system.webServer>

Oct 4 2019

Classic ASP – Getting ID of new record after insert


Dim loConn, lsSQL, loRs
Set loConn = CreateObject("ADODB.Connection")

' Open a connection to the database
loConn.Open(application("DSN=myDSN;UID=something;PWD=Something;"))

' Insert a new record into the table
lsSQL = "SET NOCOUNT ON;" &_
        "INSERT INTO tbl_test (naziv) VALUES ('pero');" &_
        "SELECT @@IDENTITY AS NewID;"

' Execute the SQL statement
Set loRs = loConn.Execute(lsSQL)

' Get the inserted ID
myNewID= loRs.Fields("NewID").value

response.write myNewID

' Close the connection
loConn.Close()
Set loConn = Nothing

The SET NOCOUNT ON suppresses messages like “1 Row(s) affected” being sent back. These messages are sent back every time SQL statement is executed.

source: http://www.kamath.com/tutorials/tut007_identity.asp


Sep 25 2019

Classic ASP – URLDecode

FUNCTION URLDecode(str)
'// This function:
'// - decodes any utf-8 encoded characters into unicode characters eg. (%C3%A5 = å)
'// - replaces any plus sign separators with a space character
'//
'// IMPORTANT:
'// Your webpage must use the UTF-8 character set. Easiest method is to use this META tag:
'//
'//
Dim objScript
Set objScript = Server.CreateObject("ScriptControl")
objScript.Language = "JavaScript"
URLDecode = objScript.Eval("decodeURIComponent(""" &amp; str &amp; """.replace(/\+/g,"" ""))")
Set objScript = NOTHING
END FUNCTION

 

source: https://gist.github.com/gwobcke/2773779


Sep 9 2019

Classic ASP – Strip HTML Function


<%
FUNCTION stripHTML(strHTML)
  Dim objRegExp, strOutput, tempStr
  Set objRegExp = New Regexp
  objRegExp.IgnoreCase = True
  objRegExp.Global = True
  objRegExp.Pattern = "<(.|n)+?>"
  'Replace all HTML tag matches with the empty string
  strOutput = objRegExp.Replace(strHTML, "")
  'Replace all < and > with &lt; and &gt;
  strOutput = Replace(strOutput, "<", "&lt;")
  strOutput = Replace(strOutput, ">", "&gt;")
  stripHTML = strOutput    'Return the value of strOutput
  Set objRegExp = Nothing
END FUNCTION
%>

source: https://gist.github.com/gwobcke/1027133


Sep 9 2019

Classic ASP – Strip Special Character Function


<%
Function StripSpecialChar(strInput)
	Dim objRegExp
	Set objRegExp = New Regexp
	objRegExp.IgnoreCase = True
	objRegExp.Global = True
	objRegExp.Pattern = "[\+\#\@\&\%\$\?\*]"
	'//Replace all character matches with an Empty String
	StripSpecialChar = objRegExp.Replace(strInput, "")
	Set objRegExp = Nothing
End Function
%>

source: https://gist.github.com/gwobcke/1027138/revisions


Sep 8 2019

Classic ASP – IN ARRAY

Function InArray(Needle, Haystack)
    Dim i, x
    InArray = False

    For i = 0 To Ubound(Haystack)
        If IsArray(Needle) = True Then
            For x = 0 To Ubound(Needle)
                If Trim(Haystack(i)) = Trim(Needle(x)) Then
                    InArray = True
                    Exit Function
                End If
            Next
        Else
            If Trim(Haystack(i)) = Trim(Needle) Then
                InArray = True
                Exit Function
            End If
        End If
    Next
End Function

SOURCE: https://gist.github.com/gwobcke/1044367


Sep 8 2019

ASP – ArrayList

Option Explicit

dim list
Set list = CreateObject("System.Collections.ArrayList")
list.Add "Banana"
list.Add "Apple"
list.Add "Pear"

'list.Sort
'list.Reverse

response.write list.Count                 ' --> 3
response.write list.Item(0)               ' --> Pear
response.write list.IndexOf("Apple", 0)   ' --> 2
response.write join(list.ToArray(), ", ") ' --> Pear, Banana, Apple

source: https://stackoverflow.com/questions/13585660/lists-in-vbscript


Sep 14 2016

ASP – dynamic variable i execute

Problem: imamo varijable slika_1, slika_2, slika_3, slika_4 i slika_5 i želimo ispisati svih 5 slika koristeći for petlju

Rješenje:

for i=1 to 5

execute("slika = slika_" & i)

response.write(slika)

next