Kobarin's Development Blog

C#やASP.NETなどについての記録です。

ASP.NETで、URLrewriteされたページでPostBackしてもURLを変えない方法

ページロード時にFormのActionを書き換えるらしい。
元の(Rewriteされた)URLを保存しているServerVariableを使う。

protected void Page_Load(object sender, EventArgs e)
{
    if ( !String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_ORIGINAL_URL"]) )
    {
        form1.Action = Request.ServerVariables["HTTP_X_ORIGINAL_URL"];
    }
}