简体   繁体   中英

How to get current request url in Sharepoint 2013 in C#?

How to get current request url

I type in browser:

http://srv-1/sites/1001/Account Documents/Order

but in Page_Load in my controls I get

HttpContext.Current.Request.Url = http://srv-1/_layouts/15/start.aspx

and

Page.Request.RawUrl = Page.Request.RawUrl

I need to retrieve information: /Account Documents/Order

This happens because of Minimal Download Strategy feature. Your url is rewritten by SharePoint.

Easiest solution is to disable this feature, but you can also try to get url via SPUtility.OriginalServerRelativeRequestUrl property or refactor your code not use url, but current library or something else.

SharePoint does it's own URL rewrites, if you would try that for example for the page

The solution is to use special property on [SPUtility class – SPUtility.OriginalServerRelativeRequestUrl][1]

http://blog.voyta.net/2012/07/09/how-to-get-original-request-url-in-sharepoint/

This property returns the original URL before it was rewritten, which is useful if you need to get the subweb from which an application page was loaded.

As this URL is server-relative, to get full url, you can use:

SPUtility.GetFullUrl(SPContext.Current.Site, SPUtility.OriginalServerRelativeRequestUrl);

This can be useful if you need to redirect for example to the same URL with some additional parameters.

Thanks

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