在 .NET 4(.5) 中有这个惊人的Attribute
: PreApplicationStartMethodAttribute
,我想在 SharePoint 2013 中使用它,所以我不必直接编辑文件app_start
中的方法global.asax
。
由于 SP2013 运行正确版本的 .NET,我认为该属性可以正常工作……但情况似乎并非如此。
有没有人知道如何使用它?或解释为什么它不能工作?
小更新:在 system.web dll 中我可以看到PreApplicationStartMethodAttribute
由以下类调用。
// System.Web.Compilation.BuildManager
internal static ICollection<MethodInfo> GetPreStartInitMethodsFromAssemblyCollection(IEnumerable<Assembly> assemblies, bool buildingFromCache)
{
List<MethodInfo> list = new List<MethodInfo>();
foreach (Assembly current in assemblies)
{
PreApplicationStartMethodAttribute[] array = null;
try
{
array = (PreApplicationStartMethodAttribute[])current.GetCustomAttributes(typeof(PreApplicationStartMethodAttribute), true);
}
catch
{
}
if (array == null || !array.Any<PreApplicationStartMethodAttribute>())
{
if (buildingFromCache)
{
return null;
}
}
else
{
PreApplicationStartMethodAttribute[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
PreApplicationStartMethodAttribute preApplicationStartMethodAttribute = array2[i];
MethodInfo methodInfo = null;
if (preApplicationStartMethodAttribute.Type != null && !string.IsNullOrEmpty(preApplicationStartMethodAttribute.MethodName) && preApplicationStartMethodAttribute.Type.Assembly == current)
{
methodInfo = BuildManager.FindPreStartInitMethod(preApplicationStartMethodAttribute.Type, preApplicationStartMethodAttribute.MethodName);
}
if (!(methodInfo != null))
{
throw new HttpException(SR.GetString("Invalid_PreApplicationStartMethodAttribute_value", new object[]
{
current.FullName,
(preApplicationStartMethodAttribute.Type != null) ? preApplicationStartMethodAttribute.Type.FullName : string.Empty,
preApplicationStartMethodAttribute.MethodName
}));
}
list.Add(methodInfo);
}
}
}
return list;
}
如果 SharePoint 2013 在 asp.net 4.0 上运行,我可能会幸运地在应用程序上调用以下内容。
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe