简体   繁体   English

ASP.NET如果根URL包含查询字符串,则在重定向时将其传递给default.aspx

[英]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; 有什么办法可以保存查询字符串并将其传递给default.aspx; For example: 例如:

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

becomes

http://www.example.com/Default.aspx?test=123 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 您可以使用Request.QueryString["test"]从查询字符串中获取值,并使用它将其传递给其他页面

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

Do this in Session_Start method of Global.asax.cs 在Global.asax.cs的Session_Start方法中执行此操作

Or if you want to pass the entire query string instead of one value just use Request.QueryString.ToString() 或者,如果要传递整个查询字符串而不是一个值,只需使用Request.QueryString.ToString()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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