C# 4.0 var appAssembly=Assembly.GetEntryAssembly()&;OWN-don';不混?
在使用OWIN的WebAPI项目中,调用似乎总是返回NULL:C# 4.0 var appAssembly=Assembly.GetEntryAssembly()&;OWN-don';不混?,c#-4.0,asp.net-web-api2,owin,C# 4.0,Asp.net Web Api2,Owin,在使用OWIN的WebAPI项目中,调用似乎总是返回NULL: var appAssembly = Assembly.GetEntryAssembly(); 我也试过: var entryAssembly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly; 返回的只是“System.Web” 如何获取应用程序名称、版本 我正试图在Web API项目启动时捕获以下信息: /// <summary> /
var appAssembly = Assembly.GetEntryAssembly();
我也试过:
var entryAssembly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly;
返回的只是“System.Web”
如何获取应用程序名称、版本
我正试图在Web API项目启动时捕获以下信息:
/// <summary>
/// The OWIN startup class.
/// </summary>
public class Startup
{
/// <summary>
/// The necessary OWIN configuration method.
/// </summary>
/// <param name="app">The app being started under OWIN hosting.</param>
public void Configuration(IAppBuilder app)
{
var appAssembly = Assembly.GetEntryAssembly();
Aspect.Logging.LoggingHandler.Initialize(appAssembly, "Hard Coded App Name!");
Log.Information("Starting App...");
// Order is important here. The security wiring must happen first.
ConfigureAuthentication(app);
// Create web configuration and register with WebAPI.
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
// Configure documentation.
ConfigureDocumentation(config);
// Configure support for static files (e.g. index.html).
app.UseFileServer(new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = new PhysicalFileSystem(".")
});
// Start the API.
app.UseWebApi(config);
Log.Information("App started.");
}
//
///OWIN启动类。
///
公营创业
{
///
///必要的OWIN配置方法。
///
///正在OWIN主机下启动的应用程序。
公共无效配置(IAppBuilder应用程序)
{
var appAssembly=Assembly.GetEntryAssembly();
Aspect.Logging.LoggingHandler.Initialize(appAssembly,“硬编码的应用程序名!”);
日志信息(“启动应用程序…”);
//这里的秩序很重要。必须首先进行安全接线。
配置认证(app);
//创建web配置并向WebAPI注册。
HttpConfiguration config=新的HttpConfiguration();
WebApiConfig.Register(配置);
//配置文档。
配置文档(config);
//配置对静态文件(例如index.html)的支持。
app.UseFileServer(新文件服务器选项
{
EnableDefaultFiles=true,
文件系统=新物理文件系统(“.”)
});
//启动API。
app.UseWebApi(配置);
日志信息(“应用程序已启动”);
}
使用:
您是引用要从中获取程序集信息的程序集,还是引用了同一个程序集?您是否考虑过
var appAssembly=typeof(Startup).assembly;
这样做!不,我没有考虑过使用它。在我的搜索中甚至没有找到它。谢谢!
var appAssembly = typeof(Startup).Assembly;