Managing website paths manually across multiple pages can quickly become difficult during development and deployment. This VB.NET Global Variable approach allows developers to centralize their website paths into a single reusable class, making it easier to switch between local DEBUG environments and live production websites. It also helps keep URLs cleaner, more organized, and easier to maintain across larger projects.
[ASP.NET - VB Global Variable]
CFFCS | CarrzSynEdit: | ASP.NET (VB/C#)
Imports System.Web
Public Class GlobalVariable

Public Shared ReadOnly Property BasePath As String
    Get
#If DEBUG Then
        Return "/ursite/"
#Else
        Return "https://ursite.com/"
#End If
    End Get
End Property
End Class

How to use
Using it in the frontend
<%=GlobalVariable.BathPath%>
Copy
Search Site
Search Google
Using is in the backend (CodeBehind)
CFFCS | CarrzSynEdit: | ASP.NET (VB/C#)
Public Function ArticleUrl(ByVal value As Object) As String
    Return GlobalVariable.BathPath & "Main.aspx?Type=Article&ID=" & Convert.ToString(value)
End Function

Other Articles Related to this Entry.