字符串替换不工作 [英] String replace not working

查看:105
本文介绍了字符串替换不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

    return uri;
}

如果我有一个URI这样的发送请求:

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

http://localhost/AppName/somepage.aspx

它不以https取代HTTP。

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

这篇关于字符串替换不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆