Application_BeginRequest With RegEX Question?

Discussion in 'ASP .Net' started by Leon, Jun 16, 2005.

  1. Leon

    Leon Guest

    Please help, what I'm I doing wrong?????
    --> This following code will not run correctly, no syntax errors, but..
    --> execution error = The subdomain does not exist in database.... "but it
    does in the database"
    --> I think this is the problem in the code but don't know how to fix =
    Me.CommandCheckSDM.Parameters(1).Value = (sdm.Replace(sdmurl, "$1"))

    --> Heres the actual live code...
    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)

    'Comments: Fires at the beginning of each request
    'Comments: Get database connection from config file
    Dim myConnectionString As String
    myConnectionString =
    ConfigurationSettings.AppSettings("myConnectionString")
    Me.Connection.ConnectionString = myConnectionString

    'Comments: Retrieving subdomain ('sdm') name from url
    Dim sdmurl As String = Request.Url.ToString
    Dim sdm As Regex
    sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")


    'Comments: Checking Subdomain name and retrieving account id
    Me.CommandCheckSDM.Parameters(1).Value = (sdm.Replace(sdmurl, "$1"))
    Me.Connection.Open()
    Me.CommandCheckSDM.ExecuteNonQuery()
    Me.Connection.Close()

    If Me.CommandCheckSDM.Parameters(0).Value < 0 Then
    If Me.CommandCheckSDM.Parameters(0).Value = -1 Then
    Throw New Exception("The subdomain does not exist in database.")

    ElseIf Me.CommandCheckSDM.Parameters(0).Value = -2 Then
    Throw New Exception("The subdomain is not active.")
    End If

    Else
    'Comments: Tranfer user to index website
    Context.Items("AccountID") =
    Me.CommandCheckSDM.Parameters(0).Value()
    Server.Transfer("index/MyPage.aspx")
    End If
    End Sub
     
    Leon, Jun 16, 2005
    #1
    1. Advertising

  2. Leon

    Guest

    Try to norrow down the problem by feeding the regex possible inputs.

    If the subdomain exist in your database than the regex doesnt give back the
    correct result.

    Which strings are presented to the regex that fail but should be recognized?

    Let me know if you have any more questions..

    Cheers,
    Tom Pester

    > Please help, what I'm I doing wrong?????
    > --> This following code will not run correctly, no syntax errors,
    > but..
    > --> execution error = The subdomain does not exist in database....
    > "but it
    > does in the database"
    > --> I think this is the problem in the code but don't know how to fix
    > =
    > Me.CommandCheckSDM.Parameters(1).Value = (sdm.Replace(sdmurl, "$1"))
    > --> Heres the actual live code...
    > Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
    > EventArgs)
    > 'Comments: Fires at the beginning of each request
    > 'Comments: Get database connection from config file
    > Dim myConnectionString As String
    > myConnectionString =
    > ConfigurationSettings.AppSettings("myConnectionString")
    > Me.Connection.ConnectionString = myConnectionString
    > 'Comments: Retrieving subdomain ('sdm') name from url
    > Dim sdmurl As String = Request.Url.ToString
    > Dim sdm As Regex
    > sdm = New Regex("http://(?!www\.)(.*)(\.domain\.com.*)")
    > 'Comments: Checking Subdomain name and retrieving account id
    > Me.CommandCheckSDM.Parameters(1).Value = (sdm.Replace(sdmurl,
    > "$1"))
    > Me.Connection.Open()
    > Me.CommandCheckSDM.ExecuteNonQuery()
    > Me.Connection.Close()
    > If Me.CommandCheckSDM.Parameters(0).Value < 0 Then
    > If Me.CommandCheckSDM.Parameters(0).Value = -1 Then
    > Throw New Exception("The subdomain does not exist in
    > database.")
    > ElseIf Me.CommandCheckSDM.Parameters(0).Value = -2 Then
    > Throw New Exception("The subdomain is not active.")
    > End If
    > Else
    > 'Comments: Tranfer user to index website
    > Context.Items("AccountID") =
    > Me.CommandCheckSDM.Parameters(0).Value()
    > Server.Transfer("index/MyPage.aspx")
    > End If
    > End Sub
     
    , Jun 16, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cynic07
    Replies:
    1
    Views:
    485
    Cynic07
    Jul 31, 2003
  2. Amil
    Replies:
    1
    Views:
    486
    William F. Robertson, Jr.
    Feb 19, 2004
  3. =?Utf-8?B?UGF1bCBEYWx5IChNQ1Ap?=

    Session Start / Application_BeginRequest Issues

    =?Utf-8?B?UGF1bCBEYWx5IChNQ1Ap?=, Jul 4, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    6,903
    Craig Deelsnyder
    Jul 4, 2004
  4. JezB
    Replies:
    3
    Views:
    5,509
  5. Replies:
    3
    Views:
    775
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page