views:

282

answers:

5

Hi,

I have a small web app being written in ASP.NET, VB.NET , .NET 3.5

I pass a value from default.aspx to demo.aspx using query string. When Go button is clicked the URL will be like this : localhost/demo.aspx?id=4

But I want URL to be sth like this when Go button is clicked : localhost/?id=4 and the id value is passed to demo.aspx so the expected result can be shown. How to get this done if possible without using the routing technique.

A: 

Something like this?

protected void btnGo_Click (Object sender, EventArgs e)
{
    Response.Redirect("localhost/?" + Request.QueryString);
}

Not sure when you want the url to change? Not sure what the routing technique is either. Sorry.

Joshua Belden
A: 

This might help.

danish
+2  A: 

This will work only if the web server considers demo.aspx to be the default document. When you load a page without stating the page name (such as you localhost/?id=4 example), the web server will locate a file with a pre-defined name and use it as the default document. Often this file is called default.aspx (or .asp, .htm, .html, .php or something like that). So if you want to load any other page you will need to either state the name, or use URL rewriting techniques.

Fredrik Mörk
In this case, it's not the same page. So I need to URL rewriting then.
Angkor Wat
A: 

if you want it to work with postbacks, you still need to make sure the webserver is configured with a default document like default.aspx.

in 3.5 sp1 MS finally allows us to set the action attribute of the form.

so on page init you can explicitly set it now

Form1.Action = "/mydirectory/"

Caveat: Some versions of IIS do not allow posting to a directory. (XP IIS for example)

Chad Grant
+1  A: 
  1. Modify your go button to link button and set herf = "?id=[id]"
  2. Modify Page_Load event of Default.aspx by using the following code.

public Page_Load(object sender,EventArg e) {

if(!string.IsNullOrEmpty(Request["id"]))
{
   // Using Server.Transfer() function to call Demo.aspx page.
   // Client still see "localhost/?id=[id]" at address bar.
   Server.Transfer("Demo.aspx?id=" + Request["id"]);
}

}

Soul_Master