Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

javascript - Where find URL in return of an ASHX returning RedirectFromLoginPage

I have an ashx receiving login/password and send error message if it's wrong but if it's good make a RedirectFromLoginPage.

Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        FormsAuthentication.SignOut()
        Dim LesDatas As New MyEntities
        Dim username As String = GetParamURL("UserName")
        Dim password As String = GetParamURL("Password")

            If Not IdentifyCollab(username, password, LesDatas) Then
                FormsAuthentication.SignOut()
                context.Session.Abandon()
                HelperJournal.Log("Echec de connexion :" & username)
                loginStatut = LoginFailed(GetIPAddress, LesDatas)
                context.Response.ContentType = "text/plain"
                context.Response.Write(loginStatut.Msg)
            Else
                 FormsAuthentication.RedirectFromLoginPage(ConnectedUser.Login, False)
            End If
End Sub

If You use directly the ashx in browser url zone : http://localhost:5959/login/login.ashx?UserName=toto&Password=MyPass, you're directly redirect in the default page http://localhost:5959//choix.aspx

But If I call it from JS :

$.post("/Login/Login.ashx?UserName=" + mdp1 + "&Password=" + mdp2, {},
     function (response,tt,ti) {
        if (response.indexOf("html") === -1) $("#ResultConnexion").html(response); else {
           window.history.pushState("", "", '/choix.aspx');
           var newWindow = window.open("", "_self");
           newWindow.document.write(response);
           }
      });

I need to use pushState to correct the url in browser, and window.open/write to display the defaultpage. But like you can see, I write in hard "/choix.aspx", cause the url are not modify and stay on referer URL (my login page http://localhost:5959/Login/login.html) But If I can have automaticly the good URL when I use in browser my ashx, it's seems the URL information is sent.

In function use in response of $post I note severals parameters : response,tt,ti response is the text to display page in return tt="success" ti is an object with lot of informations... but I don't see where is URL. If someone can help me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just find a way here

In my masterpage

 Private Sub Choix_Init(sender As Object, e As EventArgs) Handles Me.Init
    Response.AppendHeader("X-MONAPPLI", HttpContext.Current.Request.Url.PathAndQuery)
  
End Sub

and in login.js

 $.post("/Login/Login.ashx?UserName=" + mdp1 + "&Password=" + mdp2, {},
      function (response, tt, xhrreq) {
         if (response.indexOf("html") === -1) $("#ResultConnexion").html(response); else {
             window.history.replaceState("", "", xhrreq.getResponseHeader("X-MONAPPLI"));
              var newWindow = window.open("", "_self");
             newWindow.document.write(response);
             }
          });

I use replaceState instead of pushstate cause I've secyrity error


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...