简体   繁体   中英

ASP.NET if root URL contains query string, pass it to default.aspx on redirect

Is there any way that I can preserve a query string and pass it to the default.aspx; For example:

http://www.example.com/?test=123

becomes

http://www.example.com/Default.aspx?test=123

Thanks in advance!

Yes you can. You could use Request.QueryString["test"] to get the value from query string and pass it to the other page using

if(Request.QueryString["test"] != null)
{
      Response.Redirect("~/Default.aspx?test=" + Request.QueryString["test"].ToString())
}

Do this in Session_Start method of Global.asax.cs

Or if you want to pass the entire query string instead of one value just use Request.QueryString.ToString()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM