Application_BeginRequest With RegEX Question?

L

Leon

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
 
T

tom.pesterDeLeTeTHISSS

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top