user3222589
user3222589

Reputation: 184

How to build url to pass variables in c#

When I try to pass parameters in url I used GET to do so, but I noticed that facebook and some other sites passing variables by building url in different way like this "facebook.com/user1". I think "user1" is passed and there is no real directory named "user1" in facebook.com base directory.

how to use "mysite.com/user1" instead of "mysite.com/?user=user1" to maintain user id, without creating a directory named "user1" in base directory?

Programming language: C#. IIS version: 7.5

Thanks in advance.

Upvotes: 0

Views: 255

Answers (2)

Siva Charan
Siva Charan

Reputation: 18064

You can generate the URL as below

Request.Url.GetLeftPart(UriPartial.Path) + "?user=" + USERID

Upvotes: 0

user3221822
user3221822

Reputation:

Two ways:

1) Use ASP.NET MVC by using your own Route. For more about ASP.NET MVC, you can refer this:

However I suggest you starting from beginning for the 2nd link.

2) If you are using a general ASP.NET WebForm, Please use UrL-ReWriter. another good torturial at:http://www.tutorialized.com/tutorial/URL-Rewriting-in-ASP.NET-using-URLRewriter.Net/38861

Upvotes: 1

Related Questions