在ASP.NET 2.0 WebForms中使用UrlRewrite时,为了优雅地处理ReturnUrl,可以采用以下方法:
以下是一个示例代码:
<system.webServer>
<rewrite>
<rules>
<rule name="UrlRewrite" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{QUERY_STRING}" pattern="ReturnUrl=(.*)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
HttpRequest request = context.Request;
if (request.QueryString["ReturnUrl"] != null)
{
context.Session["ReturnUrl"] = request.QueryString["ReturnUrl"];
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["ReturnUrl"] != null)
{
Response.Redirect(Session["ReturnUrl"].ToString(), false);
Session.Remove("ReturnUrl");
}
}
通过这种方法,可以在ASP.NET 2.0 WebForms中使用UrlRewrite时优雅地处理ReturnUrl参数。
领取专属 10元无门槛券
手把手带您无忧上云