Sharepoint 2010 - AAM - SPSite(SPContext.Current.Site.ID) RootWeb.Url is from wrong zone

Posted by user2026343 on Stack Overflow See other posts from Stack Overflow or by user2026343
Published on 2013-12-10T16:33:04Z Indexed on 2014/05/28 9:27 UTC
Read the original article Hit count: 226

I have a sharepoint 2010 web application with 2 different zones, default zone with windows login (for search crawl), internet with Claims (FBA) for users to login.

I have custom webparts that uses

using (SPSite mySite = new SPSite(SPContext.Current.Site.ID))
                    using (SPWeb web = mySite.RootWeb)
                    { string url = web.Url

I use this url to include to emails etc... Problem is: when user connects to FBA (extended zone), and goes to the webpart,string url in my code returns the url of the default zone(windows auth) where user should not be touching.

I have different host headers for these zones, any help would be very appreciated.

Update: fixed it with using (SPSite newsite =new SPSite(SPContext.Current.Site.ID,SPContext.Current.Site.Zone)) using (SPWeb web = newsite.RootWeb) { //do your implementation here }

© Stack Overflow or respective owner

Related posts about sharepoint

Related posts about sharepoint-2010