Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String replace not working [duplicate]

Tags:

c#

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.

like image 559
PositiveGuy Avatar asked Dec 04 '22 14:12

PositiveGuy


1 Answers

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;
 }
like image 124
Ryan Alford Avatar answered Dec 26 '22 17:12

Ryan Alford