简体   繁体   English

无效的URI:URI方案在aspx中无效

[英]Invalid URI: The URI scheme is not valid in aspx

When i hardcode the url in the code it works. 当我在代码中对网址进行硬编码时,它将起作用。 I am trying to get the hostname and append the request. 我正在尝试获取主机名并追加请求。 It gives this error, 它给出了这个错误,

Invalid URI : The URI scheme is not valid. 无效的 URI :URI方案无效。

Description : An unhandled exception occurred during the execution of the current web request. 描述 :在执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。

Exception Details: System.UriFormatException: Invalid URI: The URI scheme is not valid.
Source Error: 
Line 44:         string request = url.Scheme + "//" + url.Host + ":" + url.Port +"/accounts1/asp2netbridge.asp?sessVar=";
Line 45:       
Line 46:         HttpWebRequest _myRequest = (HttpWebRequest)WebRequest.Create(new Uri(request + sessionValue));
Line 47:         _myRequest.ContentType = "text/html";
Line 48:         _myRequest.Credentials = CredentialCache.DefaultCredentials;

Here is the code: 这是代码:

  Uri url = HttpContext.Current.Request.Url;
  string request = url.Scheme + "//" + url.Host + ":" + url.Port +"/accounts1/asp2netbridge.asp?sessVar=";      
  HttpWebRequest _myRequest = (HttpWebRequest)WebRequest.Create(new Uri(request + sessionValue));

Add ":" before "//" 在“ //”之前添加“:”

string request = url.Scheme + "://" + url.Host + ":" + url.Port +"/accounts1/asp2netbridge.asp?sessVar="; 字符串请求= url.Scheme +“://” + url.Host +“:” + url.Port +“ / accounts1 / asp2netbridge.asp?sessVar =”;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM