开发者

String replace not working [duplicate]

开发者 https://www.devze.com 2022-12-08 03:17 出处:网络
This question already has answers here: string.Replace (or other string modification) not working (4 answers)
This question already has answers here: string.Replace (or other string modification) not working (4 answers) 开发者_StackOverflow中文版 Closed 7 years ago.
public static string ChangeUriToHttps(HttpRequest request)
{
    string uri = request.Url.AbsoluteUri;

    if (!IsRequestSecure(request))
        uri.Replace("http", "https");

    return uri;
}

If I send in a request that has a uri like this:

http://localhost/AppName/somepage.aspx

it doesn't replace the http with https.


common mistake. Strings are immutable. This means the original object can't be modified.

 public static string ChangeUriToHttps(HttpRequest request)
 {
      string uri = request.Url.AbsoluteUri;

      if (!IsRequestSecure(request))
          uri = uri.Replace("http", "https");

      return uri;
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消