Jump to content

Please help to understand dynamic link building class

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
sajee2004

sajee2004

    Newbie

  • Members
  • Pip
  • 2 posts
Dear all,
Im new to ASP.Net/c# programming..Im trying to develop ecommerce website and i cant understand some codes. Pls help to understand the codes given below.
thank you

if (!app.EndsWith("/")) app += "/"; //???????????????????

relativeUri = relativeUri.TrimStart('/'); //???????????????????

return HttpUtility.UrlPathEncode( String.Format("http://{0}:{1}{2}{3}", uri.Host, uri.Port, app, relativeUri)); //???????????????????

if (page == "1")
return BuildAbsolute(String.Format("Catalog.aspx?DepartmentID={0}", departmentId));
//???????????????????

#2
JKohnen

JKohnen

    Newbie

  • Members
  • Pip
  • 2 posts


/*

if the app string does not end with a / character append the / character to the end

Example: 

if app was

http://www.test.com 

app becomes 

http://www.test.com/ 

and if app was

http://www.test.com/ 

app stays 

http://www.test.com/

*/ 

if (!app.EndsWith("/")) app += "/"; 


/*

Remove all the / characters from the start of the relativeUri string

Example:

if relativeUri was

/////home.aspx

relativeUri becomes

home.aspx

and if relativeUri was

/home.aspx

relativeUri becomes

home.aspx

*/

relativeUri = relativeUri.TrimStart('/');


/*

This is a two parter:

First

String.Format creates a url

For example:

if app was /myApplication/ and relativeUril was home.aspx

(uri is probably the HttpRequest.Uri object assuming localhost)

The string.format statement would generate

http://localhost:80/myApplication/home.aspx


Second:

HttpUtility Encode the whole string to be save to pass as a query string in the url

the return value will probably be

http%3A%2F%2Flocalhost%3A80%2FmyApplication%2Fhome%2Easpx 

*/

return HttpUtility.UrlPathEncode( String.Format("http://{0}:{1}{2}{3}", uri.Host, uri.Port, app, relativeUri)); 


/*

If the string page variable is "1"

Build the Absolute path for string generated from string format

Absolute path tends to be the full URI path from the root of the website


Assuming the variable departmentId is 42

The output would most likely be:

/Catalog.aspx?DepartmentID=42

*/

if (page == "1")

return BuildAbsolute(String.Format("Catalog.aspx?Departme ntID={0}", departmentId)); 


// I hope that helps



#3
sajee2004

sajee2004

    Newbie

  • Members
  • Pip
  • 2 posts

JKohnen said:



/*

if the app string does not end with a / character append the / character to the end

Example: 

if app was

http://www.test.com 

app becomes 

http://www.test.com/ 

and if app was

http://www.test.com/ 

app stays 

http://www.test.com/

*/ 

if (!app.EndsWith("/")) app += "/"; 


/*

Remove all the / characters from the start of the relativeUri string

Example:

if relativeUri was

/////home.aspx

relativeUri becomes

home.aspx

and if relativeUri was

/home.aspx

relativeUri becomes

home.aspx

*/

relativeUri = relativeUri.TrimStart('/');


/*

This is a two parter:

First

String.Format creates a url

For example:

if app was /myApplication/ and relativeUril was home.aspx

(uri is probably the HttpRequest.Uri object assuming localhost)

The string.format statement would generate

http://localhost:80/myApplication/home.aspx


Second:

HttpUtility Encode the whole string to be save to pass as a query string in the url

the return value will probably be

http%3A%2F%2Flocalhost%3A80%2FmyApplication%2Fhome%2Easpx 

*/

return HttpUtility.UrlPathEncode( String.Format("http://{0}:{1}{2}{3}", uri.Host, uri.Port, app, relativeUri)); 


/*

If the string page variable is "1"

Build the Absolute path for string generated from string format

Absolute path tends to be the full URI path from the root of the website


Assuming the variable departmentId is 42

The output would most likely be:

/Catalog.aspx?DepartmentID=42

*/

if (page == "1")

return BuildAbsolute(String.Format("Catalog.aspx?Departme ntID={0}", departmentId)); 


// I hope that helps


Hi Dear Friend
Thank you so much for this grate explanation.. I really appriciate your effort and very understanding.
Thank you so much again. Im really sorry abt late reply,

Cheers
Sajee

#4
JKohnen

JKohnen

    Newbie

  • Members
  • Pip
  • 2 posts
My pleasure.

I'm glad I could help.

(My blog) My name is Justin Kohnen, and I’m a Geek.