我正在为所有的web项目编写一个通用库。其中之一的函数是永久重定向,如下所示:
public static void PermanentRedirect(string url, HttpResponse response, bool endResponse)
{
url = //resolve url here. how?
response.Status = "301 Moved Permanently";
response.AddHeader("Location", url);
if (endResponse) response.End();
}
如何在不传递当前页面以获取访问Page.ResolveUrl
的权限的情况下解析URL?请注意,我可以更改方法签名,但我希望不这样做,因为我认为它会过度负担API。
我有一些重载,所以我的期望用法是:
WebUtility.PermanentRedirect("~/somewhere/somepage.aspx")
new Uri(string uriString, bool dontEscape)
?那已经过时了,我不确定其他的是否适用。 - Jeff