0

So i have a web application with a DLL having function lets say function add().

I am writing an azure function V1 that has the reference of my DLL.

So is there a way for me to identify whether the function add() in my DLL is called from azure function

or it is called from my web application.

Its_Ady
  • 308
  • 2
  • 10
  • 1
    Send it a value? `myProperty(boolean calledFromAzure)`? – Liam Nov 28 '19 at 15:51
  • @Liam adding a parameter will have a huge impact as the application is old. can i use environment variables in that dll? will it be accessible? – Its_Ady Nov 28 '19 at 15:54
  • You could set an environment variable or similar when running it as a web-app, and just check that. What are you trying to achieve though? – RB. Nov 28 '19 at 15:54
  • 1
    @RB. actually i wan to give different connection strings when it is called from webapp and azure function. – Its_Ady Nov 28 '19 at 15:55
  • 3
    Put your connection string in the web.config and just deploy a different one to each environment. – Reinstate Monica Cellio Nov 28 '19 at 15:56
  • 1
    ??? Surely the connection string is part of the configuration that you apply to your instance *before* you call the method on the instance? – RB. Nov 28 '19 at 15:56
  • @RB. the function which i will call actually calls another function which get the required connection string as i have multiple database servers. for azure it will be of sql managed instance and for web app it will be simple DB. – Its_Ady Nov 28 '19 at 16:03
  • 1
    So your real issue here is that your hard coding your connection strings, yeah, stop doing that... – Liam Nov 28 '19 at 16:03
  • @RB.its not hardcoding.i am getting the value of connection string from config file in webapp.and i want to know if i can identify that if this function is called from azure i can use the azure app environment variable to assign it diff connection string. – Its_Ady Nov 28 '19 at 16:06

1 Answers1

1

You can do this with Caller Info attributes

By using Caller Info attributes, you can obtain information about the caller to a method. You can obtain file path of the source code, the line number in the source code, and the member name of the caller. This information is helpful for tracing, debugging, and creating diagnostic tools.

Owen Pauling
  • 11,349
  • 20
  • 53
  • 64