Я нашел этот замечательный маленький HttpModule, который шифрует и расшифровывает все строки запроса. Его можно найти здесь: HttpModule для шифрования строки запроса
Есть один серьезный недостаток, который я действительно мог бы использовать для решения. При обратной передаче страницы POST HttpMethod пропускается, а QueryString отображается в расшифрованном виде. Очевидно, это серьезная угроза безопасности.
void context_BeginRequest(object sender, EventArgs e)
{
try
{
HttpContext context = HttpContext.Current;
if (context.Request.Url.OriginalString.Contains("aspx") && context.Request.RawUrl.Contains("?"))
{
string query = ExtractQuery(context.Request.RawUrl);
string path = GetVirtualPath();
if (query.StartsWith(PARAMETER_NAME, StringComparison.OrdinalIgnoreCase))
{
// Decrypts the query string and rewrites the path.
string rawQuery = query.Replace(PARAMETER_NAME, string.Empty);
string decryptedQuery = Decrypt(rawQuery);
context.RewritePath(path, string.Empty, decryptedQuery);
}
else if (context.Request.HttpMethod == "GET")
{
// Encrypt the query string and redirects to the encrypted URL.
// Remove if you don't want all query strings to be encrypted automatically.
string encryptedQuery = Encrypt(query);
context.Response.Redirect(path + encryptedQuery);
}
}
}
catch (ThreadAbortException)
{
//do nothing. let it pass
}
catch (Exception exc)
{
ReportError(exc);
}
}
Я пробовал добавить добавление if catch для метода POST:
else if (context.Request.HttpMethod == "POST")
{
if (!query.StartsWith(PARAMETER_NAME, StringComparison.OrdinalIgnoreCase))
{
string encryptedQuery = Encrypt(query);
context.Response.Redirect(path + encryptedQuery);
}
}
Однако это перезагружает страницу из-за Response.Redirect, и поэтому PostBack бесполезен.
Есть ли у кого-нибудь идеи или есть ли способ определить, является ли HttpContext PostBack?