简体   繁体   English

用另一个字符串正确替换一个字符串

[英]Correctly replacing a string with another string

I am work a site that was coded in c# and uses a ssl cert "secure.mydomain.com To switch from http to https it uses the following code 我正在使用c#编码并使用ssl证书“ secure.mydomain.com”的网站,要从http切换为https,请使用以下代码

       if (useSsl)
        {
            if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["SharedSSL"]))
            {
                //shared SSL
                result = ConfigurationManager.AppSettings["SharedSSL"];
            }
            else
            {
                //SSL
               **result = result.Replace("http:/", "https://");**
            }

This will switch from "http://mydoman.com" to "https://mydomain.com", but I need "https://secure.mydomin.com". 这将从“ http://mydoman.com”切换到“ https://mydomain.com”,但是我需要“ https://secure.mydomin.com”。 If I change the code to result = result.Replace("http:/", "https://secure"); 如果我将代码更改为result = result.Replace(“ http:/”,“ https:// secure”); it takes me to an error page because it is trying to go to "https://secure". 它将我带到错误页面,因为它正尝试转到“ https:// secure”。

I have been searching for 3 weeks to find a solution and tried so of them but none worked. 我一直在搜索3周以找到解决方案,并尝试了其中的一种,但均无效果。 Any suggestions on how to correct this? 关于如何纠正这一点的任何建议?

You have missed the extra forward slash on your http 您错过了http上多余的斜杠

result.Replace("http://", "https://secure.");

This will work for you hopefully 希望对您有用

As stated by soniic, you've missed a / . 正如soniic所说,您错过了/

This means your string will look like 这意味着您的字符串看起来像

https://secure/.mydomain.com

Thats why you're being redirected to https://secure instead of https://secure.mydomain.com 这就是为什么您被重定向到https://secure而不是https://secure.mydomain.com

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

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