Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi folks, I need to remove https from my embedded link.

At the moment the link is created like this:

https://tyrescanner.net/pages/Activation.aspx


Which does not work I need the link to be like this:

tyrescanner.net/pages/Activation.aspx


My code so far:
XML
<a href = '" + VirtualPathUtility.ToAbsolute("//tyrescanner.net/pages/Activation.aspx") + "?ActivationCode=" + ActivationCode + "'>Click here to activate your account.</a>";
Posted
Updated 28-Jun-15 6:04am
v2
Comments
Sergey Alexandrovich Kryukov 28-Jun-15 10:54am    
First of all, why?
—SA

You should better use System.Uri class. Create an instance with string parameter representing your URI, which will parse the string into URI components, such as Scheme, Host, and so on:
https://msdn.microsoft.com/en-us/library/system.uri%28v=vs.110%29.aspx[^].

For understanding the components of URI, please see:
https://en.wikipedia.org/wiki/URI_scheme[^],
https://msdn.microsoft.com/en-us/library/system.uri%28v=vs.110%29.aspx[^].

This is the example of parsing it: https://en.wikipedia.org/wiki/URI_scheme#Examples[^].

This way, you can remove or replace some fragment, such as scheme name "https", but it would be much better if you think how to avoid using strings representing data instead of data itself.

—SA
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 28-Jun-15 11:15am    
Ah, I forgot this one, it would remove the need of protocol itself. Upvoted.
Sergey Alexandrovich Kryukov 28-Jun-15 11:16am    
Thank you, Afzaal.
By the way, this part, "https" is called "scheme name". It has the same name as protocol, in low case, but the name in general case does not have to be the name of a protocol.
For example, there is not "mailto" protocol, but there is such a URI scheme name: https://tools.ietf.org/html/rfc2368.
—SA
Afzaal Ahmad Zeeshan 28-Jun-15 11:37am    
Thank you for correcting me. :)
Remove it by replacing it with an empty string,

C#
string url = "<https://example.net/...>";
string urlToUse = url.Replace("https://", ""); // empty string


urlToUse would now have the URL that you want to use.
 
Share this answer
 
v2
Comments
Afzaal Ahmad Zeeshan 28-Jun-15 10:42am    
You are not going to embed anything in your code, instead you are going to update the code. Like this,


body += string.Format("<a href='{0}'>Click here to activate your account</a>", url.Replace("https://", ""));


This would return the hyperlink with the text, without HTTPS protocol in the beginning.
Sergey Alexandrovich Kryukov 28-Jun-15 10:56am    
This is just string manipulation, which will of course work. But it's better to use System.Uri where everything is done.
Please see Solution 4.
—SA
HTML
<a href = 'http:/" + VirtualPathUtility.ToAbsolute("//tyrescanner.net/pages/Activation.aspx") + "?ActivationCode=" + ActivationCode + "'>Click here to activate your account.</a>";


However ToAbsolute is not supposed to include a domain name, so you should ToAbsolute the "/pages/Activation.aspx" then add the http://domain at the start.
 
Share this answer
 
v2
Hi Afzaal Ahmad Zeesha,do you mean like this?


body += string.Format("Click here to activate your account", url.Replace("https://", "tyrescanner.net/pages/Activation.aspx""));
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 28-Jun-15 11:14am    
No, remove the tyrescanner thing. Then try again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900