Вопрос

We have an internal error reporting system (inside our functions dll) and one of the info pieces we send is the name of the application that caused it.

Current code:

string applicationname= Assembly.GetCallingAssembly().GetName().Name;

The problem is when the error is send from one of our websites as it sends application names like "App_Code.6p_c415d".

One possible way was determining if the app is an executable or a website dinamically (how do we do that?) and in the case of being a website get the folder containing it or so...

But if you have better ways we are open to any idea ^^

Это было полезно?

Решение 2

We ended up creating the following function and it works fine:

public static string getApplicationName()
{
    return string.IsNullOrEmpty(HttpRuntime.AppDomainAppId)?
        Assembly.GetEntryAssembly().GetName().Name : 
        new DirectoryInfo(HttpContext.Current.Server.MapPath("")).Name;
}

Другие советы

You can use a key in the AppSettings to identify your application.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top