Get a value from web.config from a class library

0

I have an ASP.NET app that has a presentation layer, data, business, entities, etc.

One of the peculiarities of the presentation layer is that in the beginning it executes a task in 2nd plane whose mission is to generate every X seconds the sending of a message through the network. This task is encapsulated in another project of type class library .

As part of this message, I need to send the user who logged in to the application, data that I do not have when I start the application but I get it later on a login screen.

In a first idea to pass this data through a global variable that modified its value at the time of login and then, from the function that sends the message, retrieve it to send it. This I tried using the file global.asax of the application and I could save the value without problems, since the login is in the main application MVC.

I need to be able to read that file from class library and I can not find how to do that, since in that library I do not have access to the session variables. Any other ideas on how to do this task?

Greetings and thanks for your time.

    
asked by Luis Gabriel Fabres 16.06.2017 в 18:36
source

1 answer

0

config we declare variable such as:

<appSettings>
     <add key="Prefix" value="Bkaa6guJnZ5rqwe" />
        <add key="Suffix" value="vNUaBs4ehnTDBvf" />
</appSettings>

and in the logical layer we would read it in the following way:

  string prefi = ConfigurationManager.AppSettings["Prefix"];
  string suffi = ConfigurationManager.AppSettings["Suffix"];

I hope it helps ¬V

    
answered by 17.05.2018 в 16:43