简体   繁体   中英

Get the start page of a given url

I'm trying to get the landing page of a website, for example:

www.mypage.com/ 
goes to
 www.mypage.com/default.aspx  
The landing page is default.aspx , so what I need is to identify if the loaded page is the same by entering an url, basically the following:

input:

 www.mypage.com/ = www.mypage.com/default = www.mypage.com/default.aspx 
ouput:
 default.aspx 

All those entrances redirect the user to the same page that is the start page, and the url is entered by an input field.

Can anyone help me out?

Using WatiN you can make a simple test method. Something like this should accomplish what you want.

UPDATE: I think I understand your question a little better now. I think you just want to get the landing page. This should work for you.

public string GetHomePage()
{
    string startURL = "http://www.mypage.com/";
    string[] splits = null;

    using (var browser = new IE(startURL))
    {
        string browserURL = browser.Url;
        splits = browserURL.Split(new string[] { startURL }, StringSplitOptions.None);
    }

    return splits[1];
}

You can try with this: `

string url = "http://google.com";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.AllowAutoRedirect = false;

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
     string redirect = response.Headers["Location"];
     if (redirect != null)
                Console.WriteLine("Redirected to " + redirect);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM