.NET 4(.5)には、この驚くべき機能がありますAttribute
:PreApplicationStartMethodAttribute
、SharePoint 2013で使用したいのでapp_start
、ファイル内のメソッドをglobal.asax
直接編集する必要はありません。
SP2013は正しいバージョンの.NETを実行しているので、この属性は正しく機能すると思いました...しかし、そうではないようです。
誰かがそれを使用する方法をもう理解しましたか?またはそれが機能しない理由を説明しますか?
小さな更新PreApplicationStartMethodAttribute
:system.web dllで、次のクラスによって呼び出されていることがわかります。
// 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;
}
SharePoint2013がasp.net4.0で実行されている場合、アプリケーションで次のコマンドを呼び出すことができます。
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe