Mem
Mem

Reputation: 31

how to find subdomain from current URL ASP-Classic

I am trying to write small script that single script source communicating with different database but there database name gets from subdomain name. currently I did the below test and having problem and couldn't fix by myself. the problem is, when one user opens many subdomain tabs in their browser, for 90 second or 2 minutes, the first request's responses will be same respond for another all requests.

for example URLs:

http://user1.domains.com/subdomaintest.asp

https://user1.domains.com/subdomaintest.asp

http://user2.domains.com/subdomaintest.asp

http://user3.domains.com/subdomaintest.asp

http://user4.domains.com/subdomaintest.asp

http://user5.domains.com/subdomaintest.asp

for first I open http://user1.domains.com/subdomaintest.asp then open http://user2.domains.com/subdomaintest.asp and I get the same response h1text(user1), which is not expected. it has to response h1text as user2. let say if I open after 2 minutes the second url, then responds user2, which is ok. also the GUID is same, seems like works same as the responses.

what I want is, respond has to always on depend subdomain name anytime, not after 2 minutes. if this is IIS problem, what is it and where I can change it? also how to implement the GUID into the browser tab and or session?

here is the code:

'ServerName = Request.ServerVariables("HTTP_HOST")
ServerName = Request.ServerVariables("SERVER_NAME")
arrSplitted = Split(ServerName, ".")
SubDomain = arrSplitted(0)
'response.write(SubDomain)
response.write "<h1>" & SubDomain & "</h1>"
Response.Write "<h1>"& CreateGuid() &"</h1>"
Function CreateGuid()
    CreateGuid = Mid(CreateObject("Scriptlet.TypeLib").Guid,2,36)
End Function

I did a lot's of reading on HTTP HEADER and find out the difference of Request.ServerVariables("SERVER_NAME") and Request.ServerVariables("HTTP_HOST").

response.write Request.ServerVariables("SERVER_NAME")
response.write Request.ServerVariables("HTTP_HOST")

but It didn't helped me. Also I have tried responding cookie, but it's the same. seems like IIS doesn't care I am requesting from different subdomain for 2 minutes. why is that?

About Server: IIS10, sessionstate false(I am not using), 64bit. related any information you can ask me.

any body help me, Thank you very much in advance! Please help!

Upvotes: 0

Views: 1080

Answers (2)

Mem
Mem

Reputation: 31

I found the problem by myself.

the web server was iis 10, which supports wildcard biddings and I have used many 80 and 443 bids to the website, including wildcard subdomains and live website. all was in one folder and the website has one application pool and some other configurations.

the problem is the session.

so many article I read, look for solution, none of them works. then I was sure this was the session problem and tried to test with different website. yes, created different application pool and website for the test. tested and everything works.

the problem was in the session, not the code.

Upvotes: 0

Zam
Zam

Reputation: 2940

imho you did almost everything right

but, i suppose you mess with position. you need to check only 1st level subdomain, which has index UBound(X) - 1

<%
  Dim LServerName, LNames, LCycle
  LServerName = Request.ServerVariables("SERVER_NAME")

  Response.Write "<br>Full server name: " & LServerName

  If LServerName <> "" Then
    LNames = Split(LServerName, ".")

    For LCycle = LBound(LNames) To UBound(LNames)
      Response.Write "<br>Level #" & LCycle & ": " & LNames(LCycle)
    Next

    Response.Write "<br>UBound: " & UBound(LNames)

    If UBound(LNames) > 0 Then
      Response.Write "<br>Top level domain is: " & LNames(UBound(LNames))
      Response.Write "<br>1st level subdomain is: " & LNames(UBound(LNames) - 1)
    End If 

    If UBound(LNames) > 2 Then
      Response.Write "<br>2nd level subdomain is: " & LNames(UBound(LNames) - 2)
      Response.Write "<br>3rd level subdomain is: " & LNames(UBound(LNames) - 3)
    End If
  End If
%>

Upvotes: 2

Related Questions