开发者

String replace not working [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜