javascript - 在哪里找到返回 ASHX 返回 RedirectFromLoginPage 的 URL
问题描述
我有一个 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 没有修改并停留在引用 URL 上(我的登录页面 http://localhost:5959/Login/login.html)但是如果我可以当我在浏览器中使用我的 ashx 时,自动获得了良好的 URL,似乎发送了 URL 信息。
在响应 $post 的函数使用中,我注意到几个参数:response,tt,ti response 是显示页面的文本,返回 tt="success" ti 是一个包含大量信息的对象......但我看不到在哪里是网址。如果有人可以帮助我。
解决方案
我只是在这里找到一个方法
在我的母版页中
Private Sub Choix_Init(sender As Object, e As EventArgs) Handles Me.Init
Response.AppendHeader("X-MONAPPLI", HttpContext.Current.Request.Url.PathAndQuery)
End Sub
在 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);
}
});
我使用 replaceState 而不是 pushstate 因为我有安全错误
推荐阅读
- c# - 当我有 3 个相同的对象时,只有一个游戏对象统一移动
- jenkins - 詹金斯未达到的资格
- flutter - Flutter + SharedPreferences:构建函数返回 null
- git - 当路径发生任何变化时,Gitattributes 会引发冲突
- java - Java 二维数组矩阵程序
- excel - 执行此代码后 VBA 宏冻结
- c#-4.0 - 在 C# 中连接后内存中的字符串对象
- python - 您可以使用 Jenkins 远程触发以在您的存储库中运行脚本吗(该脚本与构建无关)
- python - ND 索引与 NumPy 中的默认值
- sql-server - 如何将数据类型 VARCHAR 更改为 DATETIME?