ASP.NET:URI处理
发布时间:2020-12-16 07:36:32 所属栏目:asp.Net 来源:网络整理
导读:我正在写一个方法,比方说,1,你好,应该返回http://something.com/?something=1u0026amp;hello=en. 我可以很容易地将它们组合在一起,但ASP.NET 3.5为构建URI提供了哪些抽象功能?我喜欢这样的东西: URI uri = new URI("~/Hello.aspx"); // E.g. ResolveUrl i
我正在写一个方法,比方说,1,你好,应该返回http://something.com/?something=1u0026amp;hello=en.
我可以很容易地将它们组合在一起,但ASP.NET 3.5为构建URI提供了哪些抽象功能?我喜欢这样的东西: URI uri = new URI("~/Hello.aspx"); // E.g. ResolveUrl is used here uri.QueryString.Set("something","1"); uri.QueryString.Set("hello","en"); return uri.ToString(); // /Hello.aspx?something=1&hello=en 我发现Uri类听起来非常相关,但我找不到任何真正完成上述操作的内容.有任何想法吗? (对于它的价值,参数的顺序对我来说无关紧要.) 解决方法
编辑纠正大量错误的代码
基于this answer到类似的问题,您可以轻松地执行以下操作: UriBuilder ub = new UriBuilder(); // You might want to take more care here,and set the host,scheme and port too ub.Path = ResolveUrl("~/hello.aspx"); // Assumes we're on a page or control. // Using var gets around internal nature of HttpValueCollection var coll = HttpUtility.ParseQueryString(string.Empty); coll["something"] = "1"; coll["hello"] = "en"; ub.Query = coll.ToString(); return ub.ToString(); // This returned the following on the VS development server: // http://localhost/Hello.aspx?something=1&hello=en 这也将对集合进行urlencode,因此: coll["Something"] = "1"; coll["hello"] = "en&that"; 将输出: Something=1&hello=en%26that (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Asp.Net MVC路由表和控制器操作
- asp.net-mvc-3 – 在Razor / MVC3中使用@ Html.ActionLink获
- asp.net – applicationSettings和Web.config
- asp.net – 如何替换默认的Azure 403错误页面
- asp.net操作xml增删改示例分享
- asp.net – K运行时使用的.Net完整框架和.Net Core Framewo
- asp.net – 检查是否存在Web服务
- asp.net – 需要一个Web表单示例编辑带子项的父实体对象
- asp.net – 加速自动完成的Web服务并避免过多的方法调用
- 如果设备在asp.net web form app中移动,则更改母版页
推荐文章
站长推荐
- asp.net – 如何检查IIS是否在32位或64位模式
- ASP.NET web.config:system.web.compilation中的
- asp.net-mvc-3 – Global.asax.cs在服务器上不可
- ASP.NET自定义404和500错误页面
- reactjs – TypeError:无法读取undefined的属性
- 深蓝词库转换1.5发布
- asp.net – ASP计数器 – 不同计数器“桶”中类似
- 在asp.net mvc中的RedirectToAction用法
- 为什么只读文本框不会在ASP.NET中返回任何数据?
- asp.net-mvc-3 – 如何正确使用RedirectToAction
热点阅读