[英]Invalid URI: The format of the URI could not be determined
I keep getting this error.我不断收到此错误。
Invalid URI: The format of the URI could not be determined.
无效的 URI:无法确定 URI 的格式。
the code I have is:我的代码是:
Uri uri = new Uri(slct.Text);
if (DeleteFileOnServer(uri))
{
nn.BalloonTipText = slct.Text + " has been deleted.";
nn.ShowBalloonTip(30);
}
Update: the content in slct.Text is ftp.jt-software.net/style.css
.更新: slct.Text 中的内容是
ftp.jt-software.net/style.css
。
What gives?是什么赋予了? How is that not a valid URI format?
这怎么不是一个有效的 URI 格式? It's plain text.
是纯文本。
It may help to use a different constructor for Uri.为 Uri 使用不同的构造函数可能会有所帮助。
If you have the server name如果您有服务器名称
string server = "http://www.myserver.com";
and have a relative Uri path to append to it, eg并有一个相对的 Uri 路径来附加到它,例如
string relativePath = "sites/files/images/picture.png"
When creating a Uri from these two I get the "format could not be determined" exception unless I use the constructor with the UriKind argument, ie从这两个创建 Uri 时,除非我使用带有 UriKind 参数的构造函数,否则我会得到“无法确定格式”异常,即
// this works, because the protocol is included in the string
Uri serverUri = new Uri(server);
// needs UriKind arg, or UriFormatException is thrown
Uri relativeUri = new Uri(relativePath, UriKind.Relative);
// Uri(Uri, Uri) is the preferred constructor in this case
Uri fullUri = new Uri(serverUri, relativeUri);
Check possible reasons here:http://msdn.microsoft.com/en-us/library/z6c2z492(v=VS.100).aspx在此处检查可能的原因:http ://msdn.microsoft.com/en-us/library/z6c2z492(v=VS.100).aspx
EDIT:编辑:
You need to put the protocol prefix in front the address, ie in your case "ftp://"您需要将协议前缀放在地址前面,即在您的情况下为“ftp://”
Sounds like it might be a realative uri.听起来它可能是一个真实的 uri。 I ran into this problem when doing cross-browser Silverlight;
我在做跨浏览器 Silverlight 时遇到了这个问题; on my blog I mentioned a workaround: pass a "context" uri as the first parameter.
在我的博客上,我提到了一种解决方法:将“上下文”uri 作为第一个参数传递。
If the uri is realtive, the context uri is used to create a full uri.如果 uri 是真实的,则上下文 uri 用于创建完整的 uri。 If the uri is absolute, then the context uri is ignored.
如果 uri 是绝对的,则忽略上下文 uri。
EDIT: You need a "scheme" in the uri, eg, "ftp://" or "http://"编辑:您需要在 uri 中使用“方案”,例如“ftp://”或“http://”
Better use Uri.IsWellFormedUriString(string uriString, UriKind uriKind)
.更好地使用
Uri.IsWellFormedUriString(string uriString, UriKind uriKind)
。 http://msdn.microsoft.com/en-us/library/system.uri.iswellformeduristring.aspx http://msdn.microsoft.com/en-us/library/system.uri.iswellformeduristring.aspx
Example :-例子 :-
if(Uri.IsWellFormedUriString(slct.Text,UriKind.Absolute))
{
Uri uri = new Uri(slct.Text);
if (DeleteFileOnServer(uri))
{
nn.BalloonTipText = slct.Text + " has been deleted.";
nn.ShowBalloonTip(30);
}
}
I worked around this by using UriBuilder instead.我通过使用UriBuilder来解决这个问题。
UriBuilder builder = new UriBuilder(slct.Text);
if (DeleteFileOnServer(builder.Uri))
{
...
}
The issue for me was that when i got some domain name, i had:我的问题是,当我得到一些域名时,我有:
cloudsearch-..-..-xxx.aws.cloudsearch... [WRONG] cloudsearch-..-..-xxx.aws.cloudsearch... [错误]
http://cloudsearch-..-..-xxx.aws.cloudsearch ... [RIGHT] http://cloudsearch-..-..-xxx.aws.cloudsearch ... [右]
hope this does the job for you :)希望这对你有用:)
I was getting a debugging error like this while trying to set up Docker.我在尝试设置 Docker 时遇到了这样的调试错误。
I've set the docker setting in "launchSettings.json" as follows.我在“launchSettings.json”中设置了docker设置,如下所示。
Problem has solved.问题已经解决。
"Docker":
{
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/",
"publishAllPorts": false,
"useSSL": true
}
如果您为应用程序启用了 SwaggerDoc,请检查 xml 注释文件是否存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.