MVC 3 getting values from AppSettings in web.config

Usually I’m using AppSettings static class to access those parameters. Something like this: public static class AppSettings { public static string ClientSecret { get { return Setting<string>(“ClientSecret”); } } private static T Setting<T>(string name) { string value = ConfigurationManager.AppSettings[name]; if (value == null) { throw new Exception(String.Format(“Could not find setting ‘{0}’,”, name)); } return (T)Convert.ChangeType(value, …

Read more

CS0234: Mvc does not exist in the System.Web namespace

I had the same problem and I had solved it with: 1.Right click to solution and click ‘Clean Solution’ 2.Click ‘References’ folder in solution explorer and select the problem reference (in your case it seems System.Web.Mvc) and then right click and click ‘Properties’. 3.In the properties window, make sure that the ‘Copy Local’ property is …

Read more

Get response from PostAsJsonAsync

Continue to get from content: var httpClient = new HttpClient(); var response = httpClient.PostAsJsonAsync(posturi, model).Result; bool returnValue = response.Content.ReadAsAsync<bool>().Result; But, this is really naive approach for quick way to get result. PostAsJsonAsync and ReadAsAsync is not designed to do like this, they are designed to support async await programming, so your code should be: var …

Read more

Deploying ASP.NET MVC4 App to GoDaddy Compiler issue

I have struggled with the same problem for months. And finally solved it. In the plesk on godaddy I changed the ASP.Net settings. First changed CAS-trustlevel to Full. Then I changed in the Web.config of my project the following: Add trust level full to the system.web Remove the compilers in the system.codecom <system.web> compilation debug=”true” …

Read more

When to use RedirectToAction and where to use RedirectToRouteResult?

There isn’t much difference between the two when using within the controller like you have in your example. They both ultimately achieve the same goal. However, RedirectToRouteResult() is mostly used in an action filter type scenario seen here. It’s a little less friendly on the eyes when just using in your actions on controllers. Both …

Read more

Async loading of javascript files using MVC4 Bundling and HTML5 async attribute

If you upgrade to the 1.1-alpha1 release, you can just add the async attribute to the tag format either via: Scripts.DefaultTagFormat = @”<script src=””{0}”” async></script>” or passing it where you want the async tag Use following instead of Scripts.Render(“~/bundles/jquery”) Scripts.RenderFormat(@”<script src=””{0}”” async></script>”, “~/bundles/jquery”)