Note that there are some explanatory texts on larger screens.

plurals
  1. POString that came from Request.Url.ToString() misteriously changes to another string when manipulating/comparing the first characters
    primarykey
    data
    text
    <p>I'm aware that there are easier ways to do this and believe me, I've tried them. I'm of course open to any suggestions =). You don't need to read the whole code, just the part that says where the problem lies. Also, I'm debbugging perl style so you guys can see. Oh and did I mention that on my development environment everything works as intended?</p> <p>Here's the code:</p> <pre><code>string GetPortalAlias() { String myURL2 = Request.Url.ToString(); URLLabel.Text = "Original Request.Url.ToString() returned: \"" + myURL2 + "\""; string myURL = string.Copy(myURL2); URLLabel.Text = "Copying it to myURL, it's now: \"" + myURL + "\""; myURL = myURL.ToLower().Trim(); URLLabel.Text += "&lt;br&gt;Trimming and ToLower myURL.&lt;br&gt;The new url is \"" + myURL + "\"" + "&lt;br&gt;"; myURL = myURL.Replace(":80", ""); URLLabel.Text += "Replacing the \":80\".&lt;br&gt; The new url is\"" + myURL + "\"&lt;br&gt;"; //***HERE LIES THE PROBLEM*** myURL = myURL.Replace("http://", ""); URLLabel.Text += "Replacing the \"http://\".&lt;br&gt; The new url is\"" + myURL + "\"&lt;br&gt;"; //***PROBLEM ENDS*** myURL = myURL.Remove(myURL.IndexOf("/")); URLLabel.Text += "Removing everything after the \"/\"." + "&lt;br&gt; The new url is \"" + myURL + "\"&lt;br&gt;"; URLLabel.Text += "&lt;br&gt;GetPortalAlias Returning \"" + myURL + "\""; return myURL; } </code></pre> <p>Believe it or not, the output produced in the webpage is this:</p> <p><img src="https://i.stack.imgur.com/OpptW.png" alt="output"></p> <pre>Copying it to myURL, it's now: "http://sar.smg.com.ar/Default.aspx?TabID=912" Trimming and ToLower myURL. The new url is "http://sar.smg.com.ar/default.aspx?tabid=912" Replacing the ":80". The new url is"http://sar.smg.com.ar/default.aspx?tabid=912" Replacing the "http://". The new url is"intranetqa/default.aspx?tabid=912" Removing everything after the "/". The new url is "intranetqa" GetPortalAlias Returning "intranetqa" </pre> <p>So... for some reason whenever it reaches the replace section it mysteriously mutates to start with "intranetqa" instead of "sar.smg.com.ar". "intranetqa" is our default hostname. <strong>CHANGING OR TAKING AWAY ANY CHARACTER OF HTTP:// IN ANY WAY MUTATES THE STRING.</strong></p> <p>I do a <code>string.copy</code> because I'm aware that if two strings are equal the compiler stores them in the same place therefore I wanted to prevent errors. Taking those lines away and use <code>Request.Url.ToString()</code> to<code>myURL</code> directly does nothing at all. They were just a test to see if that worked.</p> <p>Here's a list of the things I've tried:</p> <ul> <li>All combinations of <code>string</code> / <code>String</code>, none worked.</li> <li>I've tried <code>Request.Host.Url</code> and it just gave me "intranetqa".</li> <li>I've used <code>Request.Url.AbsoluteUri</code> and that's why I have the replace :80 line.</li> <li>USING THE <code>.tochararray</code> FUNCTION GIVES ME BACK THE INTRANETQA THING</li> <li>myURL = myURL.Substring(6) gives back the intranetqa thing.</li> <li>string.Contains("sar.smg.com.ar") gives back false.</li> </ul> <p><strong>I believe the trick lies around here</strong>:</p> <ul> <li><code>Uri uriAddress1 = Request.Url;</code> and <code>"The parts are &lt;br&gt;" + "Part 1: " + uriAddress1.Segments[0] + "&lt;br&gt;Part 2: " + uriAddress1.Segments[1];</code> Gives Part1 : "/" and Part 2: "Default.aspx". Trying to access part 3 (index 2) gives an exception. The request.url does not have the first part, but when I call the ToString() method, it does have like a "fake" first part</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload