Pra*_*sad 6 asp.net-mvc query-string
我需要在我的asp.net mvc(C#)应用程序的所有页面中维护查询字符串.
例如:我会打电话给一个页面www.example.com?Preview=True.无论我点击哪个页面,都应该维护查询字符串www.example.com.即当我点击About us页面时www.example.com,网址应该是www.example.com/AboutUs?Preview=True
我怎样才能实现这一目标?什么是做这种常见手术的最佳场所.
来自@eu-ge-ne 的出色指导。
我使用了 @eu-ge-ne 的自定义路由的想法将路由值添加到每个 url,并使用基本控制器来处理会话中的预览键。
if ((requestContext.HttpContext.Request.QueryString != null &&
requestContext.HttpContext.Request.QueryString["Preview"] != null &&
requestContext.HttpContext.Request.QueryString["Preview"].ToString() =="True") ||
(requestContext.HttpContext.Request.UrlReferrer != null &&
requestContext.HttpContext.Request.UrlReferrer.ToString().Contains("Preview=True")))
{
//Add the preview key to session
}
else
{
//Remove the preview key to session
}
Run Code Online (Sandbox Code Playgroud)
Initialize我在基本控制器的方法中使用了上面的代码。这样,如果查询字符串具有预览,则预览键将在会话中,否则它将从会话中删除。
再次感谢@eu-ge-ne。
| 归档时间: |
|
| 查看次数: |
3814 次 |
| 最近记录: |