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

Asp.net 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

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.

HOW? Controller return nothing/current view

You can return an EmptyResult if you want it to do nothing… return new EmptyResult(); If you’re using the AjaxHelper you can avoid the update by supplying an unsuccessful status code (e.g. 404 or whatever is most appropriate), that’ll stop it replacing your div as the javascript in MicrosoftMvcAjax.js explicitly checks for a successful response … Read more

How do I get certain code to execute before every single controller action in ASP.NET MVC 2?

All depends what exactly you want to do, and how. Three options below: You can use route constraints for this. They are executed when evaluating the route to match to. routes.MapRoute( “HomeWithConstraint”, “Home/{action}”, new {controller=”Home”, action=”index”}, new { x = new MyCustomRouteConstraint () } ); // without constraint, i.e. if above didnt pass routes.MapRoute( “HomeWithConstraint”, … Read more