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

Asp.net web api exception only after deploying at IIS : A route named ‘HelpPage_Default’ is already in the route collection

I just ran into the same issue. I think the error was caused because I had pushed another solution to my site previously and there were leftover files that were somehow getting in the way. To fix this I checked the box that says “Remove additional files at destination” while publishing through Visual Studio to …

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

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

Using Windows Domain accounts AND application-managed accounts

The simplest approach is to have 2 different presentation Projects only for Authentication/Authorization. This has the advantage of leaning on existing framework and standard configuration. From there, you decide to either create an AD user for every internet user, or create a DB/Internet user for every AD user. Creating an Identity user for each AD …

Read more

Is there a nameof() operator for MVC controllers in C#?

Maybe an extension method like the following would suit your needs: public static class ControllerExtensions { public static string ControllerName(this Type controllerType) { Type baseType = typeof(Controller); if (baseType.IsAssignableFrom(controllerType)) { int lastControllerIndex = controllerType.Name.LastIndexOf(“Controller”); if (lastControllerIndex > 0) { return controllerType.Name.Substring(0, lastControllerIndex); } } return controllerType.Name; } } Which you could invoke like so: return …

Read more