Sharepoint 2010 - AAM - SPSite(SPContext.Current.Site.ID) RootWeb.Url is from wrong zone
- by user2026343
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
}