zoukankan      html  css  js  c++  java
  • Net中获取程序集路径

     

    从内存中加载的程序集,无路径

     

    IIS中路径

    protected void Page_Load(object sender, EventArgs e)

    {

    Response.Write("程序集路径"+System.Reflection.Assembly.GetExecutingAssembly().Location+"<BR/>");

    Response.Write("程序域路径"+System.AppDomain.CurrentDomain.BaseDirectory + "<BR/>");

    Response.Write("模块路径"+System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName + "<BR/>");

    Response.Write("运行时路径"+HttpRuntime.BinDirectory + "<BR/>");

    }

     

     

     

    输出

     

     

    程序集路径C:WindowsMicrosoft.NETFramework64v4.0.30319Temporary ASP.NET Files est2a51a221e6b2246assemblydl33464d81241e5e6a4_2697d301WebApplication3.dll
    程序域路径d:UserszwxDocumentsvisual studio 2015ProjectsWebApplication3WebApplication3
    模块路径c:windowssystem32inetsrvw3wp.exe
    运行时路径d:UserszwxDocumentsvisual studio 2015ProjectsWebApplication3WebApplication3in

     

     

     

    WINFORM中路径

    Console.Write("程序集路径" + System.Reflection.Assembly.GetExecutingAssembly().Location + " ");

    Console.Write("程序域路径" + System.AppDomain.CurrentDomain.BaseDirectory + " ");

    Console.Write("模块路径" + System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName + " ");

    Console.Write("运行时路径" + System.Windows.Forms.Application.ExecutablePath+ " ");

     

    输出

    程序集路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServicei

    nDebugY.Cloud.Front.GatewayService.exe

    程序域路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServicei

    nDebug

    模块路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServicein

    DebugY.Cloud.Front.GatewayService.exe

    运行时路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServicei

    nDebugY.Cloud.Front.GatewayService.exe

     

     

    服务中路径

    程序集路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServiceinDebugY.Cloud.Front.GatewayService.exe

    程序域路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServiceinDebug

    模块路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServiceinDebugY.Cloud.Front.GatewayService.exe

    运行时路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServiceinDebugY.Cloud.Front.GatewayService.exe

     

     

     

    操作文件时,最好在代码中显示指定路径,毕竟程序集自身的位置是不可控的。推荐使用程序域路径或ExecutablePath

  • 相关阅读:
    我很喜欢玩游戏,那么我就适合做游戏程序员吗?
    宁可多花1000元租房,也绝不要去挤半小时地铁
    996 盛行的年代,互联网人如何平衡工作和生活 ?
    互联网公司里都有哪些潜规则?
    那些拼命加班的程序员们,后来都怎么样了?
    MongoDB更需要好的模式设计 及 案例赏析
    MongoDB 提升性能的18原则(开发设计阶段)
    关于MongoDB数据库的日志解析
    实现MongoDB读写分离的“读偏好”介绍
    MongoDB分片 在部署和维护管理 中常见事项的总结
  • 原文地址:https://www.cnblogs.com/QinQouShui/p/8365547.html
Copyright © 2011-2022 走看看