VSP
VSP

Reputation: 2393

c# How to get a meaninful name of website or executable

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 ^^

Upvotes: 2

Views: 303

Answers (2)

VSP
VSP

Reputation: 2393

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;
}

Upvotes: 0

lstern
lstern

Reputation: 1629

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

Upvotes: 1

Related Questions