[c#] 잘못된 URI : URI 형식을 확인할 수 없습니다.

이 오류가 계속 발생합니다.

잘못된 URI : URI 형식을 확인할 수 없습니다.

내가 가진 코드는 다음과 같습니다.

Uri uri = new Uri(slct.Text);
if (DeleteFileOnServer(uri))
{
    nn.BalloonTipText = slct.Text + " has been deleted.";
    nn.ShowBalloonTip(30);
}

업데이트 : slct.Text의 내용은 다음같습니다.ftp.jt-software.net/style.css .

무엇을 제공합니까? 유효한 URI 형식이 아닌 이유는 무엇입니까? 일반 텍스트입니다.



답변

Uri에 대해 다른 생성자를 사용하는 것이 도움이 될 수 있습니다.

서버 이름이있는 경우

string server = "http://www.myserver.com";

추가 할 상대 Uri 경로가 있습니다. 예 :

string relativePath = "sites/files/images/picture.png"

이 두 가지에서 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);


답변

가능한 이유를 확인하십시오 : http://msdn.microsoft.com/en-us/library/z6c2z492(v=VS.100).aspx

편집하다:

주소 앞에 프로토콜 접두사를 넣어야합니다. 즉, “ftp : //”의 경우


답변

실제 URI 인 것 같습니다. 크로스 브라우저 Silverlight를 수행 할 때이 문제가 발생했습니다. 내 블로그 에서 해결 방법을 언급했습니다. “context”uri를 첫 번째 매개 변수로 전달하는 것입니다.

uri가 현실적이면 컨텍스트 uri를 사용하여 전체 uri를 만듭니다. uri가 절대적이면 컨텍스트 uri가 무시됩니다.

편집 : “ftp : //”또는 “http : //”와 같이 uri에 “scheme”이 필요합니다.


답변

더 나은 사용 Uri.IsWellFormedUriString(string uriString, UriKind uriKind).http://msdn.microsoft.com/en-us/library/system.uri.iswellformeduristring.aspx

예 :-

 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);
        }
 }


답변

대신 UriBuilder 를 사용 하여이 문제해결 했습니다.

UriBuilder builder = new UriBuilder(slct.Text);

if (DeleteFileOnServer(builder.Uri))
{
   ...
}


답변

나에게 문제는 도메인 이름을 얻었을 때 다음과 같은 것입니다.

cloudsearch -..-..- xxx.aws.cloudsearch … [잘못된]

http : //cloudsearch-..-..-xxx.aws.cloudsearch[오른쪽]

이것이 당신을 위해 일하기를 바랍니다 🙂


답변