简体   繁体   中英

C# Get URL of page that submitted a form

I have a master page that contains a SmallSearchInputBox (SharePoint control for searching). This masterpage is used by every page on my SharePoint site. There's a single results page (results.aspx), and I want to know on which page the SmallSearchInputBox was used and submitted when viewing the results on results.aspx.

I tried the usual suspects ( Request.UrlReferrer , Request.ServerVariables["HTTP_REFERER"] , etc) but these don't appear to work when forms are involved.

Is there another way I can get the URL of the previous page when viewing my results page?

I suspect this is a standard C# question rather than a SharePoint one, though I have asked the same question from a SharePoint specific approach here: sharepoint.stackexchange.com

Can you put the url of whatever page you're on in the form that is submitting the expression?

<form id="myForm" name="myForm" action="POST" method="mypage.aspx">
    <input type="hidden" id="referer" name="referer" value="somepage.aspx?somevar=20" />
</form>

When you get to results.aspx there's a queystring. In that querstring there is a parameter u , which contains the relative URL of the site containing the page with the SmallSearchInputBox.

Thanks to Splash-X and Moo-Juice for their help :)

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