This project is read-only.
How can we use configuration data and/or other server data (very sensitive data) at client side?

Sometimes application needs configuration( very sensitive data) at client side, so later on javascript code use those configuration data
and based on those data, a presentation layer is continued to execute.

Some examples are listed below;
1. application url (configured in web.config), need to render/change a view through javascript.
2. service url (configured in web.config), need to consume data at client side and later on used by presentation layer.

There are lots of ways to consume configuration data at client side (like save configured values in hidden fields
and consumed later on).

Can we have better way to access "AppSettings" at client side?
Would it be good , if "AppSettings" is accessed with below syntax (same as server side syntax, so no more learning :)) at client side (javascript)?

 1. var url = Javascript.Configuration.ConfigurationManager.AppSettings.AppUrl;
 2. var url = Javascript.Configuration.ConfigurationManager.AppSettings["AppUrl"];

Using this library we can!! Let's explore it.

1. Download "Javascript.Configuration.ConfigurationManager".
2. Reference it into your ASP.NET MVC project.
3. Add handler, please refer below code;
            <add name="jsModule" type="Javascript.JavascriptModule" />

4. Add script reference in your master page, so all the pages can use these data;
<script src="@Url.Content("~/Javascript/AppSettings")" type="text/javascript"></script>

5. Add key in the "appSettings" with following information;
<add key="jsConfig" value="AppUrl,ServiceUrl" />
<!-- keys, AppUrl and ServiceUrl, will be exposed in the client -->


Last edited Jan 24, 2011 at 5:32 AM by vrluckyin, version 6