Compare two different URLs in ASP.NET


VB Code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim url As String = Request.Url.AbsoluteUri
        Dim url1 As String = "http://localhost:2061/WebSite1/Default.aspx"
        Dim MyInt As Integer = url.CompareTo(url1) 'return 0 (true) or -1 (false)
        If (MyInt = 0) Then
            Label1.Text = "Same url"
        Else
            Label1.Text = "not same url"
        End If

    End Sub

C# Code

protected void Page_Load(object sender, System.EventArgs e)
{
          string url = Request.Url.AbsoluteUri;
          string url1 = "http://localhost:2061/WebSite1/Default.aspx";
          int MyInt = url.CompareTo(url1);
          //return 0 (true) or -1 (false)
          if ((MyInt == 0)) {
                   Label1.Text = "Same url";
          } else {
                   Label1.Text = "not same url";
          }

}

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples