URL编码周期? [英] Url Encode Periods?

查看:132
本文介绍了URL编码周期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要URL编码某些时期,因为我必须要通过一些文档路径沿着它是这样的。

I need to URL encode some periods since I have to pass some document path along and it is like this

http://example.com/test.aspx?document=test.docx

所以test.docx造成我一个非法字符的错误。所以,我需要将其更改为

So test.docx is causing me an error of an illegal character. So I need to change it to

.  -->  %2E



我试图用Server.UrlEncode

I tried to use Server.UrlEncode

  string b = Server.UrlEncode("http://example.com/test.aspx?document=test.docx");



但我得到

but I get

"http%3a%2f%2fexample.com%2ftest.aspx%3fdocument%3dtest.docx"

所以,我必须使用像一个字符串替换和做手工和替换与该代码?

So do I have to use like a string replace and do it manually and replace all periods with that code?

推荐答案

期间没有他的问题(假设%2E没有解决不了的问题)。一个时期是一个完全有效的URL字符无论问题是它不是时期。检查错误被抛出的堆栈跟踪或发布完整的错误的详细信息。

The period there isn't he problem (given that %2E doesn't solve the problem). A period is a perfectly valid URL character whatever the problem is it's not the period. Check the stack trace of the error being throw or post the complete error details.

和你不应该URL编码的完整路径。只有查询字符串参数的

And you shouldn't be URL encoding the entire path. Only the query string parameter value.

string b = "http://example.com/test.aspx?document=" + Server.UrlEncode("test.docx");

您仍然得到错误,如果你尝试这种方式?

Are you still getting the error if you try it that way?

我不会一个10英尺极触摸的SharePoint。然而,逃逸期间不一定会从这样做的把戏停止的SharePoint。但我猜你至少应该尝试一下。

I wouldn't touch SharePoint with a ten foot pole. However, escaping the period wouldn't necessarily stop SharePoint from doing it's shenanigans. But I guess you should at least try it.

Server.UrlEncode("test.docx").Replace(".", "%2E");

这篇关于URL编码周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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