Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3452250
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:14:06+00:00 2026-05-18T09:14:06+00:00

I have settings in AppSettings (web.config) and I need to pass them to an

  • 0

I have settings in AppSettings (web.config) and I need to pass them to an external javascript file.

In ASP.NET I would think of an ASHX handler to write the javascript file to the response replacing placeholders with the settings values.

Is there a better way to do it in ASP.NET MVC? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:14:07+00:00Added an answer on May 18, 2026 at 9:14 am

    You could send them via a JsonResult?

    In your JS, you’d have a request which sends a GET/POST request to a particular action (let’s call it GetAppSetting(), and the corresponding value is returned in the response.

    For security reasons, I would restrict what can be requested though…

    public JsonResult GetAppSetting(string id)
    {
      //You could check what's been requested here if you want to make sure you're only returning information that you may not wish to send.
      string appSetting = AppSettings[id];
    
      if(string.IsNullOrEmpty(appSetting) == false)
      {
        return Json(appSetting, JsonRequestBehavior.AllowGet);
      }
    
      //Handle non-existent settings here...
      throw new Exception("This setting does not exist");
    }
    

    Alternatively, it has been suggested by Chris Marisic in the comments that you may want to absolutely limit this to just a specific set of key/values for developer reasons. Therefore, here is a quick example of that…

    public JsonResult GetAppSettings()
    {
      var appSettings = new Dictionary<string, string>();
      appSettings.Add("myAppSetting1", AppSettings["myAppSetting1"]);
      appSettings.Add("myAppSetting2", AppSettings["myAppSetting2"]);
      appSettings.Add("myAppSetting3", AppSettings["myAppSetting3"]);
    
      return Json(appSettings, JsonRequestBehavior.AllowGet);
    }
    

    Note the JsonRequestBehavior.AllowGet in the JsonResults (MVC 2 only). This is because, by default, ASP.NET MVC 2 will not allow GET requests on actions which return a JsonResult. You can circumvent this by adding the JsonRequestBehaviour, but I should probably mention that you should consider doing a post request in order to retrieve this information, and remove this behaviour in your action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ASP.NET server app which has in web.config : <appSettings file=config\another.config> so the
I have various settings in my ccnet.config file and wish to pass them to
I have an asp.net mvc website which of course has a web.config file. I
Using ASP.NET under .NET 2.0, is it possible to get/set AppSettings in a web.config
I want to split web.config and take these settings in a external file. <customErrors
I have some settings in a web.config file that I want to override when
I need to store my application config settings in a hierarchical format in web.config
I have some settings stored in web.config like this: <add key=Answers value=radiobutton1,radiobutton2,radiobutton3/> Radiobutton1, radiobutton2
I have the following in my web.config: <configuration> <appSettings> <add key=PsychMon value=true/> </appSettings> .
I have the following setup: ASP.net 3.5 Web Site Project C# Class Library with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.