DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

What is difference between SPContext.Current.Web and SPContext.Current.Site.OpenWeb()

By Ashok Nalam on 01 Oct 2013 | Category: Sharepoint | Tagged: .NET security 
  Discuss Add Comment   |  
Add rating Rate this resource   
To refer SPWeb object sometimes we use SPContext.Current.Web or SPContext.Current.Site.OpenWeb(). Here we will see What are differences between SPContext.Current.Web and SPContext.Current.Site.OpenWeb()
SPContext.Current.Site.OpenWeb()
  1. Creates a new instance of the SPWeb object, and we are responsible to dispose after using it.
  2. OpenWeb() with out sending parameters opens root web of current site collection. If OpenWeb() with parameters opens specific web site.
  3. Expensive call - It cost more resources than reusing an existing one.
SPContext.Current.Web :
  1. Gives you access to the current instance of SPWeb, and you must not dispose it
  2. Gives current Subsite if you are at web other than root web.
  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 8906  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.