如何使用 Querystring 而不是 ';' [英] How to use the Querystring instead of ';'

查看:45
本文介绍了如何使用 Querystring 而不是 ';'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编写一个内部工具,供使用由 C# WebApi 支持的 Angular2 beta 15 的开发人员使用.

I have been writing an internal tool for use by developers using Angular2 beta 15 backed by a C# WebApi.

随着新版本的发布,我更新了 Angular2 版本

I up the Angular2 version as new versions are released

我从第一天开始就使用路由,但现在我需要添加可选参数.通常这是通过查询字符串完成的.

I have been using routing from day 1 but now I need to add optional parameters. Typically this is done via the querystring.

但是,Angular2 在查询字符串之前包含可选参数,如下所示:

However, Angular2 includes optional parameters before the querystring like so:

http://www.example.com;a=b;c=4

最初我认为这会很好,即使我不习惯这样做.但是,我现在遇到了需要潜在危险的 Request.Path 值[s]"的情况,例如*"(用于保存带有预填充的正则表达式搜索字段的链接).

Originally I figured that would be fine, even though it isn't what I am used to. However, I have now run into cases where I need to have "potentially dangerous Request.Path value[s]" such as "*" (for saving links with a regular expression search field pre-populated).

我能想到几个修复方法,包括:

I can think of several fixes including:

  1. 将 * 替换为不同的符号 - 意味着开发人员必须知道特殊符号才能释放网址.
  2. 对参数进行网址编码 - 意味着开发人员必须知道网址编码值才能释放网址.
  3. 排除具有特殊字符的参数 - 如果开发人员使用 * 释放网址,页面仍然会中断.
  4. 从预查询字符串参数切换到查询字符串参数.
  5. 手动控制查询字符串.

大多数简单的正则表达式在没有编码的查询字符串中是完全有效的,这意味着 (4) 和 (5) 都是有效的解决方案.

Most simple regular expressions are perfectly valid in the querystring without encoding, this means that both (4) and (5) are valid solutions.

(5) 是可能的,但我无法想象我是唯一遇到此问题的人.如果存在官方解决方案,我宁愿不创建自己的解决方法.

(5) is possible, but I can't imagine I am the only one who has run into this issue. I would rather not create my own workaround if an official solution exists.

(4) 是我的首选解决方案.我发现的许多旧示例都显示了查询字符串中的可选参数,所以我希望逻辑仍然存在,分号版本只是默认选项.

(4) is my preferred solution. Many of the older examples I have found show the optional parameters in the querystring, so I hope that the logic still remains and that the semi-colon version is simply the default option.

是否可以告诉路由器使用查询字符串参数而不是它现在使用的分号分隔的东西?

Is it possible to tell the router to use querystring parameters instead of the semi-colon delimited stuff it does now?

我搜索了 angular.io 和 stackoverflow,但找不到任何答案或任何人问这个问题.

I searched both angular.io and stackoverflow and could not find any answers or anyone asking this question.

谢谢.

推荐答案

对于根路由器的可选参数在查询字符串中表示,对于子路由器,它们被添加为矩阵参数(你所展示的)

For the root router optional parameters are represented in the querystring, for child routers they are added as matrix parameters (what you showed)

另见ROUTING &导航

这篇关于如何使用 Querystring 而不是 ';'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆