问题
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