European ASP.NET MVC 4 and MVC 5 Hosting

BLOG about ASP.NET MVC 3, ASP.NET MVC 4, and ASP.NET MVC 5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

HostForLIFE.eu Proudly Launches New Data Center in London (UK) and Seattle (US)

clock July 15, 2014 10:44 by author Peter

HostForLIFE.eu, a leading Windows web hosting provider with innovative technology solutions and a dedicated professional services team proudly announces New Data Center in London (UK) and Seattle (US) for all costumers. HostForLIFE’s new data center in London and Seattle will address strong demand from customers for excellent data center services in Europe and United States, as data consumption and hosting services experience continued growth in the global IT markets.

The new facility will provide customers and their end users with HostForLIFE.eu.com services that meet in-country data residency requirements. It will also complement the existing HostForLIFE.eu. The London and Seattle data center will offer the full range of HostForLIFE.eu.com web hosting infrastructure services, including bare metal servers, virtual servers, storage and networking.

"Our expansion into London and Seattle gives us a stronger European and American market presence as well as added proximity and access to our growing customer base in region. HostForLIFE.eu has been a leader in the dedicated Windows & ASP.NET Hosting industry for a number of years now and we are looking forward to bringing our level of service and reliability to the Windows market at an affordable price,” said Kevin Joseph, manager of HostForLIFE.eu, quoted in the company's press release.

The new data center will allow customers to replicate or integrate data between London and Seattle data centers with high transfer speeds and unmetered bandwidth (at no charge) between facilities. London and Seattle, itself, is a major center of business with a third of the world’s largest companies headquartered there, but it also boasts a large community of emerging technology startups, incubators, and entrepreneurs.

For more information about new data center in London and Seattle, please visit http://www.HostForLIFE.eu

About Company
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.



European ASP.NET MVC Hosting - Greece :: How to Remove IIS Header Bloat in ASP.NET MVC

clock June 26, 2014 09:30 by author Scott

Hi All, how do you do? In this post I will share little bit about how to remove IIS Header Bloat on IIS. This is default ASP.NET project’s response to a request for a page:

Cache-Control:private

Content-Encoding:gzip

Content-Length:3256

Content-Type:text/html; charset=utf-8

Date:Thu, 26 Jun 2014 09:07:59 GMT

Server:Microsoft-IIS/8.0

Vary:Accept-Encoding

X-AspNet-Version:4.0.30319

X-AspNetMvc-Version:4.0

X-Powered-By:ASP.NET

The first thing you need to do is remove X-AspNetMvc-Version header. How? Please just open your Global.asax.cs file to Application_Start, and add this code at the top

MvcHandler.DisableMvcResponseHeader = true;

Then, you can also eliminate the “Server” header by adding a handler to PreSendRequestHeaders event like this:

        protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;
            if (app != null &&
                app.Context != null)
            {
                app.Context.Response.Headers.Remove("Server");
            }
        }

Then, remove the “X-AspNet-Version" header by adding a config key to Web.Config. Here is the key to add (under <system.web>):

    <httpRuntime enableVersionHeader="false" />

The last is remove the X-Powered-By by adding another confing key to Web.Config (under<system.webserver>):

    <httpProtocol>

      <customHeaders>

        <remove name="X-Powered-By" />

      </customHeaders>

    </httpProtocol>

After doing all of this, we end up with a nice and clean response:

Cache-Control:private

Content-Encoding:gzip

Content-Length:3256

Content-Type:text/html; charset=utf-8
Date:Wed, 26 Jun 2014 09:17:09 GMTServer:Microsoft-IIS/8.0

Vary:Accept-Encoding



ASP.NET MVC 6 Hosting Europe - HostForLIFE.eu :: ASP.NET MVC 6 Overview

clock June 16, 2014 13:28 by author Peter

Good News! Microsoft has been released ASP.NET MVC 6 on 12 May 2014 at TechEd North America, as part of ASP.NET vNext, the MVC, Web API, and Web Pages frameworks will be merged into one framework. Microsoft feels that System.Web needs to be removed because it is actually quite expensive. A typical HttpContext object graph can consume 30.000 of memory per request. When working with small JSON-style requests this represents a disproportionately high cost. With ASP.NET MVC 6 new design, the pre-request overhead drops to roughly 2000.

The new ASP.NET MVC 6 assumes you are familiar with either MVC 5 or Web API 2. If not, here is some terminology that is used in ASP.NET MVC. The new framework removes a lot of overlap between the existing MVC and Web API frameworks. It uses a common set of abstractions for routing, action selection, filters, model binding, and so on. You can use the framework to create both UI (HTML) and web APIs.

Features of ASP.NET vNext & ASP.NET MVC 6

  • A controller handles HTTP requests and executes application logic.
  • Actions are methods on a controller that get invoked to handle HTTP requests. The return value from an action is used to construct the HTTP response.
  • Razor syntax is a simple programming syntax for embedding server-based code in a web page.
  • Routing is the mechanism that selects which action to invoke for a particular HTTP request, usually based on the URL path and the HTTP verb.
  • A view is a component that renders HTML. Controllers can use views when the HTTP response contains HTML.
  • ASP.NET vNext includes new cloud-optimized versions of MVC, Web API, Web Pages, SignalR, and Entity Framework.
  • The welcome page is not too interesting, so lets’s enable the app to serve static files.
  • Mono is a Supported Platform. In the past the support story for Mono was essentially “we hope it runs, but if it doesn’t then you need to talk to Xamarin”. Now Microsoft is billing Mono as the official cross-platform CLR for ASP.NET vNext.
  • ASP.NET vNext support true side-by-side deployment. If your application is using cloud-optimized subset of ASP.NET vNext, you can deploy all of your dependencies including the .NET vNext (cloud optimized) by uploading bin to hosting environment.
  • Cross Platform Development. Not only is Microsoft planning for cross-platform deployment, they are also enabling cross-platform development.



ASP.NET MVC 6 Hosting South Africa - HostForLIFE.eu :: How to Create a RSS feed with the new ASP.NET MVC 6

clock June 13, 2014 11:10 by author Peter

Today, we are going to discuss about create RSS feed on ASP.NET MVC 6 Hosting. The RSS classes that we will be describing are available in all types of ASP.NET applications, not only the web-based onces. But we think displaying a blog item on your website is great and relatively simple example of consuming RSS feeds in ASP.NET.

There actually is built-in RSS support in ASP.NET. We have not been aware of that support for some time and occasionally used the third-party library RSS.NET. It turns out that we do not need a separate library any longer. Here is an example MVC controller that refers to the SyndicationFeed and SyndicationItem classes in its Index action method.

using System.Web.Mvc;
using System.ServiceModel.Syndication;
using System.Xml;
using System.Linq;namespace Antrix.Web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            const string feedUrl =
            "http://yourdomain.com/feeds/posts/default?alt=rss";
           SyndicationFeed feed = null;
           using (XmlReader reader = XmlReader.Create(feedUrl))
            {
                feed = SyndicationFeed.Load(reader);
            }
            if (feed != null)
            {
                SyndicationItem item = feed.Items.First<SyndicationItem>();

                ViewBag.RssItem = item;         
            }
           
             return View();
        }
        public ActionResult About()
        {
            return View();
       }
    }
}

The Index method will reads a feed of the site that you are reading right now. It puts the first item (which we assume represents the last post that has been published) in the ViewBag. Normally we use model classes to refer to data within my MVC views, but we want to keep things simple. We have added code to show the title and summary of the last post, and a link to the full post.

@{
    ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
<p>

    To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
<div>

From our blog:  
<div style="font-weight: bold; padding: 10px">@ViewBag.RssItem.Title.Text</div>
<div style="clear: both; padding: 10px">@Html.Raw(@ViewBag.RssItem.Summary.Text)</div>
<div style="clear: both; padding: 10px"><a href="@ViewBag.RssItem.Links[0].Uri" target="_blank">Show full post</a></div>
</div>

Using the SyndicationFeed and SyndicationItem classes it becomes rather easy to create your own web-based (or Windows-based, if you prefer) RSS reader.



HostForLIFE.eu Announces Release of ASP.NET MVC 5.2 Hosting only €1.29/ month

clock June 6, 2014 08:59 by author Peter

HostForLIFE.eu, an European Recommended Windows and ASP.NET Spotlight Hosting Partner in Europe, Today has announced the availability of newest hosting plans that are optimized for the latest update of the Microsoft ASP.NET MVC 5.2 technology. HostForLIFE.eu - an affordable , high uptime, excellent customer service, quality and also reliable hosting provider in advanced Windows and ASP NET technology. HostForLIFE.eu proudly announces the availability of the ASP.NET MVC 5.2 hosting in our entire servers environment.

ASP.NET MVC 5.2 hosting includes great new features for Web API OData v4 as summarized below but has bug fixes and minor features that bring in a lot more goodness to MVC, Web API, and Web Pages. Only paying €1.29/month, The customers can get professional and high skilled support ASP NET MVC 5 .2  with HostForLIFE.eu. Really, there are many benefits when you host your site with them. We can fully guarantee you that HostForLIFE.eu will provide the best quality hosting services.

In ASP.NET MVC 5.2, Customizing IDirectRouteProvider will be more easy by extending our default implementation, DefaultDirectRouteProvider. This class provides separate overridable virtual methods to change the logic for discovering attributes, creating route entries, and discovering route prefix and area prefix.

HostForLIFE.eu claims to be the fastest growing ASP.NET MVC Hosting and Windows Hosting service provider in Europe continet. The company has its servers situated in Amsterdam and it offers the latest servers working on Dual Xeon Processor, fastest connection line of 1000 Mbps, and minimum 8 GB RAM. All these new servers are laced with the most recent versions of Windows Server 2012, ASP.NET 4.5.2 , Silverlight 5, Visual Studio Lightswitch, SQL Server 2012 and the lates SQL Server 2014, the latest ASP.NET MVC 5.2 & Previous and support various WebMatrix Applications.

For additional information about ASP NET MVC 5.2 Hosting offered by HostForLIFE, please visit http://hostforlife.eu/European-ASPNET-MVC-52-Hosting

About HostForLife.eu:

HostForLIFE.eu was established to cater to an under served market in the hosting industry; web hosting for customers who want excellent service. This is why HostForLIFE continues to prosper throughout the web hosting industry’s maturation process.

HostForLife.eu is Microsoft No #1 Recommended Windows and ASP.NET Hosting in European Continent. Our service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and many top European countries.



European ASP.NET MVC 5 Cloud Hosting - Austria :: Implementation ASP.NET MVC 5 Authentication Filters

clock June 5, 2014 09:01 by author Scott

ASP.NET MVC 5 offer many great new features. In today post, I will share one of the new ASP.NET MVC 5 feature which is called Authentication Filters and ASP.NET identity Management. ASP.NET MVC does not provide any built-in authentication filter(s). However it provides you with the framework, so you can easily create your own custom authentication filters.

 

In previous ASP.NET MVC 4, maybe you use AuthorizationFilters. New authentication filters run prior to authorization filters. It is also worth noting that these filters are the very first filters to run before any other filters get executed.

Why Use Authentication Filters?

Prior to authentication filters, developers used the Authorization filters to drive some of the authentication tasks for the current request. It was convenient because the Authorization filters were executed prior to any other action filters.  For example, before the request routes to action execution, we would use an Authorization filter to redirect an unauthenticated user to a login page. Another example would be to use the Authorization filter to set a new authentication principal, which is different from the application’s original principal in context.

Authentication related tasks can now be separated out to a new custom authentication filter and authorization related tasks can be performed using authorization filters. So it is basically about separating of concerns, while giving developers more flexibility to drive authentication using ASP.NET MVC infrastructure.

The Implementation ASP.NET MVC Authentication Filters

If you've done any development with ASP .NET MVC, you've more than likely used the Authorization attribute to enforce role-based security within your Web site. With MVC 5, you can now apply an Authentication filters to your controller to allow users to authenticate to your site from various third-party vendors or a custom authentication provider.

When applied to an entire controller class or a particular controller action, Authentication filters are applied prior to any Authorization filters. Let's see an Authentication filter in practice. Create a new C# ASP .NET Web Application, see Figure below.

Then, select ASP.NET project type.

Let's first look at how to implement a custom authentication filter that will simply redirect the user back to the login page if they're not authenticated. Create a new directory named CustomAttributes in your project. Next, create a new class named CustomAttribute that inherits from ActionFilterAttribute and IAuthenticationFilter:

public class BasicAuthAttribute: ActionFilterAttribute, IAuthenticationFilter

The IAuthenticationFilter interface defines two methods: OnAuthentication and OnAuthenhenticationChallenge. The OnAuthentication method is executed first and can be used to perform any needed authentication. The OnAuthenticationChallenge method is used to restrict access based upon the authenticated user's principal.

 For this simple example, I'll only be implementing the OnAuthenticationChallenge method and will leave the OnAuthenitcation method blank:

public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
    var user = filterContext.HttpContext.User;
    if (user == null || !user.Identity.IsAuthenticated)
    {
        filterContext.Result = new HttpUnauthorizedResult();
    }
}

Here's the complete BasicAuthAttribute implementation:

using System.Web.Mvc;
using System.Web.Mvc.Filters;

namespace VSMMvc5AuthFilterDemo.CustomAttributes
{
    public class BasicAuthAttribute : ActionFilterAttribute, IAuthenticationFilter
    {
        public void OnAuthentication(AuthenticationContext filterContext)
        {
        }

        public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
        {
            var user = filterContext.HttpContext.User;
            if (user == null || !user.Identity.IsAuthenticated)
            {
                filterContext.Result = new HttpUnauthorizedResult();
            }
        }
    }
}

You can now test out the BasicAuthAttribute by applying it to the HomeController class. Open up the HomeController class file, then add a using statement for your CustomAttributes namespace:

using VSMMvc5AuthFilterDemo.CustomAttributes;

Then apply the custom attribute to the HomeController class:

[BasicAuthAttribute]
public class HomeController : Controller

When you run the application, you should now be automatically redirected to the login page

In order to view the homepage, you must register a user account

Once your user is registered, you'll be automatically redirected to the homepage

As you can see, it isn't overly complex to implement a custom authentication filter within ASP.NET MVC 5.

Summary

The new IAuthenticationFilter provides a great ability to customize authentication within an ASP.NET MVC 5 application. This provides a clear separation between authentication and authorization filters. OnAuthentication and OnAuthenticationChallenge methods provide greater extensibility points to customize authentication within ASP.NET MVC framework. We also looked at a sample usage of CustomAuthentication attribute and how you can use to change the current principal and redirect un authenticated user to a login page.



HostForLIFE.eu Announces Release of Cheap Dedicated Windows Cloud Server Hosting Plans

clock June 3, 2014 09:13 by author Peter

European leading web hosting provider, HostForLIFE.eu announced cheap dedicated Windows cloud server due to high demand of Windows cloud server users in Europe.

Windows & ASP.NET hosting provider HostForLIFE.eu announced cheap dedicated Windows cloud server hosting plans. HostForLIFE.eu offers the ultimate performance and flexibility at an economical price for windows cloud server. HostForLIFE.eu cheap dedicated Windows cloud server hosting plans starts from just as low as €16.00/month only.

HostForLIFE.eu provisions all dedicated Windows Cloud Server in just few minutes (upon payment verification and completion). HostForLIFE.eu has a very strong commitment to introduce their Cheap dedicated Windows and ASP.NET Cloud Server hosting service to the worldwide market. HostForLIFE.eu starts to target market in Europe. HostForLIFE.eu will be the one-stop cheap dedicated Windows and ASP.NET Cloud Server Hosting Solution for every ASP.NET enthusiast and developer.

HostForLIFE’s cheap dedicated Windows Dedicated Cloud Server hosting plan comes with the following features: Windows 2008R2/2012, Data Center OS Version, 1 x vCPU, 1 GB RAM, You have full root access to the server 24/7/365, 40 GB Storage (SSD), 1000 GB Bandwidth, 1000 Mbps Connection, 1 Static IP and SAN Storage.

For additional information on this cheap Windows dedicated cloud server Hosting plan, please visit http://hostforlife.eu/European-Cheap-Windows-Cloud-Server-Plans

About HostForLIFE.eu:
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. HostForLIFE.eu deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

HostForLIFE.eu is awarded Top No#1 SPOTLIGHT Recommended Hosting Partner by Microsoft (see www.microsoft.com/web/hosting/HostingProvider/Details/953). Their service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and other European countries. Besides this award, they have also won several awards from reputable organizations in the hosting industry and the detail can be found on their official website.



FREE Trial Cloud ASP.NET MVC Hosting - France :: Creating PDF Report Using ITextPDF in ASP.NET MVC Project

clock May 28, 2014 09:24 by author Scott

In this blog you will see how easy it is to build a report in an ASP.Net MVC application using a free IText PDF libraries.  By the way,  this project is still ASP.Net Webforms MVC 2, if you are already using Razor don’t just cut and paste the sample code, just get the jest and re-write it to suite to your project.

The first step is to add the libraries in your Visual Studio 2013 project by simply using the Manage NuGet Packages.

Once the libraries are installed, just create a controller.  In my example, I named my controller SysReport because I want it to be a generic report controller for all my reporting needs.  The code contains one GET method and a bunch of private methods that returns a PDF MemoryStream created by ITextPDF.

using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using System.Web.Http; 

namespace wfmis.Controllers
{
    public class SysReportController : ApiController
    {
        public HttpResponseMessage Get()
        {
            NameValueCollection nvc = HttpUtility.ParseQueryString(Request.RequestUri.Query);
            string Report = nvc["Report"].ToString();
            Int64 Id = Convert.ToInt64(nvc["Id"]);
            var response = new HttpResponseMessage(HttpStatusCode.OK); 

            switch (Report)
            {
                case "PurchaseOrder":
                    response.Content = new StreamContent(this.PurchaseOrder(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

                    break;
                case "PurchaseInvoice":
                    response.Content = new StreamContent(this.PurchaseInvoice(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    break;
                case "Disbursement":
                    response.Content = new StreamContent(this.Disbursement(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    break;
                case "SalesOrder":
                    response.Content = new StreamContent(this.SalesOrder(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    break;
                case "SalesInvoice":
                    response.Content = new StreamContent(this.SalesInvoice(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    break;
                case "Collection":
                    response.Content = new StreamContent(this.Collection(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    break;
                case "JournalVoucher":
                    response.Content = new StreamContent(this.JournalVoucher(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    break;
                case "StockIn":
                    response.Content = new StreamContent(this.StockIn(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    break;
                case "StockOut":
                    response.Content = new StreamContent(this.StockOut(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    break;
                case "StockTransfer":
                    response.Content = new StreamContent(this.StockTransfer(Id));
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                    break;
            } 

            return response;
        }
    }
}

The second part of the controller is the method that creates the report itself.  Noticed that in the above code I highlighted two lines, the first line, calls the method that creates the byte stream while the second line informs the controller what is the content type, those are the methods.  I cannot paste the entire code that contains all the methods because it will take a lot of typing space, what I can paste is just one sample method, PurchaseInvoice.

private MemoryStream PurchaseInvoice(Int64 Id)
{
    var doc = new Document(PageSize.LETTER, 50, 50, 25, 25);
    var stream = new MemoryStream(); 

    try
    {
        BaseFont BaseFontTimesRoman = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
        Font TitleFont = new Font(BaseFontTimesRoman, 18, Font.BOLD);
        Font SubTitleFont = new Font(BaseFontTimesRoman, 14, Font.BOLD);
        Font TableHeaderFont = new Font(BaseFontTimesRoman, 10, Font.BOLD);
        Font BodyFont = new Font(BaseFontTimesRoman, 10, Font.NORMAL);
        Font EndingMessageFont = new Font(BaseFontTimesRoman, 10, Font.ITALIC); 

        PdfWriter writer = PdfWriter.GetInstance(doc, stream); 

        writer.PageEvent = new PDFHeaderFooter("Purchase Invoice"); 

        var PurchaseInvoices = from d in db.TrnPurchaseInvoices where d.Id == Id select d; 

        doc.Open(); 

        var HeaderTable = new PdfPTable(2);
        HeaderTable.HorizontalAlignment = 0;
        HeaderTable.SpacingBefore = 20;
        HeaderTable.SpacingAfter = 10;
        HeaderTable.DefaultCell.Border = 0;
        HeaderTable.SetWidths(new int[] { 2, 6 }); 

        HeaderTable.AddCell(new Phrase("PI Number:", TableHeaderFont));
        HeaderTable.AddCell(new Phrase(PurchaseInvoices.First().PINumber, BodyFont));
        HeaderTable.AddCell(new Phrase("PI Date:", TableHeaderFont));
        HeaderTable.AddCell(new Phrase(PurchaseInvoices.First().PIDate.ToShortDateString(), BodyFont));
        HeaderTable.AddCell(new Phrase("Supplier:", TableHeaderFont));
        HeaderTable.AddCell(new Phrase(PurchaseInvoices.First().MstArticle.Article, BodyFont));
        HeaderTable.AddCell(new Phrase("Term:", TableHeaderFont));
        HeaderTable.AddCell(new Phrase(PurchaseInvoices.First().MstTerm.Term, BodyFont));
        HeaderTable.AddCell(new Phrase("Document Reference:", TableHeaderFont));
        HeaderTable.AddCell(new Phrase(PurchaseInvoices.First().DocumentReference, BodyFont)); 

        doc.Add(HeaderTable); 

        var DetailTable = new PdfPTable(7);
        DetailTable.HorizontalAlignment = 0;
        DetailTable.SpacingAfter = 10;
        DetailTable.DefaultCell.Border = 0;
        DetailTable.SetWidths(new int[] { 2, 2, 6, 3, 3, 3, 3 });
        DetailTable.WidthPercentage = 100;
        DetailTable.DefaultCell.Border = Rectangle.BOX; 

        DetailTable.AddCell(CreateCenterAlignedCell("Qty", TableHeaderFont, 1));
        DetailTable.AddCell(CreateCenterAlignedCell("Unit", TableHeaderFont, 1));
        DetailTable.AddCell(CreateCenterAlignedCell("Item", TableHeaderFont, 1));
        DetailTable.AddCell(CreateCenterAlignedCell("Particulars", TableHeaderFont, 1));
        DetailTable.AddCell(CreateCenterAlignedCell("Cost", TableHeaderFont, 1));
        DetailTable.AddCell(CreateCenterAlignedCell("Tax", TableHeaderFont, 1));
        DetailTable.AddCell(CreateCenterAlignedCell("Amount", TableHeaderFont, 1)); 

        decimal TotalAmount = 0;
        if (PurchaseInvoices.First().TrnPurchaseInvoiceLines.Any())
        {
            foreach (var Line in PurchaseInvoices.First().TrnPurchaseInvoiceLines)
            {
                DetailTable.AddCell(CreateRightAlignedCell(Line.Quantity.ToString("#,##0.#0"), BodyFont,1));
                DetailTable.AddCell(new Phrase(Line.MstUnit.Unit, BodyFont));
                DetailTable.AddCell(new Phrase(Line.MstArticle.Article, BodyFont));
                DetailTable.AddCell(new Phrase(Line.Particulars, BodyFont));
                DetailTable.AddCell(CreateRightAlignedCell(Line.Cost.ToString("#,##0.#0"), BodyFont,1));
                DetailTable.AddCell(new Phrase(Line.MstTax.TaxCode, BodyFont));
                DetailTable.AddCell(CreateRightAlignedCell(Line.Amount.ToString("#,##0.#0"), BodyFont,1)); 

                TotalAmount = TotalAmount + Line.Amount;
            }
        } 

        DetailTable.AddCell(CreateCenterAlignedCell("TOTAL", TableHeaderFont, 6));
        DetailTable.AddCell(CreateRightAlignedCell(TotalAmount.ToString("#,##0.#0"), TableHeaderFont, 1)); 

        doc.Add(DetailTable); 

        var SignatureTable = new PdfPTable(3);
        SignatureTable.HorizontalAlignment = 0;
        SignatureTable.SpacingBefore = 10;
        SignatureTable.SpacingAfter = 10;
        SignatureTable.SetWidths(new int[] { 6, 6, 6 });
        SignatureTable.WidthPercentage = 100;
        SignatureTable.DefaultCell.Border = Rectangle.BOX; 

        SignatureTable.AddCell(CreateLeftAlignedCell("Prepared By:", TableHeaderFont, 1));
        SignatureTable.AddCell(CreateLeftAlignedCell("Checked By: ", TableHeaderFont, 1));
        SignatureTable.AddCell(CreateLeftAlignedCell("Approved By:", TableHeaderFont, 1)); 

        PdfPCell cell1 = new PdfPCell(new Phrase(PurchaseInvoices.First().MstUser.FullName, BodyFont)) { HorizontalAlignment = PdfPCell.ALIGN_CENTER, VerticalAlignment = PdfPCell.ALIGN_BOTTOM };
        PdfPCell cell2 = new PdfPCell(new Phrase(PurchaseInvoices.First().MstUser1.FullName, BodyFont)) { HorizontalAlignment = PdfPCell.ALIGN_CENTER, VerticalAlignment = PdfPCell.ALIGN_BOTTOM };
        PdfPCell cell3 = new PdfPCell(new Phrase(PurchaseInvoices.First().MstUser2.FullName, BodyFont)) { HorizontalAlignment = PdfPCell.ALIGN_CENTER, VerticalAlignment = PdfPCell.ALIGN_BOTTOM }; 

        cell1.FixedHeight = 50f;
        cell2.FixedHeight = 50f;
        cell3.FixedHeight = 50f; 

        SignatureTable.AddCell(cell1);
        SignatureTable.AddCell(cell2);
        SignatureTable.AddCell(cell3); 

        doc.Add(SignatureTable); 

        doc.Close();
    }
    catch { } 

    byte[] file = stream.ToArray();
    MemoryStream output = new MemoryStream();
    output.Write(file, 0, file.Length);
    output.Position = 0; 

    return output;
}

Now it may look gruesome at first, because it is 100% hardcore code to create a report, but once you start writing it down you will get a familiarity of the ITextPDF libraries, which is very powerful and customizable, the code will be clearer and understandable.  I hightlighted a single line above because this line is optional, it is just merely overloading the PdfPageEventHelper class to create a header and footer of the report.  I will discuss this soon in my future blogs.

In order also to fully understand the code, below is the sample actual output report created by the code.

And the last step is to call the controller in your views, it turns out, it is very simple as shown in the sample Javascript code below.

function cmdPrint_onclick()
   {
      if ($Id &gt; 0)
      {
         window.location.href = '/api/SysReport?Report=PurchaseInvoice?Id=' + $Id;
      }
}

Hope this blog helpful.



FREE Trial ASP.NET MVC 5.1.2 Hosting - Germany :: What's New in ASP.NET MVC 5.1.2?

clock May 21, 2014 08:02 by author Scott

Just check on Microsoft site and Microsoft has launched new ASP.NET MVC 5.1.2. Microsoft also announces the availability ASP.NET 4.5.2. Just check the preview of ASP.NET 4.5.2 here and Microsoft official site.

So, what’s new in ASP.NET MVC 5.1.2?

You can download the packages through NuGet. You can get the latest ASP.NET MVC 5.1.2 version. The release also includes corresponding localized packages on NuGet.

You can install or update to the released NuGet packages by using the NuGet Package Manager Console:

Install-Package Microsoft.AspNet.Mvc -Version 5.1.2

Interesting Feature in ASP.NET MVC 5.1.2:

Attribute routing improvements

Attribute routing now supports constraints, enabling versioning and header based route selection. Many aspects of attribute routes are now customizable via the IDirectRouteFactory interface and RouteFactoryAttribute class. The route prefix is now extensible via the IRoutePrefix interface and RoutePrefixAttribute class.

Enum support in views

1. New @Html.EnumDropDownListFor() helper methods.
2. New EnumHelper.GetSelectList() methods which return an IList<SelectListItem>.

If you want to see how to implement this new feature, please see the complete example here.

Bootstrap support for editor templates

ASP.NET MVC 5.1.2 allow passing in HTML attributes in EditorFor as an anonymous object.

Unobtrusive validation for MinLengthAttribute and MaxLengthAttribute

Client-side validation for string and array types will now be supported for properties decorated with the MinLength and MaxLength attributes.

Supporting the ‘this’ context in Unobtrusive Ajax

The callback functions (OnBegin, OnComplete, OnFailure, OnSuccess) will now be able to locate the invoking element via the this context.

Cheap hosting for ASP.NET MVC 5.1.2

If you want to try out this new feature of ASP.NET MVC 5.1.2, you can start your affordable ASP.NET MVC 5.1.2 hosting with us. We have also launches new packages which is more affordable and start from only €1.29/month. For more information about our hosting plan, please visit our official site at http://hostforlife.eu/ASPNET-Shared-European-Hosting-Plans.



HostForLIFE.eu offers €1.29/month Affordable and High Performance Windows & ASP.NET Shared Hosting Plan

clock May 20, 2014 11:53 by author Peter

European Windows and ASP.NET hosting specialist, HostForLIFE.eu, has officially launched the new Windows & ASP.NET Shared Hosting Plan offered from as low as €1.29/month only. This LITE Windows & ASP.NET Hosting packages combine generous or 1 website, 1 GB disk space, 10 GB bandwidth, Support UTF-8 Domains, Dedicated Pool, etc. As the market for hosted solutions continues to grow, the new hosting range is designed to exceed the growing technical demands of businesses and IT professionals.

HostForLIFE.eu  is confident that their new LITE shared hosting plans will surely appeal to the personal across the world, besides the website owners and companies owning websites. The new web hosting plans will meet the requirement of high performance web hosting where one can easily update the content of a website on a regular basis. This plan is designed more for the web hobbiest needing affordable, high availability, hosting and easy backend management of windows and ASP.NET with powerful Plesk control panel.

Every day thousands of people decide to set up a website for business or personal use. New business owners and the average consumer don’t always have access to unlimited budgets. HostForLIFE.eu understand the importance of reliable hosting but are not always prepared to pay the exorbitant prices that reliable hosts charge.

For additional information about LITE Shared Hosting Plan offered by HostForLIFE.eu, please visit http://hostforlife.eu

About HostForLIFE.eu:

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. HostForLIFE.eu  deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

HostForLIFE.eu is awarded Top No#1 SPOTLIGHT Recommended Hosting Partner by Microsoft (see www.microsoft.com/web/hosting/HostingProvider/Details/953). Their service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and other European countries. Besides this award, They have also won several awards from reputable organizations in the hosting industry and the detail can be found on their official website.



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in