假设我有链接http://www.somesite.com/file.aspx?a=1&b=2
现在我想删除所有参数,所以它变成:
http://www.somesite.com/file.aspx
或者我可能只想删除其中的一个参数,例如
http://www.somesite.com/file.aspx?b=2
有没有办法在C#中执行上述操作?发生的事情是我来自另一个页面,在网址中有一个名为edit的参数,但当页面回发时,编辑参数仍然存在,所以它仍然认为它处于编辑模式.例:
用户A转到第one.aspx页并点击编辑链接.他们被带到two.aspx?edit = true.在页面加载期间,它看到查询字符串参数edit不为null并且它将内容置于编辑模式.用户完成编辑后,页面会刷新,但网址仍为two.aspx?edit = true并保持内容处于编辑模式,实际上应该是two.aspx
可能重复:
子串算法
给定两个字符串A和B,如何在A中找到B的第一个位置?例如,A ="ab123cdefgcde"; B ="cde"然后A中B的第一个位置是5.
有什么技巧可以解决这个问题,或者只是从头开始搜索A?
我有一个现有的asp.net网站,它使用母版页构建,我需要隐藏或加密所有传递查询字符串值,而不需要更改大量代码.
任何人都可以帮我解决这个问题吗?还是有其他想法而不是隐藏或加密>>?
谢谢.
我实现面搜索功能,用户可以过滤和向下钻取4我的模型的属性:City,Type,Purpose和Value.
我有一个像这样的facet的视图部分:

上图中显示的每一行都是可点击的,以便用户可以向下钻取并进行过滤...
我这样做的方式是使用自定义ActionLink帮助器方法传递的查询字符串:
@Html.ActionLinkWithQueryString(linkText, "Filter",
new { facet2 = Model.Types.Key, value2 = fv.Range });
Run Code Online (Sandbox Code Playgroud)
此自定义帮助程序保留先前的筛选器(查询字符串参数),并将它们与其他操作链接中存在的新路由值合并.当用户应用了3个过滤器时,我得到了这样的结果:
http://leniel-pc:8083/realty/filter?facet1=City&value1=Volta%20Redonda&
facet2=Type&value2=6&facet3=Purpose&value3=3
Run Code Online (Sandbox Code Playgroud)
它正在工作,但我想知道使用路线更好/更清洁的方式.参数的顺序可以根据用户应用的过滤器而改变.我有这样的想法:
http://leniel-pc:8083/realty/filter // returns ALL rows
http://leniel-pc:8083/realty/filter/city/rio-de-janeiro/type/6/value/50000-100000
http://leniel-pc:8083/realty/filter/city/volta-redonda/type/6/purpose/3
http://leniel-pc:8083/realty/filter/type/7/purpose/1
http://leniel-pc:8083/realty/filter/purpose/3/type/4
http://leniel-pc:8083/realty/filter/type/8/city/carangola
Run Code Online (Sandbox Code Playgroud)
这可能吗?有任何想法吗?
我正在寻找一个jQuery选择器来查找图像的所有链接,这很简单,比方说,
$('a[href$="jpg"], a[href$="jpeg"], a[href$="png"], a[href$="gif"]')
但是,如果我的链接附加了一个查询字符串,则会中断,如下所示:
<a href="http://example.com/image1.jpg?1737892">link</a>
有没有办法选择上面的所有图像链接,但如果图像链接在其末尾有一个查询字符串,它仍然可以工作?
我的查询字符串有下一个样子:
....xxxx.aspx#access_token=xxxx&expires=xxxx
Run Code Online (Sandbox Code Playgroud)
当我查询querystring的值时,它什么也没给我.在这篇特殊字符尖锐的URL-Query-String文章中,我发现#字符之后的所有内容都视为null.我如何获取值?
我需要能够在C#应用程序中打开浏览器中的链接.通常,我会使用这样的代码打开链接:
Process.Start(new ProcessStartInfo("explorer.exe", @"http://www.google.com"));
Run Code Online (Sandbox Code Playgroud)
不幸的是,当URL包含查询字符串时,只有成功打开资源管理器而不是浏览器,例如:http: //www.google.com/search?q = stackoverflow
如何打开包含查询字符串的URL?
编辑注释:我使用的是Windows 8和非IE默认浏览器.当我尝试使用如下所述的Process.Start时,我看到同样的错误"Class Not Registered":在Windows 8/Chrome上打破了Process.Start(url) - 还有替代方案吗?
问题:
是否可以知道被调用动作所期望的参数类型?例如,我有一些action:
[TestCustomAttr]
public ActionResult TestAction(int a, string b)
{
...
Run Code Online (Sandbox Code Playgroud)
并TestCustomAttr定义为:
public class TestCustomAttr : System.Web.Mvc.ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
...
Run Code Online (Sandbox Code Playgroud)
因此,当调用TestAction此处内部时OnActionExecuting,我想知道该TestAction方法所期望的类型.(例如:在这种情况下,有2个预期参数.一个是类型int,另一个是类型string.
实际目的:
实际上我需要更改值QueryString.我已经能够获取查询字符串值(通过HttpContext.Current.Request.QueryString),更改它,然后手动将其添加ActionParameters为filterContext.ActionParameters[key] = updatedValue;
问题:
目前,我尝试将值解析为int,如果它被成功解析,我认为它是一个int,所以我进行需求更改(例如值+ 1),然后将其添加到操作参数,对应其键.
qsValue = HttpContext.Current.Request.QueryString[someKey].ToString();
if(Int32.TryParse(qsValue, out intValue))
{
//here i assume, expected parameter is of type `int`
}
else
{
//here i assume, …Run Code Online (Sandbox Code Playgroud) c# custom-attributes query-string onactionexecuting asp.net-mvc-4
我可以从脚本中使用节点4.2.6中的查询字符串,但我可以从节点提示符.这是一些证据.
我有以下脚本:
$ cat test.js
console.log(process.versions)
console.log(querystring)
Run Code Online (Sandbox Code Playgroud)
我运行时遇到错误:
$ node test.js
{ http_parser: '2.5.0',
node: '4.2.6',
v8: '4.5.103.35',
uv: '1.8.0',
zlib: '1.2.8',
ares: '1.10.1-DEV',
icu: '56.1',
modules: '46',
openssl: '1.0.2e' }
/path/to/file/test.js:2
console.log(querystring)
^
ReferenceError: querystring is not defined
at Object.<anonymous> (/path/to/file/test.js:2:13)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
Run Code Online (Sandbox Code Playgroud)
但是如果我在命令行进入节点,我就不会收到错误.
$ node
> console.log(process.versions)
{ http_parser: '2.5.0',
node: '4.2.6',
v8: '4.5.103.35',
uv: '1.8.0',
zlib: '1.2.8',
ares: '1.10.1-DEV', …Run Code Online (Sandbox Code Playgroud) 我有一个flask-RESTful端点,定义为:
class SearchEvents(Resource):
def get(self, name, start_date, end_date):
#do stuff
api.add_resource(endpoints.SearchEvents, '/events/<string:name>/<string:start_date>/<string:end_date>')
Run Code Online (Sandbox Code Playgroud)
我正在用邮递员手动测试它。我想传递start_date和end_date的空值。然而:
http://127.0.0.1:5000/events/test/ / #<--Spaces
Run Code Online (Sandbox Code Playgroud)
和
http://127.0.0.1:5000/events/test/""/""
Run Code Online (Sandbox Code Playgroud)
无济于事。