获得ASP.NET应用程序进入组装 [英] Get entry assembly from ASP.NET application

查看:112
本文介绍了获得ASP.NET应用程序进入组装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/4277692/getentryassembly-for-web-applications\">GetEntryAssembly Web应用程序

有是类库它通过调用获取其执行的程序集的位置 GetEntryAssembly()。但是使用ASP.NET Web应用程序,函数返回类库空。

There is class library which gets its executing assembly location by calling GetEntryAssembly(). However using that class library in ASP.NET web application that function returns null.

是否有可能从类库,它被称为获得ASP.NET应用程序的可执行文件的位置?

Is it possible to get location of ASP.NET application executable from class library which it calls?

GetCallingAssembly()不适合,因为功能不是直接从Web应用程序调用。

GetCallingAssembly() is not suitable since the function is not called directly from web application.

推荐答案

有一个看的 HttpRuntime.BinDirectory - 获取对当前应用程序的/ bin目录的物理路径

Have a look at HttpRuntime.BinDirectory - "Gets the physical path to the /bin directory for the current application."

这应该返回所有DLL的为Web应用程序都存储在目录中。

This should return the directory that all the dll's for your web application are stored in.

编辑:

好吧,根据您的反馈,这可能工作:

Ok, based upon your feedback, this might work:

var webApplicationType = typeof(MyWebApplicationClass);
var assemblyPathAndName = new System.Uri(webApplicationType.Assembly.CodeBase)).LocalPath;

您需要更换MyWebApplicationClass在要用于装配路径和名称Web项目的任何类的名称。

You will need to replace 'MyWebApplicationClass' with the name of any class in the web project that you want the assembly path and name for.

这篇关于获得ASP.NET应用程序进入组装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆