Getting URL of rewritten request?
<p>All the users on my site have public-facing profile pages. I am using URL rewriting to change urls from the form <code>http://mysite.com/profile.aspx?id=sdsdfsdsdfsdfdsdffsdfsdf</code> into <code>http://mysite.com/Username</code> like this (in my global.asax file):</p>

<pre><code>static Regex _handleRegex1 = new Regex("/(?&lt;hndl&gt;[\\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}&amp;{1}", userId, Request.QueryString));
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}
</code></pre>

<p>This works fine. However, if I do a postback to the server, the URL changes from something like <code>/username</code> to the form <code>/profile?id=5ab47aa3-3b4d-4de6-85df-67527c9cdb52&amp;</code>, which I want to hide from the user. </p>

<p>I thought about doing something like <code>Response.Redirect(Request.RawUrl);</code> to sent the user back to the right page. However, <code>Request</code> doesn't seem to contain any information about the desired URL.</p>

<p>Is there any way to find the pre-rewritten URL?</p>
