问题描述
我有一个 ashx 接收登录名/密码,如果有误,则发送错误消息,但如果它很好,请创建一个 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
如果直接在浏览器url区域使用ashx:http://localhost:5959/login/login.ashx?UserName=toto&Password=MyPass,直接跳转到默认页面http://localhost:5959 //choix.aspx
但是如果我从 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);
}
});
我需要使用pushState来更正浏览器中的url,并使用window.open/write来显示默认页面。但正如你所看到的,我写了硬“/choix.aspx”,因为url没有修改并停留在referer URL上(我的登录页面http://localhost:5959/Login/login.html) 但是,如果我在浏览器中使用我的ashx时可以自动获得好的URL,则似乎是发送了URL信息。
在响应 $post 的函数使用中,我注意到几个参数:response,ti response 是返回显示页面的文本 tt=“成功” ti 是一个包含大量信息的对象......但我没有看到 URL 在哪里。 如果有人可以帮助我。
解决方法
我只是找到了一种方法here
在我的主页
arrays?[0].filter(elem => arrays.every(array => array.includes(elem))) ?? []
在 login.js 中
Private Sub Choix_Init(sender As Object,e As EventArgs) Handles Me.Init
Response.AppendHeader("X-MONAPPLI",HttpContext.Current.Request.Url.PathAndQuery)
End Sub
我使用 replaceState 而不是 pushstate 因为我有安全错误