我有一个链接,它看起来像这样:http://www.example/about/49
。
我希望它看起来像http://www.example/about/
,但是我必须将这些参数作为QueryString
参数传递。
这是否可能?
我有一个链接,它看起来像这样:http://www.example/about/49
。
我希望它看起来像http://www.example/about/
,但是我必须将这些参数作为QueryString
参数传递。
这是否可能?
我的解决方法(得益于SO社区的帮助,非常有效)
创建一个名为SiteSession.cs
的类
输入以下代码:
using System;
using System.Collections.Generic;
using System.Web;
/// <summary>
/// Summary description for SiteSession
/// </summary>
public class SiteSession
{
/// <summary>
/// The _site session
/// </summary>
private const string _siteSession = "__SiteSession__";
/// <summary>
/// Prevents a default instance of the <see cref="SiteSession" /> class from being created.
/// </summary>
private SiteSession()
{
}
/// <summary>
/// Gets the current Session
/// </summary>
/// <value>The current.</value>
public static SiteSession Current
{
get
{
SiteSession session = new SiteSession();
try
{
session = HttpContext.Current.Session[_siteSession] as SiteSession;
}
catch(NullReferenceException asp)
{
}
if (session == null)
{
session = new SiteSession();
HttpContext.Current.Session[_siteSession] = session;
}
return session;
}
}
//Session properties
public int PageNumber {get;set;}
}
您可以将任何内容放入Session Properties
中,只需确保其为公共的。
然后,通过以下方式进行设置:
SiteSession.Current.PageNumber = 42
并使用以下方式调用:
int whatever = SiteSession.Current.PageNumber
QueryString
或URL输入中的任何其他内容,这违反了客户端浏览器规则。唯一可以隐藏的是在网页中。如果您真的不想使用会话,则会很困难。 - TheGeekZn