1

I want to hide the guts of my URL programmatically.
I know I can use:

Server.Transfer("url",boolean)

This is not what I want in this case. I would like to be able to manipulate the URL after I get the variables I need.

How would I do this in ASP.NET?


Edit:

My URL:

URL.aspx?st=S&scannum=481854

I want to change it when the page loads to just be URL.aspx? but I need to first get the st and scannum values.

Community
  • 1
  • 1
Eric
  • 7,930
  • 17
  • 96
  • 128
  • Hide the URL... from? The browser? Why isn't Server.Transfer what you want? A bit more info would probably help. – womp Aug 10 '09 at 17:06
  • What, precisely, do you need? What does the incoming URL look like, and what do you want to do with it? – John Fisher Aug 10 '09 at 17:07
  • ok. I edited it my question to be more clear – Eric Aug 10 '09 at 17:38
  • 3
    That's still not very clear. It seems like you're asking if there's a way to change the client-side URL to `URL.aspx` without the GET parameters even though the client sent the request with those parameters. *Nothing has this control*. It is impossible. If you don't want GET parameters to appear in the URL, use POST instead of GET, like Dav says. – Welbog Aug 10 '09 at 17:49

6 Answers6

5

Have you seen this article that covers Url Rewriting in ASP.NET?

I recommend checking out ASP.NET MVC as well. MVC stands for Model View Controller. This framework will use a "controller" to route the end user to "views" that display your data (your "model"). MVC does all the routing for you based on the URL.

Frinavale
  • 3,908
  • 10
  • 44
  • 74
  • 1
    You can use routing without MVC as well... if you are scared to get wet... http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx – BigBlondeViking Aug 11 '09 at 13:22
  • That's very true BigBlondViking :) That's why I posted the link to the article that covers URL Rewriting in ASP.NET first. I'm very excited about MVC though. It's an amazing framework that was long over due. The separation of the data (model) from the user interface (the view) lets you keep your code very organized and I am a big fan of clean code. It also lets you structure the URLs for your site, which not only makes it easier for your end user to use the site but also lets you change the location of your resources (models and views) because they aren't tightly linked to the url any more. – Frinavale Aug 11 '09 at 15:56
1

If you're passing in variables that you don't want displayed in the URL, why not use POST instead of GET?

Amber
  • 507,862
  • 82
  • 626
  • 550
  • Ok.. how exactly can i do that? i'm using response.redirect to set my url with variables. – Eric Aug 10 '09 at 18:02
1

You will have to provide more details on what your desired end result is. There are many options for manipulating the URL.

Using POST will allow you to transfer information between pages without littering your URL with extra values. Using encryption will not hide the extra parameters, but will make them unreadable. Using a URL Rewriter you can use regex to have the user enter one URL, but actually load another.

Jay S
  • 7,904
  • 2
  • 39
  • 52
0

I have answered a question similar to this in the past. I say similar, because I am not sure what exactly you are looking for, but I feel the need to post a link to the other question to see if it will help:

ASP.NET - Building your own routing system

Community
  • 1
  • 1
Dale Ragan
  • 18,202
  • 3
  • 54
  • 70
0

Look at ASP.NET Routing for new Apps. Have you tried HttpContext.RewritePath Method (String) Cross-Page Posting in ASP.NET Web Pages

moo
  • 11
  • 3
0

It's not possible to do what I want to do. I would want to change the appearance of my url in javascript without refreshing. If this was possible, hackers would rule the world.

Eric
  • 7,930
  • 17
  • 96
  • 128