简体   繁体   中英

Setting connection string after publishing on IIS Server

I have two projects, an asp.net MVC project called Home and ac# class library project called Home.Dao.

  • Home is a simple MVC Project with no connectionstring property in its web.config
  • Home.Dao is ac# class library project and it is responsible off all the interactions between the code and the database. It has an app.config and contains a connectionstring property

When publishing the Home project in IIS server, I can only find these files (web.config, Hom.Dao.dll, ... etc ) there is no app.config published. My problem is I cannot set the connectionstring after publishing. So I have two questions in mind :

  1. How is it possible to set connectionstring from web.config so this connectionstring can be used on Home.Dao
  2. Is possible to publish also the app.config ?

To answer your questions:

  1. It is not only possible, it is necessary to set the connection string from web.config
  2. You could copy the app.config to the output directory, but that wouldn't be of much use to you.

To explain why:

Configuration files are only created for the top-level application. For web applications this is the web.config file which is copied to the output directory. For executables the app.config is renamed to -executable name-.exe.config. Configurations are only read from the top-level application config. All settings you need have to be there. So if you transfer your connection string to your web.config, you're good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM