What is the correct way for redirecting from the domain name itself to a page in a directory?

有些话、适合烂在心里 提交于 2019-12-11 13:36:51

问题


I want anyone browsing for "MyDomain.com" to see what's in "MyDomain.com/Folder1/HomePage.aspx".

I tried adding a page with <meta http-equiv="refresh" content="0;URL='MyDomain.com/Folder1/HomePage.aspx'" /> but there is a slight delay. I'd rather it is done silently.

I tried using iis-manager's HTTP-Redirect, but all sub-directories inherit it. (And asking here https://stackoverflow.com/questions/13629137/prevent-subdirectories-from-inheriting-an-http-redirect-in-iis about solving that returned mainly silent close-votes.)

So how do I achieve it?


回答1:


Meta will take some time because it will first come to client, and then it will be transferred to the new page since HTML executes in browser - not on server.

The fastest method if to place use Server.Transfer("~/Folder1/HomePage.aspx") on your Default.aspx page. This will be executed on server as compared to Response.Redirect which also throws content back to browser first, then transfers to new page.

But the drawback of using Server.Transfer("~/Folder1/HomePage.aspx") is that it will not change the URL of the browser. I mean even you will be sitting on "MyDomain.com/Folder1/HomePage.aspx" but browser will be showing you the URL of previous page.

I hope this answers your question. If yes, then mark it as "answered".




回答2:


What about trying something like this in the Default.aspx page load event?

Response.Status = "Redirecting"
Response.AddHeader("Location", "MyDomain.com/Folder1/HomePage.aspx")



回答3:


Response.Redirect

Seems to be the best way.



来源:https://stackoverflow.com/questions/13630820/what-is-the-correct-way-for-redirecting-from-the-domain-name-itself-to-a-page-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!