Issues with Masterpage loading dynamically

I have an application, that needs to have the masterpage file to be dynamically loaded at runtime.

Based on each portal_id passed, i need to query the database for the corresponding masterpage file and use it. here is the back end code

Partial Class UserProfileLogin
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Overrides Sub OnPreInit(ByVal e As EventArgs)

        Session("PORTAL_ID") = Request.QueryString("PortalID")
        Dim objSiteConfiguration As New DomainDALTableAdapters.objSiteConfigurationTableAdapter
        Dim masterfile As String = objSiteConfiguration.RetrieveMasterPage(CInt(Session("PORTAL_ID")))
        If Not masterfile.Equals(String.Empty) Then
            MyBase.MasterPageFile = masterfile
        End If
    End Sub

End Class

I get the following error

Illegal characters in path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Illegal characters in path.

Any thoughts !!!
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Abu HamdanConnect With a Mentor Enterprise Architect, PM ExpertCommented:
See this article,

You have to do some configuration on web.config
Try stepping through the project and tell us what the value for the masterfile is. We can assist you from there. Its most likely just the path no being properly constructed.
All Courses

From novice to tech pro — start learning today.