0

I'm working on a company website that allows users to have their own homepage under the same domain. The URL would look similar to http://mydomain.com/UserName We have each user's content saved in a database which gets displayed on a page be located in http://mydomain.com/users/default.aspx (it grabs the user's content by looking up the URL in the database)

I want the URL to stay the same in the address bar so it looks like each user has their own folder.

I've tried using Server.Transfer but my session variables end up being nothing. RewritePath works but the URL in the address bar changes. I can't do the code in a 404 page because the address bar will show 404.aspx?aspxerrorpath={requestedURL}

My main goal is to redirect and not to lose what's in the address bar. I'm using ASP.NET (if aspx extension didn't give it away LOL)

Mark Hurd
  • 10,665
  • 10
  • 68
  • 101
Spidergirl
  • 23
  • 7
  • 2
    You want *what* url to stay the same as *what other* url? I'm not clear what you are really wanting here. – Andrew Barber Dec 01 '11 at 00:10
  • If the user types in http://mydomain.com/UserName I want that to persist in the address bar but the back end redirect to another page and grab the user's content, making it look like each user has a folder under that domain. – Spidergirl Dec 01 '11 at 14:50
  • See the answer by Ruzzie; what you want is Routing or URL Rewriting. Forget all about `Server.Transfer`. With Routing, you can define patterns for routes that will call a specific page automatically and transparently for URLs that meet certain patterns... like anything with www.mydomain.com/Users/AndrewBarber goes to www.mydomain.com/UserPage.aspx?username=AndrewBarber behind the scenes, without changing the URL, with anything replacing the username you want. – Andrew Barber Dec 01 '11 at 14:55

3 Answers3

2

You could use Routing or Rewriting to map the user url to your asp script. This way different url's can go the the same aspx script.

Rewriting http://www.helicontech.com/isapi_rewrite/doc/RewriteRule.htm

animuson
  • 53,861
  • 28
  • 137
  • 147
Ruzzie
  • 124
  • 4
  • I did a google search on the subject and found this tutorial: http://blogs.msdn.com/b/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx After doing the demo, I used the concept for the company site and it worked flawlessly. Thanks for pointing me in the right direction! – Spidergirl Dec 01 '11 at 16:30
  • I was goinng to mention that like I did here (http://stackoverflow.com/questions/6449973/encoding-urls-c-sharp/6449988#6449988) - but SpiderGirl 3 pts I thought she was a newbie – Jeremy Thompson Dec 01 '11 at 23:07
0

You can't exactly do that. The URL is what users rely on recognizing the server. But you can show that content on the same page. You can use a fullscreen iframe and load the content in it and show it to the user and it's pretty easy to implement.

EDIT: Note that you don't even need an iframe. If you want to show some other page in your website, you can download its content and output it. (You need some changes though). But the more simple method is to use an iframe.

Alireza Noori
  • 14,961
  • 30
  • 95
  • 179
  • An iFrame - ewwwww. http://stackoverflow.com/questions/362730/are-iframes-considered-bad-practice – Jeremy Thompson Dec 01 '11 at 03:49
  • I didn't say that iFrame is a good solution, I mentioned an alternate solution, saying that iFrame is the easy path to follow. Although sometimes, in some rare cases, iFrame is the **ONLY** path to follow. Like some people, I don't think about things in a *black and white* manner. – Alireza Noori Dec 01 '11 at 04:22
0

You can achieve what you want by having a Server.Execute in the default.aspx, eg:

<%Server.Execute("path to another aspx page you wish to display inline while keeping the URL in tact")%>
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Server.Execute is the second option that I presented with the limitation of requiring a virtual path (which in this case is not introducing any restriction) but using it will introduce some *problems*. For instance if you have any relative paths in the `` tags, it won't fix them, leaving you with some broken links. – Alireza Noori Dec 01 '11 at 04:28
  • ok, your forgiven for being colorful and recommending a iFrame (hehe). With the relative links flaw you raised, the point of the question is to redirect to the same page changing content without changing the URL and in order to do that the links would need to be changed anyway:) – Jeremy Thompson Dec 01 '11 at 05:36
  • :p Yes, if he wants to use a server-side conversion as we both said, he should convert the URLs. But using and iFrame, won't need any of this. That why I said it's the easy way. Like I said, I don't say that iFrame is the best solution but it's the most simple one. Don't you agree? – Alireza Noori Dec 01 '11 at 10:32