本文整理汇总了C#中SPWebApplication类的典型用法代码示例。如果您正苦于以下问题:C# SPWebApplication类的具体用法?C# SPWebApplication怎么用?C# SPWebApplication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SPWebApplication类属于命名空间,在下文中一共展示了SPWebApplication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentContentDatabase
protected SPContentDatabase GetCurrentContentDatabase(SPWebApplication webApp, ContentDatabaseDefinition definition)
{
var dbName = definition.DbName.ToUpper();
return webApp.ContentDatabases.OfType<SPContentDatabase>()
.FirstOrDefault(d => !string.IsNullOrEmpty(d.Name) && d.Name.ToUpper() == dbName);
}
示例2: FlushBlobCache
/// <summary>
/// Flushes the BLOB cache for the specified Web Application.
/// WARNING: This method needs to be run as Farm Admin and have security_admin SQL server role and the db_owner role
/// on the web app's content DB in order to successfully flush the web app's BLOB cache.
/// </summary>
/// <param name="webApplication">The SharePoint web application.</param>
public void FlushBlobCache(SPWebApplication webApplication)
{
try
{
PublishingCache.FlushBlobCache(webApplication);
}
catch (SPException exception)
{
this.logger.Error("Failed to flush the BLOB cache accross the web app. You need You need security_admin SQL server role and the db_owner role on the web app's content DB. Caught and swallowed exception: {0}", exception);
}
catch (AccessViolationException exception)
{
this.logger.Warn("Received an AccessViolationException when flushing BLOB Cache. Trying again with RemoteAdministratorAccessDenied set to true. Caught and swallowed exception: {0}", exception);
bool initialRemoteAdministratorAccessDenied = true;
SPWebService myService = SPWebService.ContentService;
try
{
initialRemoteAdministratorAccessDenied = myService.RemoteAdministratorAccessDenied;
myService.RemoteAdministratorAccessDenied = false;
myService.Update();
PublishingCache.FlushBlobCache(webApplication);
}
finally
{
myService.RemoteAdministratorAccessDenied = initialRemoteAdministratorAccessDenied;
myService.Update();
}
}
}
示例3: ExtendWebApp
/// <summary>
/// Extends the web app.
/// </summary>
/// <param name="webApplication">The web application.</param>
/// <param name="description">The description.</param>
/// <param name="hostHeader">The host header.</param>
/// <param name="port">The port.</param>
/// <param name="loadBalancedUrl">The load balanced URL.</param>
/// <param name="path">The path.</param>
/// <param name="allowAnonymous">if set to <c>true</c> [allow anonymous].</param>
/// <param name="useNtlm">if set to <c>true</c> [use NTLM].</param>
/// <param name="useSsl">if set to <c>true</c> [use SSL].</param>
/// <param name="zone">The zone.</param>
public static void ExtendWebApp(SPWebApplication webApplication, string description, string hostHeader, int port, string loadBalancedUrl, string path, bool allowAnonymous, bool useNtlm, bool useSsl, SPUrlZone zone)
{
SPServerBinding serverBinding = null;
SPSecureBinding secureBinding = null;
if (!useSsl)
{
serverBinding = new SPServerBinding();
serverBinding.Port = port;
serverBinding.HostHeader = hostHeader;
}
else
{
secureBinding = new SPSecureBinding();
secureBinding.Port = port;
}
SPIisSettings settings = new SPIisSettings(description, allowAnonymous, useNtlm, serverBinding, secureBinding, new DirectoryInfo(path.Trim()));
settings.PreferredInstanceId = GetPreferredInstanceId(description);
webApplication.IisSettings.Add(zone, settings);
webApplication.AlternateUrls.SetResponseUrl(new SPAlternateUrl(new Uri(loadBalancedUrl), zone));
webApplication.AlternateUrls.Update();
webApplication.Update();
webApplication.ProvisionGlobally();
}
示例4: ForceRemoveConfigModifications
// We make absolutely sure no mods with this owner exist
public void ForceRemoveConfigModifications(SPWebApplication WebApp, string Owner)
{
List<SPWebConfigModification> removeMods = new List<SPWebConfigModification>();
foreach (var mod in WebApp.WebConfigModifications)
{
if (mod.Owner == Owner)
{
removeMods.Add(mod);
}
}
foreach (var mod in removeMods)
{
string message = string.Format("Removing additional owner based mod: {0}", mod.Path);
_log.Write(_id, SPTraceLogger.TraceSeverity.InformationEvent, "WebConfigModificationHandler", "Info", message);
if (mod.Type != SPWebConfigModification.SPWebConfigModificationType.EnsureSection ||
(mod.Type == SPWebConfigModification.SPWebConfigModificationType.EnsureSection && !mod.Path.ToLower().Contains("system")))
WebApp.WebConfigModifications.Remove(mod);
else
{
string message2 = string.Format("Mod: {0} Type: {1} was not removed", mod.Path, mod.Type.ToString());
_log.Write(_id, SPTraceLogger.TraceSeverity.InformationEvent, "WebConfigModificationHandler", "Info", message2);
}
}
_log.Write(_id, SPTraceLogger.TraceSeverity.InformationEvent, "WebConfigModificationHandler", "Info", "Mods deleted, updating");
SPWebService.ContentService.WebApplications[WebApp.Id].Update();
_log.Write(_id, SPTraceLogger.TraceSeverity.InformationEvent, "WebConfigModificationHandler", "Info", "Mods deleted, applying update");
SPWebService.ContentService.WebApplications[WebApp.Id].WebService.ApplyWebConfigModifications();
}
示例5: GetUrls
internal static void GetUrls(List<string> urls, SPWebApplication webApp)
{
foreach (SPAlternateUrl url in webApp.AlternateUrls)
{
GetUrls(urls, url);
}
}
示例6: AddAndCleanWebConfigModification
/// <summary>
/// Method to add one or multiple WebConfig modifications
/// NOTE: There should not have 2 modifications with the same Owner.
/// </summary>
/// <param name="webApp">The current Web Application</param>
/// <param name="webConfigModificationCollection">The collection of WebConfig modifications to remove-and-add</param>
/// <remarks>All SPWebConfigModification Owner should be UNIQUE !</remarks>
public void AddAndCleanWebConfigModification(SPWebApplication webApp, Collection<SPWebConfigModification> webConfigModificationCollection)
{
// Verify emptyness
if (webConfigModificationCollection == null || !webConfigModificationCollection.Any())
{
throw new ArgumentNullException("webConfigModificationCollection");
}
SPWebApplication webApplication = SPWebService.ContentService.WebApplications[webApp.Id];
// Start by cleaning up any existing modification for all owners
// By Good practice, owners should be unique, so we do this to remove duplicates entries if any.
var owners = webConfigModificationCollection.Select(modif => modif.Owner).Distinct().ToList();
this.RemoveExistingModificationsFromOwner(webApplication, owners);
// Add WebConfig modifications
foreach (var webConfigModification in webConfigModificationCollection)
{
webApplication.WebConfigModifications.Add(webConfigModification);
}
// Commit modification additions to the specified web application
webApplication.Update();
// Push modifications through the farm
webApplication.WebService.ApplyWebConfigModifications();
// Wait for timer job
WaitForWebConfigPropagation(webApplication.Farm);
}
示例7: RemoveExistingModificationsFromOwner
public void RemoveExistingModificationsFromOwner(SPWebApplication webApplication, IList<string> owners)
{
var removeCollection = new Collection<SPWebConfigModification>();
var modificationCollection = webApplication.WebConfigModifications;
int count = modificationCollection.Count;
for (int i = 0; i < count; i++)
{
SPWebConfigModification modification = modificationCollection[i];
if (owners.Contains(modification.Owner))
{
// collect modifications to delete
removeCollection.Add(modification);
}
}
// now delete the modifications from the web application
if (removeCollection.Count > 0)
{
foreach (SPWebConfigModification modificationItem in removeCollection)
{
webApplication.WebConfigModifications.Remove(modificationItem);
}
// Commit modification removals to the specified web application
webApplication.Update();
// Push modifications through the farm
webApplication.WebService.ApplyWebConfigModifications();
}
// Wait for timer job
WaitForWebConfigPropagation(webApplication.Farm);
}
示例8: RemoveConfigModifications
public virtual void RemoveConfigModifications(SPWebApplication WebApp, string Owner)
{
if (WebApp == null)
throw new ArgumentException("WebApp is null, perhaps your feature is not scoped at WebApp level?", "WebApp");
if (string.IsNullOrEmpty(Owner))
throw new ArgumentException("Owner is null", "Owner");
foreach (var mod in _modifications)
{
string message = string.Format("Removing Mod: {0}", mod.Path);
_log.Write(_id, SPTraceLogger.TraceSeverity.InformationEvent, "WebConfigModificationHandler", "Info", message);
WebApp.WebConfigModifications.Remove(mod);
}
//WebApp.Update();
//WebApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
_log.Write(_id, SPTraceLogger.TraceSeverity.InformationEvent, "WebConfigModificationHandler", "Info", "Mods deleted, updating");
SPWebService.ContentService.WebApplications[WebApp.Id].Update();
_log.Write(_id, SPTraceLogger.TraceSeverity.InformationEvent, "WebConfigModificationHandler", "Info", "Mods deleted, applying update");
SPWebService.ContentService.WebApplications[WebApp.Id].WebService.ApplyWebConfigModifications();
ForceRemoveConfigModifications(WebApp, Owner);
}
示例9: DeployPeoplePickerSettings
private void DeployPeoplePickerSettings(object modelHost, SPWebApplication webApplication, PeoplePickerSettingsDefinition definition)
{
var settings = GetCurrentPeoplePickerSettings(webApplication);
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = settings,
ObjectType = typeof(SPPeoplePickerSettings),
ObjectDefinition = definition,
ModelHost = modelHost
});
MapPeoplePickerSettings(settings, definition);
// reSP doesn't like updating SPWebApplication here, don't see an other way though
webApplication.Update();
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = settings,
ObjectType = typeof(SPPeoplePickerSettings),
ObjectDefinition = definition,
ModelHost = modelHost
});
}
示例10: DeleteJob
private static void DeleteJob(SPWebApplication application, string jobName)
{
var job = application.JobDefinitions.SingleOrDefault(c => jobName == c.Name);
if (job != null)
{
job.Delete();
}
}
示例11: AddAndCleanWebConfigModification
/// <summary>
/// Method to add one or multiple WebConfig modifications
/// NOTE: There should not have 2 modifications with the same Owner.
/// </summary>
/// <param name="web">The current Web Application</param>
/// <param name="webConfigModificationCollection">The collection of WebConfig modifications to remove-and-add</param>
/// <remarks>All SPWebConfigModification Owner should be UNIQUE !</remarks>
public void AddAndCleanWebConfigModification(SPWebApplication webApp, Collection<SPWebConfigModification> webConfigModificationCollection)
{
// Verify emptyness
if (webConfigModificationCollection == null || !webConfigModificationCollection.Any())
{
throw new ArgumentNullException("webConfigModificationCollection");
}
SPWebApplication webApplication = SPWebService.ContentService.WebApplications[webApp.Id];
// Start by cleaning up any existing modification for all owners
foreach (var owner in webConfigModificationCollection.Select(modif => modif.Owner).Distinct())
{
// Remove all modification by the same owner.
// By Good practice, owner should be unique, so we do this to remove duplicates entries if any.
this.RemoveExistingModificationsFromOwner(webApplication, owner);
}
if (webApplication.Farm.TimerService.Instances.Count > 1)
{
// HACK:
//
// When there are multiple front-end Web servers in the
// SharePoint farm, we need to wait for the timer job that
// performs the Web.config modifications to complete before
// continuing. Otherwise, we may encounter the following error
// (e.g. when applying Web.config changes from two different
// features in rapid succession):
//
// "A web configuration modification operation is already
// running."
WaitForOnetimeJobToFinish(
webApplication.Farm,
"Microsoft SharePoint Foundation Web.Config Update",
120);
}
// Add WebConfig modifications
foreach (var webConfigModification in webConfigModificationCollection)
{
webApplication.WebConfigModifications.Add(webConfigModification);
}
// Commit modification additions to the specified web application
webApplication.Update();
// Push modifications through the farm
webApplication.WebService.ApplyWebConfigModifications();
if (webApplication.Farm.TimerService.Instances.Count > 1)
{
WaitForOnetimeJobToFinish(
webApplication.Farm,
"Microsoft SharePoint Foundation Web.Config Update",
120);
}
}
示例12: IisSettingNode
public IisSettingNode(SPWebApplication app, KeyValuePair<SPUrlZone, SPIisSettings> iisSettings)
{
this.Tag = iisSettings.Value;
this.Name = iisSettings.Key.ToString();
this.Text = iisSettings.Key.ToString();
this.ToolTipText = iisSettings.Key.ToString();
this.BrowserUrl = app.GetResponseUri(iisSettings.Key).ToString();
this.Setup();
}
示例13: GetCurrentAlternateUrl
protected SPAlternateUrl GetCurrentAlternateUrl(SPWebApplication webApp, AlternateUrlDefinition definition)
{
var alternateUrls = webApp.AlternateUrls;
var url = definition.Url;
var urlZone = (SPUrlZone)Enum.Parse(typeof(SPUrlZone), definition.UrlZone);
return alternateUrls.GetResponseUrl(urlZone);
}
示例14: FeatureCollectionNode
public FeatureCollectionNode(SPWebApplication webApp)
: this()
{
this.Text = SPMLocalization.GetString("SiteFeatures_Text");
this.ToolTipText = SPMLocalization.GetString("SiteFeatures_ToolTip");
this.Name = "SiteFeatures";
this.Tag = webApp.Features;
this.SPParent = webApp;
}
示例15: RemoveJobIfRegistered
private void RemoveJobIfRegistered(SPWebApplication app)
{
foreach (SPJobDefinition job in app.JobDefinitions)
{
if (job.Title == JobName)
{
job.Delete();
}
}
}