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

  • 相关阅读:
    基于VIP的keepalived高可用架构
    高性能Nginx最佳实践
    Ubuntu安装Nginx
    Synchronized总结及底层原理分析#网易微专业# #Java#
    springboot Restful开发
    Volatile详解
    IOC知识点详细汇总
    python 一个函数让你决定你的二维码
    用python批量生成简单的xml文档
    基于tensorflow搭建一个神经网络
  • 原文地址:https://www.cnblogs.com/QinQouShui/p/8365547.html
Copyright © 2011-2022 走看看