Total Pageviews

Sunday, April 2, 2017

Updating site http to https

Add HTTP response header as below on IIS

Content-Security-Policy : upgrade-insecure-requests

Above will treat http request as secured.

Add a rule as below between <rules></rules> section

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
  <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>

Monday, March 13, 2017

Getting IIS hosted web site's information

VBScript will fetch IIS web site's information. Just download and double click to run, a text file will be created with necessary information.

https://drive.google.com/open?id=0B8R1wPP0Gj58SDFTUjlhdWk2Um8



Monday, February 13, 2017

.Getting .NET framework versions

Go to CMD

This will display framework version

cmd:\> reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full" /v version

Monday, October 19, 2015

Uploading fles to specific folder on BOX

Refresh token is over written on each request and store on text file.


 Function UploadToBox(ByVal attachedFilename As String, ByVal stream As System.IO.Stream) As Boolean

        Dim clientID As String
        Dim clientSecret As String
        Dim oldRefreshToken As String
        Dim newToken As BoxApi.V2.Authentication.OAuth2.OAuthToken

        clientID = ConfigurationManager.AppSettings("clientid")
        clientSecret = ConfigurationManager.AppSettings("clientsecret")

        Dim tokenProvider As New TokenProvider(clientID, clientSecret)

        '''' Reading Refresh token from the file
        Dim streamReader As StreamReader
        streamReader = System.IO.File.OpenText(Server.MapPath("~\\Box\\BoxApiRefreshToken.txt"))
        oldRefreshToken = streamReader.ReadToEnd()
        streamReader.Close()

        newToken = tokenProvider.RefreshAccessToken(oldRefreshToken)
        Dim boxManager As New BoxManager(newToken.AccessToken)

        '''' Writing the new Refresh token to the file
        Dim streamWriter As New StreamWriter(Server.MapPath("~\\Box\\BoxApiRefreshToken.txt"))
        streamWriter.Write(newToken.RefreshToken)
        streamWriter.Close()

        Dim uploadFolder As Folder

        ''''rootFolder = boxManager.GetFolder(Folder.Root)
        uploadFolder = boxManager.GetFolder(ConfigurationManager.AppSettings("uploadFolderID"))

        Dim fileName As String
        fileName = System.IO.Path.GetFileNameWithoutExtension(attachedFilename)
        fileName = fileName + "-" + Guid.NewGuid.ToString + System.IO.Path.GetExtension(attachedFilename)

        boxManager.CreateFile(uploadFolder, fileName, ConvertStreamToByteArray(stream))


    End Function
Convert stream to byte array
    Private Function ConvertStreamToByteArray(ByVal stream As System.IO.Stream) As Byte()

        Dim streamLength As Long = Convert.ToInt64(stream.Length)
        Dim fileData As Byte() = New Byte(streamLength) {}
        stream.Position = 0
        stream.Read(fileData, 0, streamLength)
        stream.Close()

        Return fileData

    End Function

Getting Salesforce session ID

Put the post request on XML files

 Function GetSalesForceSessionID() As String

        Dim SID As String = String.Empty

        Dim AllowUploadSalesforce As String

        AllowUploadSalesforce = ConfigurationManager.AppSettings("allowUploadSalesforce").ToLower()

        If AllowUploadSalesforce = "true" Then

            '''' Loading XML Data
            Dim XMLDoc As New StreamReader(Me.Server.MapPath("~") + "/XMLTemplates/WestpacCredentials.xml")

            '''' Transform XML data to byte array
            Dim XMLData As String
            XMLData = XMLDoc.ReadToEnd()
            Dim PostData As Byte() = Encoding.UTF8.GetBytes(XMLData)

            '''' Post XML data to Salesforce
            Dim WClient As New WebClient
            WClient.Headers.Add("SOAPAction", "login")
            WClient.Headers.Add("Content-Type", "text/xml; charset=utf-8")

            Dim OutPutData As Byte()

            Try
                OutPutData = WClient.UploadData(ConfigurationManager.AppSettings("SFEndPoint"), "POST", PostData)

                '''' Reading the the response
                Dim XMLOutPut As String
                XMLOutPut = WClient.Encoding.GetString(OutPutData)

                '''' Transform XML string to XML document
                Dim XMLOutputDoc As New XmlDocument
                XMLOutputDoc.LoadXml(XMLOutPut)

                Dim root As XmlElement
                root = XMLOutputDoc.DocumentElement

                '''' Reading SessionID from xml
                SID = root("soapenv:Body")("loginResponse")("result")("sessionId").InnerText

            Catch ex As Exception

                SID = String.Empty
                Me.SendServiceError(ex.ToString())

            End Try

            WClient.Dispose()
        End If

        Return SID

    End Function

Validate on lost focus

On the Page_Load

txtFirstNameStep0.Attributes.Add("onblur", "ValidatorOnChange(event);")

Disable multiple button clicks

Call on the Page_Load

 PreventMultipleClicksforContinue(ibContinueStep0)

Below method adds JAVAScript code to the on click event

    Public Shared Sub PreventMultipleClicksforContinue(ByRef button As System.Web.UI.WebControls.Button)
        button.Attributes.Add("onclick", "if (Page_ClientValidate()) { this.disabled=true;}" & button.Page.ClientScript.GetPostBackEventReference(button, String.Empty).ToString)
    End Sub