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 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 core blazor vs .net core mvc with razor

0 Video with visual explanation I decided to make a video, since several questions about Blazor were asked (also on other forums) and this format seems much better for me to visualize the differences – instead of reding my (longer) explanation. The video contains a bit improved version, compared to my first post (the text … 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

Why is the comma URL encoded?

The URI spec, RFC 3986, specifies that URI path components not contain unencoded reserved characters and comma is one of the reserved characters. For sub-delims such as the comma, leaving it unencoded risks the character being treated as separator syntax in the URI scheme. Percent-encoding it guarantees the character will be passed through as data.

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