Вопрос

Что разница между:

SPSite.Url 

SPSite.RootWeb.Url
.

Если оба такие же, что считается хорошей практикой?

Это было полезно?

Решение

I don't believe there is a difference in terms of what they return back (the string representation of the root URL of the site).

However, in the second case you are referencing both an SPSite and SPWeb object whereas in the first you are only referencing the SPSite object (so there might be some minor performance considerations if all you are looking for is the URL to the site).

In addition I would think the the context of the code you are writing would favor one over the other (e.g. if you have code that is scoped at the site level it would make more sense to just get the SPSite object Url; if your code was scoped at the web level (for example, doing something to the root SPWeb object and then traversing down to subsequent children webs) then referencing the rootweb.url would make more consistent sense to me).

In both cases you would need to make sure you are following proper disposal practices: http://msdn.microsoft.com/en-us/library/ms468609.aspx

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top