如何从asp.net中的任何内部页面重定向到根目录中的页面

时间:2014-01-15 07:38:27

标签: c# asp.net vb.net

如果我的页面位于

http://hostname.com/website_folder/page1.aspx

从内部文件夹中的页面,我想重定向到上面的页面 例如,从这些页面:

http://hostname.com/website_folder/folder1/folder2/page2.aspx

http://hostname.com/website_folder/folder1/folder2/folder3/page2.aspx

2 个答案:

答案 0 :(得分:0)

尝试使用Response.Redirect(您的网址);在你的代码页面后面。
如果您想了解更多信息,请阅读http://support.microsoft.com/kb/307903

答案 1 :(得分:0)

我假设每当请求来自以下网址时

http://hostname.com/website_folder/folder1/folder2/page2.aspx http://hostname.com/website_folder/folder1/folder2/folder3/page2.aspx

您想要永久重定向到http://hostname.com/website_folder/page1.aspx

这可以通过URL Mapping/Rewrite

来实现

有几个approaches explained by Scott Guthrie并且还会检查How to specify url mappings in ASP.NET 4.0 when parameters are involved?

希望这会对你有所帮助