我网站上的所有用户都有公开的个人资料页面。我使用的URL重写从形式http://mysite.com/profile.aspx?id=sdsdfsdsdfsdfdsdffsdfsdf
更改网址为http://mysite.com/Username
像这样(我在Global.asax文件):获取重写请求的URL?
static Regex _handleRegex1 = new Regex("/(?<hndl>[\\w]+)/?$", RegexOptions.Compiled);
void Application_BeginRequest(object sender, EventArgs e)
{
System.Text.RegularExpressions.Match handleMatch = _handleRegex1.Match(Request.Url.LocalPath);
if(handleMatch.Success){
String handle = handleMatch.Groups[1].Value;
using (SqlQuery query = new SqlQuery("[dbo].[sp_getUserIdByHandle]"))
{
try
{
query.AddParameter("@handle", handle, System.Data.SqlDbType.NVarChar, false);
query.AddParameter("@userId", new Guid(), System.Data.SqlDbType.UniqueIdentifier, true);
query.ExecuteNonQuery();
Object userId = query.GetOutParameter("@userId");
if (userId == DBNull.Value)
{
Response.Redirect("~/default.aspx");
}
else
{
Context.RewritePath(string.Format("~/profile.aspx?id={0}&{1}", userId, Request.QueryString));
}
}
catch (Exception ex)
{
}
}
}
}
这工作得很好。但是,如果我回发到服务器,则URL从/username
变为/profile?id=5ab47aa3-3b4d-4de6-85df-67527c9cdb52&
,我想从用户隐藏。
我想过要做点像Response.Redirect(Request.RawUrl);
这样的事情,让用户回到正确的页面。但是,Request
似乎没有包含有关所需URL的任何信息。
有什么方法可以找到预先重写的网址吗?
仍然工作在服务器2003/IIS6,很遗憾。 – Oliver
文章中的某些建议和链接页面可能仍然可以用于IIS 6 –