从 ReturnUrl 访问其他查询字符串键

发布于 2024-07-28 08:22:47 字数 591 浏览 0 评论 0原文

我需要从 ReturnUrl 查询字符串访问其他查询字符串参数。

整个站点都需要身份验证,因此如果用户未登录或超时,所有页面都将重定向到登录页面。 因此 www.mysite.com/Default.aspx?id=H1234 将重定向到 www.mysite.com/login.aspx?ReturnUrl=%2fDefault.aspx%3fid%3dH1234 如果用户输入凭据,他们将返回到 Default.aspx 并传递 id,但我还需要检查登录页面上的 id。

在登录页面上,我可以 Server.UrlDecode(Request.RawUrl) 到: /login.aspx?ReturnUrl=/Default.aspx?id=H1234 但因为这有 2问号 我现在无法访问 Request.QueryString("id")

我可以使用子字符串方法来提取值,但这让我担心,因为 id 不是固定长度,而且看起来不安全< /em>.

谷歌上似乎没有太多(或者至少我没有问正确的问题)

I need to access additional querystring parameters from the ReturnUrl querystring.

The entire site requires authentication so all pages will redirect to the login page if the user is not logged in or has timed out. So www.mysite.com/Default.aspx?id=H1234 will redirct to www.mysite.com/login.aspx?ReturnUrl=%2fDefault.aspx%3fid%3dH1234 and if the user then enters their credentials they will be returned to Default.aspx passing the id, but I need to check the id on the login page as well.

On the login page I can Server.UrlDecode(Request.RawUrl) to: /login.aspx?ReturnUrl=/Default.aspx?id=H1234 but as this has 2 question marks I now cannot access Request.QueryString("id")

I could use substring methods to extract the value but that worries me as the id is not a fixed length and it seems insecure.

There doesn't seem to be much on Google (or at least I'm not asking the right question)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2024-08-04 08:23:17

没有答案吗?

这就是我设法整理的:

Private Function GetParam(ByVal paramName As String, 
                          ByVal paramMaxLength As Integer) As String 
  Dim paramValue As String = String.Empty 
  Dim url As String = Server.UrlDecode(Request.RawUrl()) 
  If Not url.Contains(paramName) Then 
    Return paramValue 
  End If 

  url = url.Substring(url.LastIndexOf("?") + 1) 
  ExtractParamValue(paramName, paramValue, url) 

  If paramValue.Length > paramMaxLength Then 
    paramValue = paramValue.Remove(paramMaxLength) 
  End If 

  Return paramValue 
End Function

Private Shared Sub ExtractParamValue(ByVal paramName As String, 
                                     ByRef paramValue As String, 
                                     ByVal url As String)
  For Each valuePair As String In url.Split("&")
    If valuePair.StartsWith(paramName) Then
        paramValue = valuePair.Substring(paramName.Length + 1)
    End If
  Next 
End Sub

No answers?

This is what I've managed to put together:

Private Function GetParam(ByVal paramName As String, 
                          ByVal paramMaxLength As Integer) As String 
  Dim paramValue As String = String.Empty 
  Dim url As String = Server.UrlDecode(Request.RawUrl()) 
  If Not url.Contains(paramName) Then 
    Return paramValue 
  End If 

  url = url.Substring(url.LastIndexOf("?") + 1) 
  ExtractParamValue(paramName, paramValue, url) 

  If paramValue.Length > paramMaxLength Then 
    paramValue = paramValue.Remove(paramMaxLength) 
  End If 

  Return paramValue 
End Function

and

Private Shared Sub ExtractParamValue(ByVal paramName As String, 
                                     ByRef paramValue As String, 
                                     ByVal url As String)
  For Each valuePair As String In url.Split("&")
    If valuePair.StartsWith(paramName) Then
        paramValue = valuePair.Substring(paramName.Length + 1)
    End If
  Next 
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文