Turning the establishSecurityContext off (it’s on by default) was recommended in the IAC course on Pluralsight by Dominick Baier in the Security Best Practices module, State Management when making lots of short calls. “Other protocols like the WS 2007 Federation HttpBinding, they support state and unfortunately it’s turned on by default…. [uses] WS-Secure Conversation which is kind of heavy handed. It is quite complex as well and it has some performance implications.” ~ Pluralsight video http://www.code-magazine.co... ......
I needed to unit test a WebAPI call in my MVC 4 application that checks the user's role. I'm doing this in my MVC controllers with the following code using FakeItEasy (I should do a post on that sometime): this.UserPrincipalFake = A.Fake<IPrincipal>(); A.CallTo(() => this.UserPrincipalFake.Iden... A.CallTo(() => this.UserPrincipalFake.Iden... this.HttpContextBaseFake = A.Fake<HttpContextBase&g... this.HttpContextBaseFake.User ......
MVC can work with .cshtml or .aspx pages (you can mix Web Forms and Razor views in the One ASP.Net that Scott Hanselman talks about). This means MVC will search for a view with endings of .aspx, .ascx, .cshtml, .vbcshtml, in the Controller directory (if you have a HomeController, then it it would look in Views/Home, then Views/Shared). If you aren’t using aspx pages it’s doing extra work it doesn’t need to do. See Dave Ward’s post on the importance of using debug=false and Marcin Doboz’s post on ......
I can pass the name of the template to the controller like this (/Templates/KnockoutTemplat... where 'radial' is the name of a view (radial.cshtml), return a partial view of that name and have Knockout put it in the template block. My Controller: public class TemplatesController : Controller{ public TemplatesViewModel viewModel { get; set; } public ActionResult KnockoutTemplate(string templateName, int? id) { this.viewModel.Id = id; return PartialView(templateName.Re... ......
We upgraded a javascript library and pointed to the *.min.js files in our MVC4 application. They weren't getting downloaded and were not in the source code when running in debug="true", but worked in debug="false".
The lesson is to remove .min from your js files or the ScriptBundle doesn't return them for downloading.
bundles.Add(new ScriptBundle("~/bundles/x").Include(
"~/Scripts/x*"));
One part of MVC Views that can cause problems is that the cshtml can cause run-time errors. This can lead to bugs in Production or found by QA that could be avoided if it was built when you build the project. Pre-compiling can be turned on to avoid those problems. You add this in the project file of your web application, by setting the <MvCBuildViews>true&l... in the .csproj. See http://www.dotnetcurry.com/... for more details. Another reason to pre-compile ......
I was getting a JavaScript error that pointed to line number 1 of my MVC page. I have a form on the page and expected the Unobtrusive Validation to work with the Data Annotations. It took me a while to realize the validation messages weren't showing. After I while I found that I was missing the @Html.ValidationMessageFor(m => m.Name). Adding that for each field fixed it. My password reset with token example. I was missing line 12 and 17. 1: @using (Html.BeginForm("PasswordRe... "Home")) 2: { ......
I have requirement (specification) that the password has to be at least 7 characters long and contain a special character (~@#$&*()-_+=) which are all the specials in the number keyboard row. I found that using the RegularExpression DataAnnotations is really slick, but there was a point that caught me for a while. The problem is that @".*([!@#$&*()-_+=]+).*$" works in the UI, but fails in the unit test. @"[!@#$&*()-_+=]+" works in the test, but not in the UI (the MVC unobtrusive library ......
Since I installed the v2 update, Visual Studio has been hanging on occasion. The CPU for the process jumps to 25% and stays there and Visual Studio stops responding. I found a Microsoft Connect feedback which describes the same problem. It seems to be connected to intellisense for Knockout. There is a registry hack to turn it off, and this has worked for me. On March 13th, they report that the fix will be in VS Update 2, which is currently in CTP4 state (on March 19, 2013) with a “go-live” license.Update ......
If you try to dependency injection into a constructor with WebAPI, you’ll get an exception that says you need a parameter less constructor. The same is true for MVC controllers, but that is a different topic. Microsoft contains a good guide on how to get this working. There is also a useful StructureMap.DependencyReso... nuget package by statish860 that does it for you. Get the nuget package, then add GlobalConfiguration.Configu... = new DependencyResolver(ObjectFa... ......