How to Get Key Value From Web Config in ASP.Net MVC


How to Get Key Value From Web Config in ASP.Net MVC

Read value from web.config C#

Web config appsettings section is used to store user defined values such as connection strings which is used through out the project for database connection. This tip shows that how to get key value from web config in asp net in two different ways at client side using javascript and at server side in code behind. Find the code snippet below :-
    <add key="vDirectory" value="demo" />

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MVC4_ReadAppSettingValue.Controllers
    public class MainController : Controller
        // GET: /Main/      
        public ActionResult GetAppSettingsValueClientSide()
            return View();
        public ViewResult GetAppSettingsValueServerSide()
            ViewData["vDir"] = System.Configuration.ConfigurationManager.AppSettings["vDirectory"].ToString();
            return View();
c# .net mvc, mvc web,dot net mvc, mvc dot net,asp mvc, mvc website,
read value from web.config c#
       ViewBag.Title = "Get value from web.config AppSettings Server Side";
    Get value from web.config AppSettings Server Side

If you want to read web.config APP key settings in HTML at Client side, use the below code in your mvc web application

<!DOCTYPE html>
    <title>MVC 4 - Get value from web.config AppSettings using jQuery</title>
    <script src="~/Scripts/utility.js" type="text/javascript"></script>
    <script type="text/javascript">
        var Vdir = '@System.Web.Configuration.WebConfigurationManager.AppSettings["vDirectory"]';     
        Click below to get value from web.config AppSettings
    <a href="#" onclick="GetAppSettingsValue();">Get Appsettings Value</a>

function GetAppSettingsValue() {
get value from web.config appsettings c#,access web.config appsettings, web.config app settings, web config appsettings, appsettings read
mvc view get value from web.config using at client side
How to Get Key Value From Web Config in ASP.Net MVC Reviewed by Ravi Kumar on 6:19 PM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form


Email *

Message *

Powered by Blogger.