print barcode labels in c# Custom ActionResult Objects in VB.NET

Drawing Quick Response Code in VB.NET Custom ActionResult Objects

Custom ActionResult Objects
QR Code ISO/IEC18004 Creator In Visual Basic .NET
Using Barcode creation for .NET Control to generate, create QR Code ISO/IEC18004 image in .NET framework applications.
Denso QR Bar Code Recognizer In VB.NET
Using Barcode reader for .NET Control to read, scan read, scan image in VS .NET applications.
Ultimately, the action result object is a way to encapsulate all the tasks you need to accomplish in particular situations, such as when a requested resource is missing or redirected or when some special response must be served to the browser. Let s examine a few interesting scenarios for having custom action result objects.
Paint Bar Code In Visual Basic .NET
Using Barcode maker for VS .NET Control to generate, create bar code image in VS .NET applications.
Read Bar Code In VB.NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
The PermanentRedirectResult Object
Painting QR Code In Visual C#
Using Barcode generator for .NET framework Control to generate, create Quick Response Code image in VS .NET applications.
QR Code JIS X 0510 Creator In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create Quick Response Code image in ASP.NET applications.
In 8, we discussed permanent redirection as an aspect of a Web application that can have a nontrivial impact on Search Engine Optimization (SEO). Suppose that at some point you decide to expose a given feature of your application through another URL but
QR Code Creator In VS .NET
Using Barcode generator for VS .NET Control to generate, create QR Code image in .NET framework applications.
EAN / UCC - 13 Generation In VB.NET
Using Barcode drawer for VS .NET Control to generate, create EAN / UCC - 14 image in .NET framework applications.
11 Customizing ASP.NET MVC
Encode Matrix 2D Barcode In VB.NET
Using Barcode generation for Visual Studio .NET Control to generate, create 2D Barcode image in .NET framework applications.
Paint PDF417 In VB.NET
Using Barcode encoder for VS .NET Control to generate, create PDF417 image in .NET applications.
still need to support the old URL. To increase your SEO ratio, you might want to implement a permanent redirect instead of a classic (temporary) HTTP 302 redirect. ASP.NET MVC supplies a RedirectResult class, but it lacks a PermanentRedirectResult class. Here s a possible implementation that follows closely that of RedirectResult in ASP.NET MVC 2:
Code 128B Printer In Visual Basic .NET
Using Barcode creator for .NET Control to generate, create Code-128 image in VS .NET applications.
Creating ISBN - 13 In VB.NET
Using Barcode printer for .NET framework Control to generate, create ISBN - 10 image in .NET applications.
public class PermanentRedirectResult : ActionResult { public string Url { get; set; } public bool ShouldEndResponse { get; set; } public PermanentRedirectResult(string url) { if (String.IsNullOrEmpty(url)) throw new ArgumentException("url"); Url = url; ShouldEndResponse = false; } public override void ExecuteResult(ControllerContext context) { // Preconditions if (context == null) throw new ArgumentNullException("context"); if (context.IsChildAction) throw new InvalidOperationException(); // Mark all keys in the TempData dictionary for retention context.Controller.TempData.Keep(); // Prepare the response string url = UrlHelper.GenerateContentUrl(Url, context.HttpContext); HttpResponseBase response = context.HttpContext.Response; response.Clear(); response.StatusCode = 301; response.AddHeader("Location", url); // Optionally end the request if (ShouldEndResponse) response.End(); } }
Recognizing UPC - 13 In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
Code 128C Maker In .NET Framework
Using Barcode generation for Reporting Service Control to generate, create Code 128C image in Reporting Service applications.
By having this class available, you can easily move your features around without affecting the SEO level of your application:
Code39 Generator In Java
Using Barcode creation for Java Control to generate, create Code-39 image in Java applications.
Create QR In None
Using Barcode creation for Font Control to generate, create QR Code image in Font applications.
public ActionResult Old() { string newUrl = "/Home/Index"; return new PermanentRedirectResult(newUrl); }
Making QR Code In Java
Using Barcode generator for Java Control to generate, create QR Code image in Java applications.
Code128 Decoder In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
Figure 11-5 shows the results in FireBug.
Code 128 Code Set B Reader In None
Using Barcode decoder for Software Control to read, scan read, scan image in Software applications.
Draw Data Matrix In C#.NET
Using Barcode printer for .NET framework Control to generate, create DataMatrix image in VS .NET applications.
Part III Programming Features
FIGuRE 11-5 The original URL results are permanently moved.
A Syndication Result Object
If you search the Web for a nontrivial example of an action result, you likely find a syndication action result object at the top of the list. Let s briefly go through this popular example. The class SyndicationResult supports both RSS 2.0 and ATOM 1.0 and offers a handy property for you to choose programmatically. By default, the class produces an RSS 2.0 feed. To compile this example, you need to reference the System.ServiceModel.Web assembly and import the System.ServiceModel.Syndication namespace:
public class SyndicationResult : ActionResult { public SyndicationFeed Feed { get; set; } public FeedType Type { get; set; } public SyndicationResult() { Type = FeedType.Rss; }
11 Customizing ASP.NET MVC
public SyndicationResult( string title, string description, Uri uri, IEnumerable<SyndicationItem> items) { Type = FeedType.Rss; Feed = new SyndicationFeed(title, description, uri, items); } public SyndicationResult(SyndicationFeed feed) { Type = FeedType.Rss; Feed = feed; } public override void ExecuteResult(ControllerContext context) { // Set the content type context.HttpContext.Response.ContentType = GetContentType(); // Create the feed and write it to the output stream var feedFormatter = GetFeedFormatter(); var writer = XmlWriter.Create(context.HttpContext.Response.Output); if (writer == null) return; feedFormatter.WriteTo(writer); writer.Close(); } private string GetContentType() { if(Type == FeedType.Atom) return "application/atom+xml"; return "application/rss+xml"; } private SyndicationFeedFormatter GetFeedFormatter() { if (Type == FeedType.Atom) return new Atom10FeedFormatter(Feed); return new Rss20FeedFormatter(Feed); } } public enum FeedType { Rss = 0, Atom = 1 }
The class gets a syndication feed and just serializes it to the client using either the RSS 2.0 or ATOM 1.0 format. Creating a consumable feed is another story; but it is also a concern that belongs to the controller rather than to the infrastructure. Here s how to write a controller method that returns a feed:
public SyndicationResult Blog() { var items = new List<SyndicationItem>(); items.Add(new SyndicationItem( "Controller descriptors",
Part III Programming Features
"This post shows how to customize controller descriptors", null)); items.Add(new SyndicationItem( "Action filters", "Using a fluent API to define action filters", null)); items.Add(new SyndicationItem( "Custom action results", "Create a custom action result for syndication data", null)); var result = new SyndicationResult( "Programming ASP.NET MVC 2", "Dino's latest book", Request.Url, items); result.Type = FeedType.Atom; return result; }
You create a list of SyndicationItem objects and provide for each a title, some content, and an alternate link (null in the code snippet). You typically retrieve these items from some repository you might have in your application. Finally, you pass items to the SyndicationResult object along with a title and description for the feed to be created and serialized. Figure 11-6 shows an ATOM feed in Internet Explorer.
Copyright © . All rights reserved.