Search code examples
vb.netreporting-servicesssrs-2012ssrs-expression

SSRS URL Encode


I have an issue with an expression in SSRS

Project

USE SSRS Expressions and custom code to encrypt, and then determine target to hyperlink to based on environment.

What we have accomplished

We have created a custom DLL using a custom library imported into the References in Report properties

From within the Expression then we wrote Switch statement to determine the target as follows:

Expression

=Switch
(
Globals.ReportServerUrl = "https://devportal2.xxx.com/sites/Co" , "https://stage.connect.com/secure/clr/er=" & Code.EncryptRin(Fields!Member_Member_ID_.Value),
Globals.ReportServerUrl = "https://testportal2.xxx.com/sites/Co" , "https://stage.connect.com/secure/clr/er=" & Code.EncryptRin(Fields!Member_Member_ID_.Value),
Globals.ReportServerUrl = "https://stageportal2.xxx.com/sites/Co" , "https://www.connect.com/secure/clr/er=" & Code.EncryptRin(Fields!Member_Member_ID_.Value),
Globals.ReportServerUrl = "https://stageportal2.xxx.com/sites/Co" , "https://www.connect.com/secure/clr/er=" &
 Code.EncryptRin(Fields!Member_Member_ID_.Value),true, "https://stage.connect.com/secure/clr/er=" + Code.EncryptRin(Fields!Member_Member_ID_.Value)
)

Custom Code

Public Function UserName()
Try
    Return Report.User!UserID
  Catch
    Return "System"
  End Try
End Function


Public Function EncryptRin(ByVal Rin as string) As String
    Return Encryption.AESConsole.EncryptText(Rin)
End Function

In the above there are two functions one is not relevant and that's the Username() one. The second one is the part we need to encode.

What I need help with

We need to encode the encrypted portion of the URL before we can send it over. But I'm a little confused on WHERE this needs to happen.

So my understanding is I need to do this from the Expression because that's where we are referencing it. If that's not where it happens, what would the syntax look like to reference a parameter in the above function before it gets to the expression?

Has anyone done this? Help is much appreciated.


Solution

  • In VB.net you should be able to use System.Uri.EscapeDataString to encode the data before encrypting it. Something like this:

    Public Function EncryptRin(ByVal Rin as string) As String
        Return Encryption.AESConsole.EncryptText(Uri.EscapeDataString(Rin))
    End Function