为原始URL添加了额外的查询字符串 [英] Appened extra querystring to raw url

查看:66
本文介绍了为原始URL添加了额外的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试将查询附加到原始网址,但是后来网址无法正常工作我想添加额外的内容以便使用&符号并试图追加。



 Response.Redirect(Request.RawUrl +& signoff = manager); 





但是

 Response.Redirect(Request.RawUrl +?amp; signoff = manager); 

这是有效的,但这并不是我的价值,因为我的原始网址上有几个querystrings可用,所以我必须使用&

解决方案

这就是我的方式这样做:



  var  asdiDataUri =  new  UriBuilder(_url); 

var query = HttpUtility.ParseQueryString(asdiDataUri.Query);

query.Add( user,_ user);
query.Add( datatype,_ datata);

asdiDataUri.Query = query.ToString();

WebRequest request = WebRequest.Create(asdiDataUri.ToString());





UriBuilder负责存在多个查询字符串或没有。



您可以获取网址部分并检查以确保没有#但我认为它也会处理它。我还没有测试那么多


Quote:

 Response.Redirect(Request.RawUrl +  & signoff = manager); 

如果你的RawUrl不包含?,这将不起作用。如果它包含,那么它将工作。



所以,你能做的是,首先检查RawUrl是否包含?或不。如果它包含,则添加其他字符串&,否则添加字符串?。



如果有疑问,请添加注释。


Hi ,

I am trying to append query to raw URL , but then url is not working i want to add extra so using & symbol and trying to append .

Response.Redirect(Request.RawUrl + "&signoff=manager");



but

Response.Redirect(Request.RawUrl + "?amp;signoff=manager");

this is working but this is not not givin me value as there are alredy few querystrings are available on my raw url so i must use &

解决方案

This is how I do it:

 var asdiDataUri = new UriBuilder(_url);

var query = HttpUtility.ParseQueryString(asdiDataUri.Query);

query.Add("user", _user);
query.Add("datatype", _dataType);

asdiDataUri.Query = query.ToString();

WebRequest request = WebRequest.Create(asdiDataUri.ToString());



The UriBuilder takes care of multiple querystring existing or none.

You can get the url part and check to ensure there is no # but I think it would handle that too. I haven't tested that much as of yet


Quote:

Response.Redirect(Request.RawUrl + "&signoff=manager");

This won't work if your RawUrl does not contain a "?". If it contains, then it will work.

So, what you can do is, first check if RawUrl contains "?" or not. If it contains, then add other string with "&", else add string with "?".

If there are doubts, add a comment.


这篇关于为原始URL添加了额外的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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