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

ASP.NET MVC 6 Hosting UK - HostForLIFE.eu :: Working with CDN Bundle Config in ASP.NET MVC

clock November 25, 2014 08:20 by author Peter

At this moment, I will tell you about working with CDN bundle config in ASP.NET MVC 6. ASP.NET MVC includes nice attributes and Bundling is part of them. The Bundling and Minification attributes let you scale back quantity of HTTP requests that the web site wants in order to make by combining individual scripts and style sheet files. Additionally it may scale back a general scale bundle by minifying the content material of software. From ASP.NET MVC 4 bundling also contains CDN assistance also where one can utilize public CDN accessible for typical libraries. Let’s look this attributes in particulars.

Libraries such as jQuery, jQuery UI and a few some other libraries are commonly utilized in a lot of the applications. There will be accessible in CDN (Content Delivery Networks) specifying the URL of specific library along with particular version. Bundling now has CDN path as parameter in default bundle functionality where one can specify the path from the CDN library and utilize that. Thus whenever you application operate in production environment first it'll verify regardless of whether CDN can be found or otherwise in case accessible and then it can load it coming from the CDN itself and In case CDN isn't accessible and then it can load files hosted on server. CDN will use the distributed network when enabled, and in optimization mode. You can’t combine multiple CDN’s together (you can only use 1 script). By default. UseCdn is set to false.

And First, you need to Enable UseCdn feature:
bundles.UseCdn = true;

Now, Add the jQuery Bundle from the CDN Bundle with the code bellow:
var jqueryBundle = new ScriptBundle("~/bundles/jquery", "http://code.jquery.com/jquery-2.0.3.min.js").Include(
                "~/Scripts/jquery-{version}.js");
            jqueryBundle.CdnFallbackExpression = "window.jquery";
            bundles.Add(jqueryBundle);


The CdnFallbackExpression is used when even CDN server is unavailable. And next step, this is CDN bundle config:

bundles.UseCdn = true;
            var jqueryBundle = new ScriptBundle("~/bundles/jquery", "http://code.jquery.com/jquery-2.0.3.min.js").Include(
                "~/Scripts/jquery-{version}.js");
            jqueryBundle.CdnFallbackExpression = "window.jquery";
            bundles.Add(jqueryBundle);



ASP.NET MVC 6 Hosting Germany - HostForLIFE.eu :: How To Combine Angular.js with ASP.NET MVC?

clock November 21, 2014 05:31 by author Peter

Angular is a superb resource, however it took me a few time to identify a method to combine it elegantly along with ASP.NET MVC. This is essentially how I made it happen. First, you must build a new ASP.NET MVC app. Next step, install the Angular package through NuGet. Now for the customization.

The goal is to make use of the normal ASP. NET MVC navigation, unless for certain URLs, when we will permit Angular get over. So, http://www.yourdomain.com/Account/Login could be managed by ASP. NET (" ASP.NET-mode "), however http://www.yourdomain.com/#/Customers could be dealt with by Angular (" Angular-mode "). In fact, it is ASP.NET serving us the Customers page, however after that, we wish to use Angular for data-binding, navigation, routing, the forms, and so on.

Add a new Controller along with one method, Index (), which returns View (). Standard ASP. NET up till currently. I named mine AngularController.Next, add a View inside the corresponding folder (in my case :/Angular/Index. cshtml). During this view, found out your primary Angular view. Some thing such as:
@{
    ViewBag.Title = "Index";

<div ng-app="app">
    <div ng-controller="main as vm">
        <div ng-view class="shuffle-animation"></div>
    </div>
</div> 
@section scripts {
    @Scripts.Render("~/bundles/angular")
}

Now, when I am in "Angular-mode", I want my ASP.NET MVC include with Angular scripts. The Angular bundle looks something such as: (in /App_Start/BundleConfig.cs):
bundles.Add(new Bundle("~/bundles/angular").Include(
                      "~/Scripts/angular.js",
                      "~/Scripts/angular-animate.js",
                      "~/Scripts/angular-route.js",
                      "~/Scripts/angular-sanitize.js",
                      "~/Scripts/app/app.js",
                      "~/Scripts/app/config.js",
                      "~/Scripts/app/main.js",
                      "~/Scripts/app/customers/customers.js"));


The explanation I am not using a ScriptBundle is because we don't need ASP.NET to minify the Angular scripts. This leads to errors as a result of Angular generally depends on function arguments being certain strings.

In the meantime, minification is not necessary, however inside a production-environment, you'd need to make use of the minified Angular scripts. In app.js, config. js and main. js, I have place the required code to obtain Angular running. The most significant component is the getRoutes function in config.js :
function getRoutes() {
    return [
        {
            url: '/customers',
            templateUrl: '/Scripts/app/customers/customers.html'
        }
    ];
}


Finally, the customers.html and customers.js include my Angular logic and HTML markup for that particular page. This currently lets you navigate to http://localhost:1578/Angular/#/ (your portnumber may differ of course).

There you've it. ASP.NET MVC is serving the HTML page which contains references to Angular scripts and templates, the browser downloads everything, after which Angular wires all of it along (In fact, you may wish to configure ASP. NET to make use of a totally different URL to the AngularController)

Adding the following code with your navigation is as easy as adding this tag within your _Layout. cshtml file:
<li><a href="https://www.blogger.com/Angular/#/customers">Customers</a></li>

Do not forget the hash. Next, lets add a second page. This'll build the distinction in among what I have been calling " ASP. NET-mode " and " Angular-mode " more clear. Add a new html file and also a new javascript file onto the/Scripts/app/customers/folder, add the route to config. js and add the javascript file in the Angular bundle in BundleConfig. cs. The link inside my case might currently be :
<a href="https://www.blogger.com/Angular/#/customers/create">Create new customer</a>

Next step, whenever you operate the app, navigating from/Angular/#/customers to, say,/Account/Login can load the complete new page. However navigating from/Angular/#/customers to/Anguler/#/customers/create stays inside Angular, and merely loads the new template, " staying within " your SPA. You are able to sort of notice as a result of loading a new page " within " the SPA feels faster. So, we have effectively combined ASP. NET MVC along with Angular.js, allowing us to select where we want/need that.

 



ASP.NET MVC 6 Hosting with Paris (France) Server - HostForLIFE.eu :: Fixing Cached Values when Update Posted Form Values on Postback with ASP.MVC

clock November 18, 2014 08:56 by author Peter

While focusing on a project I encountered a wierd issue on my ASP.NET MVC 6. I produced an easy registration form which posted to my controller method, that obtained a view design like a parameter. Inside my method I had the need to update the values for this View Model prior to passing it to the user through a similar View. But, this really is exactly in which I encountered " strange " outcomes. Regardless of the correct data binding, correct code updating the design values, and also the correct design becoming passed straight into the view, front-end users still obtained the recent form values they initially posted.

This was initially puzzling, because I can notice the model I'd been passing in was the right way up to date. Initially I assumed it was actually some type of caching issue and tried numerous choices, however to no avail. Eventually I found out the matter was coming coming from the Razor Helper I'd been utilizing - specifically the EditorFor method (though this relates to any Razor helper method).

Let us have a closer look. Below is an easy registration view :
@model  posting.Controllers.Guest
 <h2>Register</h2>
 <p>Welcome...</p>
@using (Html.BeginForm())
{
    <table>
        <tr>
            <td>
                @Html.LabelFor(g => g.FirstName)
            </td>
            <td>
                @Html.EditorFor(g => g.FirstName)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(g => g.LastName)
            </td>
            <td>
                @Html.EditorFor(g => g.LastName)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(g => g.Highlight)
            </td>
            <td>
                @Html.EditorFor(g => g.Highlight)
            </td>
        </tr>
    </table>
    <input type="submit" />
}

Now, I set up 2 simple controller methods to demonstrate that error. public ActionResult Register()
{
      return View();
}
[HttpPost]
public ActionResult Register(Guest guest)
{
    guest.FirstName = "Peter";
    return View(guest);

}

The first register method is really a Get request that will returns a simple sign up form using a first name and last name. The 2nd method will be the Post version from the first methodology, which means the values our user enters directly into form are certain to get mapped to our Guest view model. For demonstration purposes, I'm changing all users' names to Peter. But, when you operate this and fill out the form, you may notice the name never comes again as Peter - it constantly comes again as no matter what the user entered. The explanation for right here is the EditorFor helper method. These helper ways retrieve their information from ModelState first, then due to model object which is passed in. ModelState is essentially metadata in regards to the current model assigned from the MVC Model Binder when a request is mapped into your controller. Therefore in case the ModelState presently has values mapped from the MVC Model Binder, Razor Helpers can use those. The answer to get this is easy.
[HttpPost]
public ActionResult Register(Guest guest)
{
    ModelState.Remove("FirstName");
    guest.FirstName = "Peter";
    return View(guest);
}

That is literally all we need to do - this'll eliminate the FirstName property value set from the default MVC Model Binder and permit our personal code to write down a whole new value. You may also clear out the complete ModelState directly, as noticed beneath :
[HttpPost]
public ActionResult Register(Guest guest)
{
    ModelState.Remove("FirstName");
    guest.FirstName = "Peter";
    return View(guest);
}

This is a very simple issue however could be terribly frustrating in case you do not know what is happening.



ASP.NET MVC 6 Hosting with Paris (France) Server - HostForLIFE.eu :: Creating Calendar using ASP.NET MVC, Entity Framework and jQuery

clock November 14, 2014 05:22 by author Peter

Now, I we are going to learn how to create an  Event Calendar using ASP.NET MVC 6, Entity Framework and jQuery Fullcalendar plugin. First thing, that you have to do is Install the full calendar plugin using the Nuget Package Manager with the following command:

Install-Package jQuery.Fullcalendar

After that you'll be able to either add the scripts inside the BundleConfig. cs or you could reference all of these immediately in the _Layout. cshtml page (Master Page)
//Calendar css file
            bundles.Add(new StyleBundle("~/Content/fullcalendarcss").Include(
                     "~/Content/themes/jquery.ui.all.css",
                     "~/Content/fullcalendar.css"));
            //Calendar Script file
            bundles.Add(new ScriptBundle("~/bundles/fullcalendarjs").Include(
                      "~/Scripts/jquery-ui-1.10.4.min.js",
                      "~/Scripts/fullcalendar.min.js"));
@ViewBag.Title - My ASP.NET Application
    @Styles.Render("~/Content/css")
    @Styles.Render("~/Content/fullcalendarcss")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/fullcalendarjs")


Currently Determine the full calendar in the Home/Index.cshtml page. We really need to outline the calendar along with page identity therefore build a div with all the id “calendar”
<div id=”calendar”></div>

Then, you must add the code below, in the Home controller:
public ActionResult GetEvents(double start, double end)
        {
            var fromDate = ConvertFromUnixTimestamp(start);
            var toDate = ConvertFromUnixTimestamp(end);
            //Get the events
            //You may get from the repository also
            var eventList = GetEvents();
            var rows = eventList.ToArray();
            return Json(rows, JsonRequestBehavior.AllowGet);
        }
        private List GetEvents()
        {
            List eventList = new List();
            Events newEvent = new Events{
                id = "1",
                title = "Event 1",
                start = DateTime.Now.AddDays(1).ToString("s"),
                end = DateTime.Now.AddDays(1).ToString("s"),
                allDay = false
            };
            eventList.Add(newEvent);
            newEvent = new Events
            {
                id = "1",
                title = "Event 3",
                start = DateTime.Now.AddDays(2).ToString("s"),
                end = DateTime.Now.AddDays(3).ToString("s"),
                allDay = false
            };
            eventList.Add(newEvent);
            return eventList;       
}      
private static DateTime ConvertFromUnixTimestamp(double timestamp)
        {          
            var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return origin.AddSeconds(timestamp);
        }
Now, Make an Events class under the Models folder:
public class Events
    {
        public string id { get; set; }
        public string title { get; set; }
        public string date { get; set; }
        public string start { get; set; }
        public string end { get; set; }
        public string url { get; set; }
        public bool allDay { get; set; }
    }

Then Add the code below to your page:

@section scripts{
<script type=”text/javascript”>// <![CDATA[
$(document).ready(function () {
$('#calendar').fullCalendar({
theme: true,

defaultView: 'agendaDay',
editable: false,
events: "/home/getevents/"
});
});
// ]]></script>
}



European ASP.NET MVC 6 Hosting - HostForLIFE.eu :: How to Duplicate Controller Names in ASP.NET MVC Areas ?

clock November 11, 2014 07:02 by author Peter

By convention, ASP.NET MVC 6 applications use HomeController to discuss with the controller that handles requests created to the root of the application. this can be designed by default with the subsequent route registration:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

If you choose to partition your application using the ASP.NET MVC Areas feature, it’s commonplace that you simply would need calls to the root of every space to be handled employing a similar convention, via a HomeController.  However, if you add a HomeController to a part (for instance, an Admin area), you'll find yourself faced with this exception:

Multiple types were found that match the controller named ‘Home’. This can happen if the route that services this request (‘{controller}/{action}/{id}’) does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the ‘MapRoute’ method that takes a ‘namespaces’ parameter.

The request for ‘Home’ has found the following matching controllers:
AreaDemo.Areas.Admin.Controllers.HomeController
AreaDemo.Controllers.HomeController

Unfortunately by default you can not have duplicate controller names in ASPNET MVC Areas (or between a part and also the root of the application). fortunately, the fix for this can be pretty easy, and also the exception describes the step you wish to require.  Once you’ve added a part, you may have 2 completely different places (by default) wherever routes are defined: one in your root application and one in your area registration. you may need to regulate each of them to specify a namespace parameter. the root registration will change to one thing like this:
routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    namespaces: new string[] {"AreaDemo.Controllers"}
);

Likewise, at intervals the AdminAreaRegistration.cs class, the default RegisterArea methodology feels like this:
public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Admin_default",
        "Admin/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional}
        );
}

To adjust it to support a default HomeController and namespaces, it ought to be updated like so:
public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Admin_default",
        "Admin/{controller}/{action}/{id}",
        new { controller="Home", action = "Index", id = UrlParameter.Optional},
        new string[] {"AreaDemo.Areas.Admin.Controllers"}
        );
}

With that changes in place, you must currently be ready to support the HomeController convention at intervals your MVC Areas, with duplicate controller names between areas and also the root of the applying.



HostForLIFE.eu Windows Hosting Proudly Launches New Data Center in Paris (France)

clock November 10, 2014 10:57 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 Paris (France) for all costumers. HostForLIFE’s new data center in Paris will address strong demand from customers for excellent data center services in Europe, as data consumption and hosting services experience continued growth in the global IT markets.

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

HostForLIFE.eu expansion into Paris gives us a stronger European market presence as well as added proximity and access to HostForLIFE.eu 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.

The new data center will allow customers to replicate or integrate data between Paris data centers with high transfer speeds and unmetered bandwidth (at no charge) between facilities. Paris 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.

Our network is built from best-in-class networking infrastructure, hardware, and software with exceptional bandwidth and connectivity for the highest speed and reliability. Every upstream network port is multiple 10G and every rack is terminated with two 10G connections to the public Internet and two 10G connections to our private network. Every location is hardened against physical intrusion, and server room access is limited to certified employees.

All of HostForLIFE.eu controls (inside and outside the data center) are vetted by third-party auditors, and we provide detailed reports for our customers own security certifications. The most sensitive financial, healthcare, and government workloads require the unparalleled protection HostForLIFE.eu provides.

Paris data centres meet the highest levels of building security, including constant security by trained security staff 24x7, electronic access management, proximity access control systems and CCTV. HostForLIFE.eu is monitored 24/7 by 441 cameras onsite. All customers are offered a 24/7 support function and access to our IT equipment at any time 24/7 by 365 days a year.

For more information about new data center in Paris, please visit http://hostforlife.eu/Paris-Hosting-Data-Center

About HostForLIFE.eu
HostForLIFE.eu is an European Windows Hosting Provider which focuses on the 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 http://www.asp.net/hosting/hostingprovider/details/953). 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 other European countries. Besides this award, we have also won several awards from reputable organizations in the hosting industry and the detail can be found on our official website.



ASP.NET MVC Hosting UK - HostForLIFE.eu :: How to Create ASPPDF Application with Classic ASP Hosting ?

clock November 7, 2014 08:29 by author Peter

ASPPDF is an active server part written by Persists package INC. With this part you'll dynamically produce, browse and modify portable Document Format (PDF) files. PDF is the de-facto world-wide commonplace for making and exchanging platform-independent printable documents. Giving your ASP.NET MVC / ASP.Net-based web applications the power to come up with and modify PDF documents on the fly opens endless opportunities for you and your users. Our initial application can produce a one-page PDF document, set its Title and Creator properties, and draw the phrase "Hello, World!" in giant helvetica letters across the page.

VBScript
Set Pdf = Server.CreateObject("Persits.Pdf")
Set Doc = Pdf.CreateDocument
Doc.Title = "ASPPDF Chapter 3 Hello World Sample"
Doc.Creator = "Peter"
Set Page = Doc.Pages.Add
Set Font = Doc.Fonts("Helvetica")
Params = "x=0; y=650; width=612; alignment=center; size=50"
Page.Canvas.DrawText "Hello World!", Params, Font
Filename = Doc.Save( Server.MapPath("hello.pdf"), False )
Response.Write "Success! Download your PDF file <A HREF=" & Filename & ">here</A>"

C#
IPdfManager objPdf = new PdfManager();
IPdfDocument objDoc = objPdf.CreateDocument(Missing.Value);
objDoc.Title = "ASPPDF Chapter 3 Hello World Sample";
objDoc.Creator = "Peter";
IPdfPage objPage = objDoc.Pages.Add(Missing.Value, Missing.Value, Missing.Value);
IPdfFont objFont = objDoc.Fonts["Helvetica", Missing.Value];
String strParams = "x=0; y=650; width=612; alignment=center; size=50";
objPage.Canvas.DrawText( "Hello World!", strParams, objFont );
String strFilename = objDoc.Save( Server.MapPath("hello.pdf"), false );
lblResult.Text = "Success! Download your PDF file <A HREF=" + strFilename + ">here</A>";


The primary line creates an instance of the PdfManager object, ASPPDF's top-level object. the subsequent line creates an empty PdfDocument object. The Pdf.CreateDocument technique accepts one optional argument, a document ID string. If no ID is specified , ASPPDF can generate a random one automatically. The document ID argument isn't used.
Doc.Title = "ASPPDF Chapter 3 hello World Sample"
Doc.Creator = "Peter"

That 2 lines above, will set the document's Title and Creator. These values may be viewed in acrobat Reader below File/Document Properties/Summary. different document properties which will be set via the PdfDocument object include Subject, Author, Keywords, Producer, CreationDate and ModDate.
Set Page = Doc.Pages.Add

This line adds a new page to the document. The Pages.Add technique accepts 3 optional arguments: width, Height (in PDF units, one unit equals 1/72 of an inch) and InsertBefore that controls the location of the new page among existing page (not applicable if the document is at the start empty).

By default, the page width and height are 612 and 792, severally, that corresponds to the quality 8.5" x 11" size.

If InsertBefore is omitted, the new page is added to the end of the document. If present, it should be a 1-based index of an existing page within the document.
Set Font = Doc.Fonts("Helvetica")

This line queries the Doc.Fonts collection for a desired font. The default parameterized Fonts..Item property expects a font name as the initial parameter, and a CharSet code because the second optional parameter.
Params = "x=0; y=650; width=612; alignment=center; size=50"
Page.Canvas.DrawText "Hello World!", Params, Font

These 2 lines show the text "Hello World!" in size fifty helvetica on the page. (The auxiliary string variable Params is used for readability functions only. The second argument to Canvas.DrawText might even be an initialized PdfParam object.)

Besides the text and font arguments, 5 numeric arguments are being passed to the DrawText technique. X and Y are always needed, the others are optional in most cases. during this case, text alignment is set to center that makes the width parameter required also.

Filename = Doc.Save( Server.MapPath("hello.pdf"), False )

This line saves the document to disk. the primary argument is required and should be set to a full file path. The second argument is optional. If set to True or omitted, it instructs the Save technique to write an existing file. If set to False, it forces distinctive file name generation. as an example, if the file hello.pdf already exists within the specified  directory and another document is being saved below the same name, the Save technique tries the filenames hello(1).pdf, hello(2).pdf, etc., till a non-existent name is found. The Save method returns the filename (without the path) below that the file was saved.

 



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