Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

5- Application Settings

0 (0 Likes / 0 Dislikes)
in most if not all application we have one or more setting that can affect how the application operates for example, our application may use a mail server to send emails so it needs to know the address of the mailserver as well as the user name and password as the best pratice we should not store these settings in the code instead we should store them in the web.config so here in we.config we have this sessions called appSetting where we can store appSetting using key Value pair by default we have 4 setting here which is basically there because of the legacy stuff in ASP.Net MVC and how we have evolve from version 1 to version 5 for example we have setting for enabling validation for client or unobstrusive JS you don't need to touch any of these stuffs, they are used internally by MVC Framework so, now let me show you a real example of using appSetting earlier, we added this appId and appSecret for facebook authentication these values are hard coded here, and it is not a good thing so, I am gonna move them to application setting in web.config, I am gonna add a couple of key FacebookAppId value 12345 duplicate FacebookAppSecret abcde now back to our startup class, to read application setting, we use the configuration manager class which is defined in system.configuration, so you need to import this namespace on the top this class has a bunch of static property and method most of the time we work with AppSettings or ConnectionString so AppSetting, now this is like a dictionary so we can provide a string indexer facebookAppId and similarly FacebookAppSecret so in this case both of our values are stored in form of string but if you want to store in form of numeric or boolean or datetime in application setting you need to convert them to the corresponding type because appSetting always returns a string so this is basically how we work with application setting now let's take this to the next level back in web.config I am gonna add another setting Mailserver, this is just for demo, we are not gonna send emails and I set this to dev-smtp.vidly now let's say in our testing environment, we want to use a different mail server that's where our Build Configuration comes into the picture in web.config, we add the appSetting session now I m go back to the original we.config, copy these setting and back to Web Testing and paste it and if I leave it like this, it is not going to overwrite the setting in the original web.config we need to apply a transformation and for that I am going to borrow this line from connection string session so this transformation said, when you find an element with the same name attribute set all the values attributes based on the values in this file now I am gonna change this to key with this key application setting in this file with the same key will overwrite the one in the parent Web.config now let's me show you technique we can always preview the output of this transformation select Web Testing.config right click, select preview Transform so on the left we have the original web.config, on the right we have the web.config for the testing environment we have two changes here one is for the default connection another change is for the compilation session, debug=true is removed back to web testing.config change this value to test-smtp.vidly.com save, close the preview windows and open it again now you can see the MailServer setting in our testing environment equal test-smtp.vidly.com in the next lecture I will talk about securing application setting

Video Details

Duration: 5 minutes and 26 seconds
Country:
Language: English
License: Dotsub - Standard License
Genre: None
Views: 0
Posted by: lpk1234 on Nov 5, 2019

Caption and Translate

    Sign In/Register for Dotsub to translate this video.