Tag Archives: ASP.NET

ASP.NET and Web Tool 2012.2 Released Today

The ASP.NET and Web Tools 2012.2 update was released today.  There were many updates including some big additions like OData support and SignalR.   Some of the things that jump out at me form the release notes.

“Paste JSON as a .NET class. Using this Special Paste command to paste JSON into a C# or VB.NET code file, and Visual Studio will automatically generate .NET classes inferred from the JSON.”

“Mobile Emulator support adds extensibility hooks so that third-party emulators can be installed as a VSIX. The installed emulators will show up in the F5 dropdown, so that developers can preview their websites on a variety of mobile devices. Read more about this feature in Scott Hanselman’s blog entry on the new BrowserStack integration with Visual Studio.”

ASP.NET Web API OData

ASP.NET Web API OData gives you the flexibility you need to build OData endpoints with rich business logic over any data source”

“ASP.NET SignalR

ASP.NET SignalR makes it simple to add real-time web capabilities to your ASP.NET application, using WebSockets if available and automatically falling back to other techniques when it isn’t.”

Related Blog Posts

ASP.NET and Web Tools 2012.2 Release Notes
ScottGu – Announcing release of ASP.NET and Web Tools 2012.2 Update
Scott Hanselman – Released: ASP.NET and Web Tools 2012.2 in Context
Jon Galloway – Announcing the ASP.NET and Web Tools 2012.2 Release!
Web Tools 2012.2 and Web Essentials

Passing values from your ASP.NET MVC Controller to Javascript

Inspired by John Papa’s Single Page Application series on Pluralsight, in my latest project I am making heavy use of the JavaScript MVVM pattern.  Since my application isn’t a true single page application I found myself in some cases needing use values from my Controller in my JavaScript methods.

After doing some research I came across this post from A. Friedman about Ngon a port he created of the Ruby Gon gem.  Ngon allows you to add a value to a ViewBag NGon property and then consume it in your JavaScript.

To use Ngon I can just add the NGonActionFilterAttribute to my RegisterGlobalFilters

<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> RegisterGlobalFilters(GlobalFilterCollection filters)
{
   filters.Add(<span class="kwrd">new</span> NGonActionFilterAttribute());
   filters.Add(<span class="kwrd">new</span> HandleErrorAttribute());
}

So in my controller action I just set the Ngon values.

<span class="kwrd">if</span> (User.Identity.IsAuthenticated)
{
   ViewBag.NGon.UserName = User.Identity.Name;
   ViewBag.NGon.CurrentUserId = WebSecurity.CurrentUserId;
}

In my _Layout.cshtml file I added a @using NGon and a @Html.IncludeNGon() to the <head> section.

@<span class="kwrd">using</span> NGon
&lt;!DOCTYPE html&gt;
&lt;html lang=<span class="str">"en"</span>&gt;
    &lt;head&gt;
        &lt;meta charset=<span class="str">"utf-8"</span> /&gt;
        &lt;title&gt;@ViewBag.Title - My ASP.NET MVC Application&lt;/title&gt;
        &lt;link href=<span class="str">"~/favicon.ico"</span> rel=<span class="str">"shortcut icon"</span> type=<span class="str">"image/x-icon"</span> /&gt;
        &lt;meta name=<span class="str">"viewport"</span> content=<span class="str">"width=device-width"</span> /&gt;
        @Html.IncludeNGon()
        @Styles.Render(<span class="str">"~/Content/css"</span>)
        @Scripts.Render(<span class="str">"~/bundles/modernizr"</span>)
    &lt;/head&gt;
    &lt;body&gt;
...
 

And then I can just use the ngon object like this in my JavaScript

activate = function (callback) {
 
   config.currentUserId = ngon.CurrentUserId;
   config.currentUser = function () { <span class="kwrd">return</span> { id: function () { <span class="kwrd">return</span> ngon.CurrentUserId; } }; };
 
    messenger.publish.viewModelActivated({ canleaveCallback: canLeave });
    getActivityItems(callback);
},

Very elegant solution to the problem.  Ngon is now available as a Nuget package.

ASP.NET Web API replaces WCF Web API

The new MVC 4 beta was released last Thursday / Friday.  One of the big changes is the moving of the WCF Web API into the ASP.NET MVC code stream.

Get the bits and the initial documentation on the ASP.NET Web API page at http://www.asp.net/web-api

The team has provided some initial guidance on migrating from the WCF Web API to ASP.NET Web API on the WCF CodePlex site.

ScottGu has an overview on his blog along with a video of a presentation that he gave at the Belgium and Dutch TechReady events.

Jon Galloway interviewed Brad Wilson about the ASP.NET MVC 4 release.  Brad Wilson on ASP.NET 4 Beta and ASP.NET Web API

Henrik Nielsen the Principal Architect on the WCF Team has a post on the new HttpClient for ASP.NET Web API that has been back ported from .NET 4.5.

I plan on migrating my current project using the WCF Web API and ASP.NET MVC 3 to the new ASP.NET Web API and ASP.NET MVC 4 API this week.  After spending a lot of time last week getting Ninject work work with the WCF Web API, it looks like the ASP.NET Web API makes it trivial.  But it was still a good learning experience right?

I am also contemplating moving to the new .NET 4.5 beta when it is released.  It looks like the asynchronous support on C# 5 will be very useful with the new ASP.NET Web API.