?
Solved

encode url string C#

Posted on 2011-10-20
5
Medium Priority
?
427 Views
Last Modified: 2012-06-22
How do i use Server.UrlEncode to firstly remove a '~' and add additional text to the URL? using C#
0
Comment
Question by:Pixie_IT
5 Comments
 
LVL 9

Expert Comment

by:sachinpatil10d
ID: 36999440
not clear about you question
some thing like this would work
String MyURL;
MyURL = "http://www.Testsite.com/testPage.aspx?title=" + Server.UrlEncode("samples~".Replace("~", "additional text"));

Response.Write("<a href=" + MyURL + "> samples </a>");

Open in new window

0
 

Expert Comment

by:johnchapmansc
ID: 36999591
String MyURL;
MyURL = "http://www.contoso.com/articles.aspx?title=" + Server.UrlEncode("ASP.NET Examples");

Response.Write("<a href=" + MyURL + "> ASP.NET Examples </a>");
0
 
LVL 14

Expert Comment

by:nishant joshi
ID: 36999986
string url=System.Web.HttpUtility.UrlDecode("http:\\www.google.com") + "Append something something";
0
 

Accepted Solution

by:
Pixie_IT earned 0 total points
ID: 37079134
The answer we were looking for we eventually found and was:
//Getting the current context of HTTP request
        var context = HttpContext.Current;

        //Checking the current context content
        if (context == null) return null;

        //Formatting the fully qualified website url/name
        var appPath = string.Format("{0}://{1}{2}{3}",
                                    context.Request.Url.Scheme,
                                    context.Request.Url.Host,
                                    context.Request.Url.Port == 80
                                        ? string.Empty
                                        : ":" + context.Request.Url.Port,
                                    context.Request.ApplicationPath);
0
 

Author Closing Comment

by:Pixie_IT
ID: 37098946
Unfortunately the wording of the question may have resulted in not gettign the answer we required.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question