0

I have integrated an existing Classic ASP site with JQuery (they were using VBScript before). The previous version works fine but the script's needed to be updated so it will work on other browsers. But when I redirect the page with JQuery integrated, the system loads the default.asp file and the second URL. The address bar also shows the default url.

How can I prevent this?

When I use the window.open('url'), it opens the correct page with the correct URL but I have 2 tabs open. When I use window.open('url', '_self') it still redirects to the problematic page.

P.S. Response.Redirect 'url' and window.open('url', '_self') give the same results.

Edit: Here's some of the code used

Here's the main frame JS (submit function) that loads within the default.asp

$("img[name=cmdLog]").click(function(){
            $("form[name=frmLogIn]").target = "_top";
            $("form[name=frmLogIn]").get(0).setAttribute("action", "ValidateUser.asp");
            $("form[name=frmLogIn]").submit();
        });

Here's ValidateUser.asp (without the updated JS, using only VBScript)

<form name="frmValidate" method="post">
    <%
        Session("PMISConnString")="Provider=SQLOLEDB;Server=192.168.x.x;User ID=sa;PWD=x;Database=DB"
        dim conn, rsEmp, SQLQuery, m_Code,i,lenStr,newCode,rsUser
        set conn=Server.CreateObject("ADODB.Connection")

        m_Code=Request.Form("txtEmpID")
        lenStr=len(m_code)
        newCode=""
        for i=1 to lenStr
            if mid(m_Code,i,1)="'" then
                newCode=newCode & "''"
            else
                newCode=newCode & mid(m_Code,i,1)
            end if
        next 


        conn.Open=Session("PMISConnString")

        dim clsCrypt
        dim url
        set clsCrypt=Server.CreateObject("ChiperText.clsChiperText")

        SQLQuery="SELECT UserCode, Pwd "
        SQLQuery=SQLQuery & "FROM Users "
        SQLQuery=SQLQuery & "WHERE UserCode='" & clsCrypt.ChiperText(lcase(newCode)) & "'"

        set rsUser=Server.CreateObject("ADODB.Recordset")
        rsUser.Open SQLQuery,conn

        if rsUser.EOF then
            url = "ErrorPage.asp?TYPE=6"
        elseif rsUser.Fields("Pwd")<>clsCrypt.ChiperText(Request.Form("txtEmpPassword")) then
            url = "ErrorPage.asp?TYPE=7"
        end if

        SQLQuery="SELECT EmpID,EmpFirst,EmpLast,dbo.GetCapitalChars(Employee.EmpMid) AS MidInitial From Employee WHERE EmpID='" & newCode & "' "
        SQLQuery=SQLQuery & "AND EmpActive=1 "

        set rsEmp=Server.CreateObject("ADODB.Recordset")
        rsEmp.Open SQLQuery,conn
        if not rsEmp.EOF then
            Session("EmpID")=Request.Form("txtEmpID") 
            Session("MyName")=rsEmp.Fields("EmpFirst") & " " & rsEmp.Fields("MidInitial") & " " & rsEmp.Fields("EmpLast")
            'varServer="http://" + Request.ServerVariables("SERVER_NAME") + "/" + Session("VirtualName") + "/"

            Response.Cookies("Site")="http://" + Request.ServerVariables("SERVER_NAME") + "/" + "PMIS"

            Session("Server")="http://" + Request.ServerVariables("SERVER_NAME") + "/" + "PMIS"
            Session("ImgFolder")="http://" + Request.ServerVariables("SERVER_NAME") + "/" + "PMIS/Images/" 'full path ng images folder under PMIS directory
            url = "main2.asp"
        else
            url = "ErrorPage.asp?TYPE=1"
        end if

        Response.Redirect(url)
        rsEmp.Close
        Set rsEmp=Nothing
        set clsCrypt=Nothing
        conn.Close
        set conn=Nothing
    %>
</form>
phper
  • 33
  • 6
  • Create a fresh html/asp page with nothing in it and try redirect to this page. See if the same issue happens. – Jules Jun 19 '15 at 01:39
  • It's still the same. And the default.asp is still being loaded. – phper Jun 19 '15 at 02:25
  • OK, create page1.asp and page2.asp on the same server. In page1.asp, create a button with click window.open('page2.asp','_self'). This exercise is to determine whether the issue is on your page or server. – Jules Jun 19 '15 at 03:33
  • Deosn't <%Response.End%> work? – cem Jun 19 '15 at 04:31
  • The window.open('url', '_self') gives the same result. And the window.open('url') opens the right page with the right url on the new tab. document.location.href doesn't work as expected too. – phper Jun 19 '15 at 05:09
  • Have you tried with a different browser and/or on another machine? – Jules Jun 19 '15 at 05:54
  • 1
    Perhaps you need to [read this post](http://stackoverflow.com/questions/7077770/window-location-href-and-window-open-methods-in-javascript) - should help. – Paul Jun 19 '15 at 09:15
  • @Jules I've tried it with other browsers and they give the same problem. – phper Jun 22 '15 at 01:07
  • As mentioned by cem, these are server side vbscript not client side. – Jules Jun 22 '15 at 06:34
  • What could be the problem, then? Neither that VBScript nor JS works correctly. – phper Jun 22 '15 at 08:08
  • I noticed on your js the form name is frmLogin where as in your asp is frmValidate? – Jules Jun 22 '15 at 10:29
  • They are separate files. After the frmLogin has been submitted, it redirects to the ValidateUser.asp – phper Jun 23 '15 at 02:24

1 Answers1

0

If in a frameset, consider using JavaScript to change window.top.location.href to your redirect URL instead.

CLaFarge
  • 1,277
  • 11
  • 16
  • The reason why I want to convert it to JS it that it could be accessed with other browsers, not just IE. It's the main problem for us, we can only use the site with IE. If there's a way to make VBScript work with other browsers without needing to install some plugins per computer, I would stick to the VBScript. – phper Jun 22 '15 at 01:11
  • I was referring to the VBScript on the Server-Side, which the Browser never sees. We don't see enough code to have a real sense of what's happening and where the code lives that you're trying to use. My comment is in the context of rewriting the ASP, not the stuff that goes to the browser. For clarity: The SERVER-SIDE VBScript is never sent to the CLIENT-SIDE browser. The stuff that does all the Response.Writing can stay in VBScript... it's the stuff that it Response.Writes that needs to be JavaScript. – CLaFarge Jun 22 '15 at 01:54
  • I don't think I understand you fully. But please check my edit and tell me what my code lacks. That code is not redirecting correctly, btw. – phper Jun 22 '15 at 02:35
  • If the second code listing is doing it's job, that form will never be seen. Response.Redirect is meant to end all processing and send the user to the given URL and NOT render anything from the current script. – CLaFarge Jun 22 '15 at 20:28
  • Also, when you use Response.Redirect, it's good to close all of the recordset and connection objects prior to calling Response.Redirect, as ASP processing stops at that call. ASP _should_ auto-close them as it leaves the page, but it's always better to explicitly clean our own stuff instead of counting on ASP to do it for us. Also, do not write any HTML prior to using Response.Redirect, as its job is send the user to another page anyway. You shouldn't _need_ to do this, but try sending the fully qualified URL instead of a relative link, and could also try prepending "./" to the link. – CLaFarge Jun 22 '15 at 20:28
  • It's still the same. And yes, I have enabled the error reporting of ASP, there's no error shown. When I checked the source code after redirecting, I've found out that the main frame from default.asp loads the redirected page (from the ValidateUser.asp) inside of it. Is it normal for ASP to always load the default.asp? – phper Jun 23 '15 at 02:30
  • You haven't shown us the frame structure... that would be determined by your frameset. If in a frameset, consider using JavaScript to change window.top.location.href to your redirect URL instead. – CLaFarge Jun 23 '15 at 03:31
  • 1
    It worked! I added `$('form[name=frmLogIn]').prop("target", "top");` before the `$('form[name=frmLogIn]').submit();` in my JS. Now it doesn't load the default.asp anymore. Thank you very much, sir! :) Off-topic: I cannot upvote your comment yet, how can I mark your answer as the correct one? – phper Jun 23 '15 at 04:47
  • Outstanding! Feel free to mark the EDITED answer as Answer. – CLaFarge Jun 23 '15 at 16:46