CheapWindowsHostingReview.com |Best and cheap ASP.NET Core 1.0 hosting. If you are searching for the best web hosting service online, read all our updated Web Hosting Reviews & Comparison 2017 to ensure you make a well informed decision. On this page we have investigated and reviewed all the major web hosting companies so you can easily differentiate features, pricing, support, service uptime and customer feedback. Every review was taken around the last 6 months and each hosting provider is reviewed on regular basis. If you have any experience with these website hosts services please feel free to write your own review of their service to help other people to find the best web hosting service for their online business. Our web hosting comparisons and reviews include customer support, features, pricing, value for money, security and reliability. All the best and we hope we help you to find your perfect hosting partner.
To choose the best Windows hosting for your websites, we will compare two of this India Windows hosting providers in the industry. This WindowsASPNETHosting.in VS IndiaLinks comparison is about to make clear that who is a better option ASP.NET Core 1.0 Hpsting in India.
India Windows Hosting Review
Item
WindowsASPNETHosting.in
IndiaLinks
Price
*****
***
Features
*****
*****
Uptime
*****
****
Speed
*****
****
Technical Support
*****
****
WindowsASPNETHosting.in is the India’s #1 Windows hosting provider that offers the most reliable world class Windows hosting solutions for customers. WindowsASPNETHosting.in provides high quality affordable India’s Windows hosting services for personal and companies of all sizes. You can host your website with an innovative, reliable, and a friendly India’s Windows hosting company who cares about your business.
Indialinks Founded in 1997 Based in Mumbai, India Industry Leader in Managed Hosting Solutions. They are providing now web hosting on Linux, Window, Window reseller hosting, Linux Reseller hosting, VPS Hosting. They also treat their costumer as family member and costumer’s trouble as their own trouble.
WindowsASPNETHosting.in VS IndiaLinks: Pricing & Features
WindowsASPNETHosting.in releases four plans called Personal, Developer, Business and Expert at the prices of INR 159.99/month35% OFF , INR 299.99/month35% OFF , INR 679.99/month35% OFF andINR 1099.99/month35% OFF . Three billing cycles with different prices are available in WindowsASPNETHosting.in best India Windows hosting package. You can choose between 3-months, 1-year, 3-years and 5-years payment methods. WindowsASPNETHosting.in also supports 30-days money back guarantee. On the contrary, IndiaLinks offers several kinds of India Windows hosting plan starting from $149.99/mo in regular time. IndiaLinks only provide the costumers yearly payment method.
In below, we create a feature-comparison table of this two best India Windows hosting companies:
From the above comparison list, both of them are fully ASP.NET compatible. However, WindowsASPNETHosting.in and IndiaLinks are different from each other in many features. They both support the .NET technology, like Windows Server, IIS, isolated application pool, LINQ, AJAX, Silverlight, Full Trust, URL rewrite module. But WindowsASPNETHosting.in supports almost all version of Windows Server, ASP.NET, ASP.NET MVC, IIS and MSSQL database. WindowsASPNETHosting.in also supports ASP.NET Core 1.0 hosting with affordable price. What’s more WindowsASPNETHosting.in also provides unlimited domain while IndiaLinks still limit their domain. From the above table, we can conclude that WindowsASPNETHosting.in has more rich-featured India Windows hosting that what IndiaLinks has offered.
WindowsASPNETHosting.in VS IndiaLinks: Uptime & Speed
To ensure uptime and speed, both WindowsASPNETHosting.in and IndiaLinks have been investing much money and time. WindowsASPNETHosting.in leverages best-in-class connectivity and technology to innovate industry-leading, fully automated solutions that empower enterprises with complete access, control, security, and scalability. They own and operate three world-class data centers strategically located in Mumbai (India), London (UK) and Washington D.C.(US). WindowsASPNETHosting.in promise you in delivering 99.9% uptime. When it comes to IndiaLinks, they also located their data center in Chennai, Tamil Nadu and promise 99.9% uptime guarantee. However, most of IndiaLinks’s costumers are disappointed because of their slow speed website.
WindowsASPNETHosting.in VS IndiaLinks: Technical Support
WindowsASPNETHosting.in offers 24/7 support through tickets, e-mail and contact form. When we contacted the their support representatives via e-mail, we got responses from WindowsASPNETHosting.in within an average of 5 minutes. In the other hand, IndiaLinks only provide phone call for their costumer. We’ve tried to call their support but they always show the busy tune. We do believe that WindowsASPNETHosting.in has more responsive support team.
Conclusion: WindowsASPNETHosting.in VS IndiaLinks?
From the combination of high performance, responsive support, rich-featured hosting and reasonable pricing, we conclude that WindowsASPNETHosting.in is better in serving India Windows hosting. It is clear that WindowsASPNETHosting.in is a more favorable choice due to its cost-effective features and considerate customer service.
CheapASPNETHostingReview.com| Best and cheap ASP.NET Core 1.0 hosting. In this article, we will review how to deploy an ASP.NET Core application to IIS. Deploying an ASP.NET Core app to IIS isn’t complicated, but ASP.NET Core hosting is a little different than ASP.NET.
How to Configure Your ASP.NET Core App For IIS
The first thing you will notice when creating a new ASP.NET Core project is they are actually console applications. Your project now contains a Program.cs file just like a console app would have and it contains the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
publicclassProgram
{
publicstaticvoidMain(string[]args)
{
varhost=newWebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup()
.Build();
host.Run();
}
}
What is the WebHostBuilder?
All ASP.NET Core applications require a WebHost object that essentially serves as the application and web server. WebHostBuilder is used to configure and create the WebHost. You will normally see UseKestrel() and UseIISIntegration() in the WebHostBuilder setup code.
What do these do?
UseKestrel() – This registers the IServer interface for Kestrel as the server that will be used to host your application. In the future, there could be other options, including WebListener which will be Windows only.
UseIISIntegration() – This tells ASP.NET that IIS will be working as a reverse proxy in front of Kestrel. This then specifies some settings around which port Kestrel should listen on, forwarding headers, and other details.
If you are planning to deploy your application to IIS, UseIISIntegration() is required
What is AspNetCoreModule?
You may have noticed that ASP.NET Core projects create a web.config file. This is only used when deploying your application to IIS. It registers the AspNetCoreModule as an HTTP handler.
Default web.config for ASP.NET Core:
If you are planning to deploy your application to IIS, UseIISIntegration() is required
AspNetCoreModule handles all incoming traffic to IIS and acts as the reverse proxy that knows how to hand the traffic off to your ASP.NET Core application. You can view the source code of it on GitHub. It also ensures that your web application is running. It is responsible for starting your process up.
Install .NET Core Windows Server Hosting Bundle
Before you deploy your application, you need to install the .NET Core hosting bundle for IIS. This will install the .NET Core runtime, libraries, and the ASP.NET Core module for IIS.
After installing it, you may need to do a “net stop was /y” and “net start w3svc” to ensure all the changes are picked up for IIS.
Steps to Deploy ASP.NET Core to IIS
Before you deploy, you need to make sure that WebHostBuilder is configured properly to use Kestrel and IIS. Your web.config should also exist and look similar to our example above.
Step 1: Publish to a File Folder
Step 2: Copy Files to Preferred IIS Location
Now you need to copy your publish output to where you want the files to live. If you are deploying to a remote server, you may want to zip up the files and move to the server. If you are deploying to a local dev box, you can copy them locally.
For my example, I am copying the files to C:\inetpub\wwwroot\AspNetCore46
You will notice that with ASP.NET core there is no bin folder and it potentially copies over a ton of different .NET dlls. Your application may also be an EXE file if you are targeting the full .NET Framework. My little sample project had over 100 dlls in the output.
Step 3: Create Application in IIS
First, create a new IIS Application Pool. You will want to create one under the .NET CLR version of “No Managed Code“. Since IIS only works as a reverse proxy, it isn’t actually executing any .NET code.
Second, create your new application under your existing IIS Site, or create a new IIS site. Either way, you will want to pick your new IIS Application Pool and point it at the folder you copied your ASP.NET publish output files to.
Step 4: Load Your App!
At this point, your application should load just fine. If it does not, check the output logging from it. Within your web.config file you define how IIS starts up your ASP.NET Core process. Enable output logging by setting stdoutLogEnabled=true and you may also want to change the log output location as configured in stdoutLogFile. Check out the example web.config before to see where they are set.
Advantages of Using IIS with ASP.NET Core Hosting
Microsoft recommends using IIS with any public facing site for ASP.NET core hosting. IIS provides additional levels of configurability, management, security, logging, and many other things. Check out my blog post about Kestrel vs IIS to see a whole matrix of feature differences. It goes more in depth about what Kestrel is and why you need both Kestrel & IIS.
One of the big advantages to using IIS is the process management. IIS will automatically start your app and potentially restart it if a crash were to occur. If you were running your ASP.NET Core app as a Windows Service or console app, you would not have that safety net there to start and monitor the process for you.
CheapASPNETHostingReview.com | Best and cheap ASP.NET Core 1.0 hosting. In this article, we will use Visual Studio 2017 and Entity Framework Core step by step to learn how we can:
Change Identity table names.
Change Identity table property names.
Change Identity table datatype of primary key.
When you decide to use ASP.NET Core Identity it will generate some tables used to store data for users and other things.
Prior to it, let’s take a brief definition about ASP.NET Core Identity.
Released on 2016 and from the name we can say it’s all about identity of the users, you can manage login and Logout functionality, create an account also you can use external login providers such as Facebook, Google, Microsoft Account and Twitter. In other words, you can say, it gives you the ability to make an authentication and an authorization.
Let us see it in action
Open your Visual Studio 2017
I am using an Enterprise edition but you can use any edition, which is available to you.
File > New > Project
Click ASP.NET Core Web Application and give it a name, as shown below.
Select Web Application.
Click Change authentication, select an individual user account and click OK, as shown below.
Now, we have an Application but we need to make migration and we have several ways to achieve it. We will use Package Manager, as shown below
Now, you need to create the database. Go to appsettings.json file and edit your connection string, if you want. I am using SQL Server 2016, so this is my appsettings.json file and it looks, as shown below.
1
2
3
4
5
6
7
8
9
10
11
{
"ConnectionStrings":{
"DefaultConnection":"Server=localhost;Database=aspnet-IdentityConfig;user id =sa;password=123456;MultipleActiveResultSets=true"
},
"Logging":{
"IncludeScopes":false,
"LogLevel":{
"Default":"Warning"
}
}
}
Now, in Package Manager console, write Add-migration command, followed by the name of this migration command like this and wait for some seconds.
Now, update the database and click enter.
Now, go to the database and refresh it. You will find aspnet-IdentityConfig database with some tables created by default like AspNetUsers table.
We will use this table to achieve our goal.
Now, how can we change this table name from AspNetUsers to AspUsers as example.
It’s database stuff, so we can achieve this from ApplicationDbContext class.
To be specific from OnModelCreating method into this class, we can customize our ASP.NET Identity model and override the defaults like change table name, property name and others.
We will change the table name now from AspNetUsers to AspUsers by this code inside OnModelCreating method. Proceed, as shown below.
In this code we told entity to get Email property and change this column name to EmailAddress
Now you should make a migration to reflect your changes on Database and we will use it as usual
Add-Migration command then Update-Database
Now it’s time to look in the database
Change Identity table datatype of primary key
We will need to make some changes in ApplicationUser class so go to this class and open it
1
2
3
publicclassApplicationUser:IdentityUser
{
}
ApplicationUser class contains all the custom information I want to store about a user, also inheritance here from IdentityUser gives me all essentials like username ,id, password property or Email, that means if I want to add any property, I will add it here in ApplicationUser class
By default the primary key is string
Because IdentityUser has the primary key we want to pass our new primary key datatype.
Where will we pass this new datatype? Look to the picture below
As you can see we need to pass our primary key as example int datatype to IdentityUser<int> .
And because every user has roles we will need to make this change in roles also by creating new class ApplicationRole which will inherit from IdentityRole class and pass the new datatype to it, and the code will look, as shown below.
CheapASPNETHostingReview.com | Best and cheap ASP.NET Core 1.0 hosting. These days users expect a fluid, app-like experience on the internet. Thus, the new web is being built with APIs and single-page frontends. This means it’s more important that ever to build APIs that are easy to use, reliable, and scalable. ASP.NET Core makes it easy to build great APIs, but there are a few tips we’ve picked up that can help make your APIs even stronger and more scalable.
1. Set the Default Route for ASP.NET Core MVC
A lot of programmers who start using ASP.NET Core just use the default app.UseMvc(); line in the Configure method of Startup.cs. There are options that you can pass to the UseMvc function, like setting the default routes, which is one of the most overlooked:
This will set the root route of your API to: http://www.mycompany.com/api to call the DefaultController’s Get method.
What this does for you (aside from the obvious) is it sets the tone for a decent RESTful API. It also makes changes to URL strategy easier, including versioning the API in the URL easy to do if you set the URL strategy in one place.
2. Return IActionResult from .NET Core Controller Methods
Returning IActionResult from your controller methods affords the ability to take advantage of some of the helper methods and classes to ease returning proper HTTP results. The Ok method on the ControllerBase class will return an OkObjectResult that implements IActionResult and returns a 200 OK HTTP message to the caller. The NotFound method returns an object that sends a 404 NOT FOUND HTTP message.
There are quite a few others, but another extremely helpful one is the CreatedAtAction class that returns not only a 201 CREATED HTTP result but adds a header Location with the URL to access the newly created resource.
3. Use the .NET Async Pattern
Network calls by their very nature are asynchronous. It makes the most sense to create async controller methods that extend that asynchronicity when the controllers need to make database and external API calls.
The fact is, asynchronous support in .NET Core and the supporting libraries is very good these days. Using and creating asynchronous code is easy using async/await and libraries that support the Task pattern. The benefit is more simultaneous requests handled with the same hardware requirements.
Asynchronous code just performs better, and since it is so easy to create, why not do it?
4. Use .NET Attributes
Using attributes to decorate routes helps you to take advantage of some of the power of MVC. This may seem counterintuitive since I just told you to use the default routes. Decorating your methods and controller classes with just enough decoration for that class or method can help you take advantage of things like the CreatedAtAction.
You can also use attributes to help the JSON serializer do its job. You can use the NullValueHandling attribute to tell the serializer that when the value of a property is null, not to even serialize the property. You can change the property name that gets serialized so that you can stick with an internal coding standard and still return standard JSON names (like changing ‘MaxTitleLength’ to ‘maxLength’ when serialized). You can even set the order that properties are serialized so that more important properties are serialized first in the JSON documents.
5. Use Async Result Filters
Using Async Result Filters, you can shape the data in the last moments before it goes back to the caller. Usually, you’d add the properties you want (the way you want them) via an anonymous object. There are two problems with that approach, the first is that you need to do a lot of copying of properties and it violates the single responsibility principle. You could use AutoMapper to combat this property copying, but it doesn’t solve the second problem, which is adding new properties (like hypermedia).
Solution: An Async Result Filter will solve both problems and give you a cleaner, more maintainable code base.
BONUS: Try This Workaround to Improve Serialization of Self-Referencing Object Graphs
One of the problems with traditional .NET Web API serialization, is that it doesn’t handle self-referencing object graphs very well. The fact is, in good object-oriented objects there may actually be some reference loops, so it’s important to handle them gracefully.
In your ConfigureServices method of Startup.cs, change your MVC line from:
In .NET 4.x a reference loop would cause an error. Once the serializer realized that serializing the object graph would cause a reference loop, it would fail and just send a 500 error. However, in .NET Core without the above JSON options added, the serializer serializes the object until it hits a reference loop and simply sends what has been serialized so far, ignoring the rest of the object, even if it could serialize the rest of the object graph easily.
What this line adds is, it tells the JSON serializer to ignore reference loops and continue serializing the rest of the graph. So far, this is just a workaround for the issue. It’s not perfect, but it’s better than just a failure.
The best way to handle this problem is to simply not have the problem. Normally, we would put these objects into DTOs that are not self-referencing and remove the problem altogether.
CheapASPNETHostingReview.com| Best and cheap ASP.NET Core 1.0 hosting. In this post we will talking about Authentication in ASP.NET for web API and Angular. Authentication in a single page application is a bit more special, if you just know the traditional ASP.NET way. To imagine that the app is a completely independent app like a mobile app helps. Token based authentication is the best solution for this kind of apps. In this post I’m going to try to describe a high level overview and to show a simple solution.
There are many ways to protect your application out there. The simplest one is using an Azure Active Directory. You could also setup a separate authentication server, using IdentityServer4, to manage the users, roles and to provide a token based authentication.
And that’s the key word: A Token Based Authentication is the solution for that case.
With the token bases authentication, the client (the web client, the mobile app, and so on) gets a string based encrypted token after a successful log-in. The token also contains some user info and an info about how long the token will be valid. This token needs to be stored on the client side and needs to be submitted to the server every time you request a resource. Usually you use a HTTP header to submit that token. If the token is not longer valid you need to perform a new log-in.
In one of our smaller projects, didn’t set-up a different authentication server and we didn’t use Azure AD, because we needed a fast and cheap solution. Cheap from the customers perspective.
The Angular2 part
On the client side we used angular2-jwt, which is a Angular2 module that handles authentication tokens. It checks the validity, reads meta information out of it and so on. It also provides a wrapper around the Angular2 HTTP service. With this wrapper you are able to automatically pass that token via a HTTP header back to the server on every single request.
The work flow is like this.
If the token is not valid or doesn’t exist on the client, the user gets redirected to the log-in route
The user enters his credentials and presses the log-in button
The date gets posted to the server where a special middle-ware handles that request
The user gets authenticated on the server side
The token, including a validation date and some meta date, gets created
The token gets returned back to the client
the client stores the token in the local storage, cookie or whatever, to use it on every new request.
The angular2-jwt does the most magic on the client for us. We just need to use it, to check the availability and the validity, every time we want to do a request to the server or every time we change the view.
This is a small example about how the HTTP wrapper is used in Angular2:
On the server side we also use a, separate open source project, called SimpleTokenProvider. This is really a pretty simple solution to authenticate the users, using his credentials and to create and provide the token. I would not recommend to use this way in a huge and critical solution, in that case you should choose the IdentiyServer or any other authentication like Azure AD to be more secure. The sources of that project need to be copied into your project and you possibly need to change some lines e. g. to authenticate the users against your database, or whatever you use to store the user data. This project provides a middle-ware, which is listening on a defined path, like /api/tokenauth/. This URL is called with a POST request by the log-in view of the client application.
The authentication for the web API, is just using the token, sent with the current request. This is simply done with the built-in IdentiyMiddleware. That means, if ASP.NET MVC gets a request to a Controller or an Action with an AuthorizeAttribute, it checks the request for incoming Tokens. If the Token is valid, the user is authenticated. If the user is also in the right role, he gets authorized.
We put the users role information as additional claims into the Token, so this information can be extracted out of that token and can be used in the application.
To find the users and to identify the user, we use the given UserManager and SignInManager. These managers are bound to the IdentityDataContext. This classes are already available, when you create a new project with Identiy in Visual Studio.
This way we can authenticate a user on the server side:
This code will not work, if you copy and past it in your application, but shows you what needs to be done to create a token and how the token is created and sent to the client.
CheapASPNETHostingReview.com | Best and cheap ASP.NET Core 1.0 hosting. This post is about Bundling and Minification in ASP.NET Core. Bundling and minification are two techniques you can use in ASP.NET to improve page load performance for your web application. Bundling combines multiple files into a single file. Minification performs a variety of different code optimizations to scripts and CSS, which results in smaller payloads. In ASP.NET Core RTM release Microsoft introduced “BundlerMinifier.Core” tool which will help you to bundle and minimize Javascript and style sheet files. Unlike previous versions MVC, the bundling and minification is happening on development time not in runtime. To use “BundlerMinifier.Core” first you need to add reference of BundlerMinifier.Core in the project.json tools section.
Now you need to specify the Javascript and stylesheet files for bundling and minification. You can do this by adding “bundleconfig.json” file. The name can be changed, but if the filename is bundleconfig.json, it will bundle command will take it automatically. Here is a minimal bundleconfig.json file.
The file is self explantory, you can specify multiple file in the inputFiles element, which will be combined and minified based on the minify element. Now you can combine and minify using “dotnet bundle” command. Here is the output when I run the dotnet bundle command on my MVC project.
You can integrate it to the development lifecycle by adding the dotnet build command in the “precompile” script section in project.json file. If you are using Yo ASP.NET generator, the project template will be using precompile script section in project.json.
There are few more commands also available with dotnet bundle tool.
dotnet bundle clean – Executing dotnet bundle clean will delete all output files from disk.
dotnet bundle watch – To automatically run the bundler when input files change, call dotnet bundle watch. This will monitor any file changes to input files in the working directory and execute the bundler automatically.
dotnet bundle help – Get help on how to use the CLI.
CheapASPNETHostingReview.com | Best and cheap ASP.NET Core 1.0 hosting. ASP.NET Core is a complete rewrite of ASP.NET, targeting .NET Core on Linux and OS X as well as Windows.
Among the many upgrades in the new version is a completely rewritten diagnostic logging pipeline that not only emits interesting events from the framework, but uses structured logging to do so.
Structured Logging in ASP.NET Core
Like Serilog, ASP.NET Core uses message templates (named placeholders in format strings) to capture structured properties along with textual log data:
1
logger.Information("Handled in {Elapsed} ms",timer.ElapsedMilliseconds);
If this event is written out to the console, it will be formatted as plain text:
1
Handled in456ms
This is ideal during development, when a readable text format is preferred.
But, when the logging provider supports structured data, the properties associated with the event can be preserved in a machine-readable form:
1
2
3
4
5
6
{
"MessageTemplate":"Handled in {Elapsed} ms",
"Properties":{
"Elapsed":456
}
}
Armed with structured log data, it’s easy to slice and dice logs with queries like:
1
Elapsed>300
This is a game-changing capability for complex distributed apps, or when log data runs more than a few hundred events in a day.
Setting Up
These instructions assume that you’ve created a new ASP.NET web application using the template in Visual Studio (File > New… > Project > ASP.NET Web Application).
Out of the box it should look something like this:
The packages we’ll install are:
Serilog – a logging framework for structured data
Serilog.Extensions.Logging – an ASP.NET logging provider that implements ASP.NET’s ILogger on top of Serilog
Serilog.Sinks.Seq – a Serilog sink that ships events to Seq over HTTP
To really take advantage of ASP.NET Core’s logging today, you’ll need a complete logging provider like Serilog to handle the task of shipping log events to most back-end storage targets, as only a few basic providers such as a console logger are there today. Over time it’s likely ASP.NET Core will gain more capabilities of its own in this area.
Crucially, all of the packages supporting ASP.NET Core are currently pre-release, so make sure to include the -Pre switch when installing from the Package Manager Console:
1
2
3
Install-PackageSerilog
Install-PackageSerilog.Extensions.Logging
Install-PackageSerilog.Sinks.Seq
Then, the following lines added to Startup.cs will configure the Serilog back-end:
1
2
3
4
5
6
7
8
publicStartup(IHostingEnvironment env)
{
// Configure the Serilog pipeline
Log.Logger=newLoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();
This assumes you have Seq running locally on your development machine, listening on the default port. Replace http://localhost:5341 with the address of you Seq server if it lives somewhere else.
(Adding Enrich.FromLogContext() here ensures that any events written directly through Serilog will seamlessly pick up correlation ids like RequestId from ASP.NET.)
Finally, also in Startup.cs, add Serilog to the ILoggerFactory that’s passed into the Configure() method:
When you refresh the application, all kinds of interesting data from the framework’s inner workings will appear in Seq:
In this screenshot you can see a few familiar MVC processes going on – requests started and finished, actions invoked and views selected.
Writing custom events
It would be interesting, but fairly underwhelming, if the story ended here. The real value in the new logging pipeline is that your own application events get the same treatment.
The simplest way to start logging from your own controllers is to take a dependency on type ILogger<T>:
The T generic parameter is passed so that log events can be tagged with the class that raised them.
ILogger<T> has methods like LogInformation(), LogWarning() and LogError() to write events to the logging pipeline:
_logger.LogInformation("Hello from {MachineName}!",machine);
returnView();
}
Look carefully at the properties attached to the resulting event:
The first thing to notice is that the MachineName argument we supplied in the format string is there as a first-class property that can be used when searching for events.
The second thing to observe is RequestId – this little gem is added automatically by the ASP.NET framework to all events raised during a web request. Filtering down to a single RequestId will find all events related to just that HTTP request – your own, and the ones raised by the framework. If you don’t use this technique already, it’s something you absolutely must try.
Alternatives for ASP.NET 4.6
Not using ASP.NET Core just yet? Check out the Serilog support for ASP.NET 4.6, which adds a lot of structured logging goodness through a NuGet package.
CheapASPNETHostingReview.com | Best and cheap ASP.NET Core 1.0 hosting. When errors occur in your ASP.NET Core app, you can handle them in a variety of ways, as described in this article.
The developer exception page
To configure an app to display a page that shows detailed information about exceptions, install the Microsoft.AspNetCore.Diagnostics NuGet package and add a line to the Configure method in the Startup class:
Put UseDeveloperExceptionPage before any middleware you want to catch exceptions in, such as app.UseMvc.
Warning [wp-svg-icons icon=”warning” wrap=”i”]
Enable the developer exception page only when the app is running in the Development environment. You don’t want to share detailed exception information publicly when the app runs in production
To see the developer exception page, run the sample application with the environment set to Development, and add ?throw=true to the base URL of the app. The page includes several tabs with information about the exception and the request. The first tab includes a stack trace.
The next tab shows the query string parameters, if any.
This request didn’t have any cookies, but if it did, they would appear on the Cookies tab. You can see the headers that were passed in the last tab.
Configuring a custom exception handling page
It’s a good idea to configure an exception handler page to use when the app is not running in the Development environment.
In an MVC app, don’t explicitly decorate the error handler action method with HTTP method attributes, such as HttpGet. Using explicit verbs could prevent some requests from reaching the method.
1
2
3
4
5
[Route("/Error")]
publicIActionResult Index()
{
// Handle error here
}
Configuring status code pages
By default, your app will not provide a rich status code page for HTTP status codes such as 500 (Internal Server Error) or 404 (Not Found). You can configure the StatusCodePagesMiddleware by adding a line to the Configure method :
1
app.UseStatusCodePages();
By default, this middleware adds simple, text-only handlers for common status codes, such as 404:+
The middleware supports several different extension methods. One takes a lambda expression, another takes a content type and format string.
app.UseStatusCodePages("text/plain","Status code page, status code: {0}");
There are also redirect extension methods. One sends a 302 status code to the client, and one returns the original status code to the client but also executes the handler for the redirect URL.
Code in exception handling pages can throw exceptions. It’s often a good idea for production error pages to consist of purely static content.
Also, be aware that once the headers for a response have been sent, you can’t change the response’s status code, nor can any exception pages or handlers run. The response must be completed or the connection aborted.
Server exception handling
In addition to the exception handling logic in your app, the server hosting your app will perform some exception handling. If the server catches an exception before the headers have been sent it sends a 500 Internal Server Error response with no body. If it catches an exception after the headers have been sent, it closes the connection. Requests that are not handled by your app will be handled by the server, and any exception that occurs will be handled by the server’s exception handling. Any custom error pages or exception handling middleware or filters you have configured for your app will not affect this behavior.
Startup exception handling
Only the hosting layer can handle exceptions that take place during app startup. Exceptions that occur during app startup can impact server behavior. For example, if an exception happens before you call KestrelServerOptions.UseHttps, the hosting layer catches the exception, starts the server, and displays an error page on the non-SSL port. If an exception happens after that line executes, the error page is served over HTTPS instead.
You can configure how the host will behave in response to errors during startup using CaptureStartupErrors and the detailedErrors key.
ASP.NET MVC error handling
MVC apps have some additional options for handling errors, such as configuring exception filters and performing model validation.
Exception Filters
Exception filters can be configured globally or on a per-controller or per-action basis in an MVC app. These filters handle any unhandled exception that occurs during the execution of a controller action or another filter, and are not called otherwise. Learn more about exception filters in
Tip [wp-svg-icons icon=”pushpin” wrap=”i”]
Exception filters are good for trapping exceptions that occur within MVC actions, but they’re not as flexible as error handling middleware. Prefer middleware for the general case, and use filters only where you need to do error handling differently based on which MVC action was chosen.
Handling Model State Errors
Model validation occurs prior to each controller action being invoked, and it is the action method’s responsibility to inspect ModelState.IsValid and react appropriately.
Some apps will choose to follow a standard convention for dealing with model validation errors, in which case a filter may be an appropriate place to implement such a policy. You should test how your actions behave with invalid model states.
CheapASPNETHostingReview.com | Best and cheap ASP.NET Core RTM 1.0 hosting. In this post I will explain how to setup Visual Studio 2015 in order to develop an Angular 2 RC3 application hosted inside ASP.NET Core project. I of course read the quick start first. You need to make sure to install VS 2015, you can use Community edition of you want. You would also need to install ASP.NET Core.
Let’s get started. Create new ASP.NET Core project.
Select empty template to keep everything simple for getting started demo.
Let’s add static files support to serve a plain vanilla HTML page. Open project.json file and add the static files line from below.
I also added support for DotNet.Watcher tools which make it easier to make changes to C# code and have the process automatically compile and restart as needed.
Now we can add a page which will host our Angular app. Again, add just a plain HTML page under wwwroot folder, since that is the root of our deployable Core application. You can just right click on that folder, add new item, then pick HTML page template. I am calling mine index.html. In order to see this page we need to turn off preloaded startup code and replace it with static files server. Open up Startup.cs file and replace Configure method with the following.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
publicclassStartup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
Now we can test the host page. Open up VS command prompt and navigate to the project folder (NOT solution folder). Type “dotnet watch run”. Your app will compile and Kestrel web server with start. Open browser and navigate to http://localhost:5000/index.html. You will see the host page. To make sure edit the index.html page and add some content to it. It is time to start up Angular 2 portion. I like adding NPM support to the project from command line. From the same command prompt type “npm init” to initialize NPM file. Follow the prompts, giving some meaningful answers. Once this is done, switch to visual studio. You will see that dependencies node in project explorer with have npm listed. Right click on that node and select open package.json. We need to add all Angular 2 scripts and dependencies by adding dependencies and devDependencies nodes as shown below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
"name":"demo",
"version":"1.0.0",
"description":"",
"main":"index.js",
"scripts":{
"test":"echo \"Error: no test specified\" && exit 1"
},
"author":"",
"license":"ISC",
"dependencies":{
"@angular/common":"2.0.0",
"@angular/compiler":"2.0.0",
"@angular/core":"2.0.0",
"@angular/forms":"2.0.0",
"@angular/http":"2.0.0",
"@angular/platform-browser":"2.0.0",
"@angular/platform-browser-dynamic":"2.0.0",
"@angular/router":"3.0.0",
"systemjs":"0.19.27",
"core-js":"^2.4.1",
"reflect-metadata":"^0.1.3",
"rxjs":"5.0.0-beta.12",
"zone.js":"^0.6.23",
"bootstrap":"^3.3.6"
},
"devDependencies":{
"gulp":"^3.9.1",
"typings":"^1.3.3",
"del":"^2.2.2",
"rimraf":"^2.5.4"
}
}
All packages that start with @angular are angular core packages. This is different from beta versions, which only had a single package. Other packages are supporting packages for angular 2. In order to proving TypeScript support, we will use typings NPM module, which is under devDependencies. Give VS a minute to restore the packages after saving package.json file. If you get an error, just type “npm install” at the command prompt.
Now we need to install code JavaScript typings files for TypeScript. At the same prompt type “typings install –global –save dt~core-js”. Once completed, you will see typings folder in project explorer, with core-js folder under it.
In the next step we will setup compilation options for TypeScript. Add new item to the root of your project, selecting TypeScript Configuration File item template. Change the content to look as follows.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"compileOnSave":true,
"compilerOptions":{
"target":"es5",
"module":"commonjs",
"moduleResolution":"node",
"sourceMap":true,
"emitDecoratorMetadata":true,
"experimentalDecorators":true,
"removeComments":false,
"noImplicitAny":true,
"suppressImplicitAnyIndexErrors":true
},
"exclude":[
"node_modules",
"wwwroot"
]
}
We are adding decorator options, which are required for Angular 2. We are setting module to use systemjs, which is the default for all the demos I have seen.
Now I am going to setup gulp to make my development flow a bit smoother. If you do not have gulp installed globally, type “npm install gulp” at the command prompt. After that you can add new item to the root of the project, selecting Gulp Configuration File item template. Open gulpfile.js and replace the content with the following.
What is going on here? Third party task copies necessary Angular 2 scripts from node_modules folder to the same folder under wwwroot. Copy task copies our own application files, which will be placed under app folder under project root to wwwroot folder as well. Finally, watch task will monitor the changes to app folder and re-copy the files wwwroot folder by firing copy task. By default we will run all three tasks when we run gulp every time.
Time to write application code. Create new folder called “app” under project root. Now we need to create root component. We will add app.ts file with the following code.
We created a new class called App. It is decorated with a component attribute. We specify the selector or tag that will be replaced with our component. We also specify the HTML that will be injected and bound to the component. The component just has a property and a method to test data binding.
Now we need to create a starting module. Let’s call the file appModule.ts
This class actually does not have any executable code, just a decorator that defines our root module. It imports compile module, BrowserModule, necessary for compiling and bootstrapping Angular code in browser. it contains our single App component that we both declare and bootsrtap, setting it as entry point into the application.
Finally, add new item to shell folder, picking TypeScript file template. Change the name to main. This will be our bootstrapping code for Angular 2 application.
Now we need to configure systemjs module loader. Create new JavaScript file called system.config.js under wwwroot folder. This is the only file we will add there. We could also add it under app folder if we wanted to. Here it its content.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* System configuration for Angular 2 samples
* Adjust as necessary for your application needs.
*/
(function(global){
// map tells the System loader where to look for things
varmap={
'app':'app',// 'dist',
'@angular':'node_modules/@angular',
'rxjs':'node_modules/rxjs'
};
// packages tells the System loader how to load when no filename and/or no extension
We are specifying our app folder as a package for system js. We are also adding core angular packages, including rxjs, reactive extensions. We are configuring systemjs by calling config method and passing our packages map. Finally we are starting app package. Previously in the same file we specified that the entry point for it is main.js.
It is time to edit our index.chtml page and add the necessary scripts. We will start by creating views folder with some stock files. I am adding _ViewStart.cshtml under Views.
1
2
3
@{
Layout="_Layout";
}
This code just sets up default layout page for all our views. Now we just need default view. I am going to create home folder and single view under it Index.cshtml. Its content is very simple.
1
<app-shell>Loading...</app-shell>
It just contains the tag for our root component. Now the import part of adding out layout page, _Layout.cshtml under Views/Shared folder. It just contains all the necessary libraries.
It also setups up configuration object, which we do not technically need in this sample app, but it is a good illustration on how to inject server side configuration into client side JavaScript. We are keeping node_modules and third party libraries folder, but to be sure, we are not using entire folder, we just compy necessary stuff via gulp (see above).
Time to create C# controller under Controllers folder. We will call it HomeController.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using Microsoft.AspNetCore.Mvc;
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespaceWebAppAngular2RTM.Controllers
{
publicclassHomeController:Controller
{
// GET: /<controller>/
publicIActionResult Index()
{
returnView();
}
}
}
You can now build the project in the Visual Studio just in case. Then switch to command prompt, navigate to the folder where our project is (NOT solution). Just make sure you see project.json file. Now we need to run gulp to copy files around. Type “gulp” and let the process finish. Now open second prompt, nvaigate to the same folder and type “dotnet watch run”. This will compile if necessary, start runtime process and watch for any changes. Let this finish as well. Make sure you see something like the following:
1
2
Now listening on:http://localhost:5000
Application started.Press Ctrl+Ctoshut down.
Final step. Open browser and navigate to the URL above. You should see the following.
Feel free to click on a button to make sure the method in your App component got bound properly as well. Also feel free to make changes to the App component and refresh the page to see them.
In this post we achieved a lot. We setup new .Net Core project, created default controller and cshtml page, setup Angular 2 minimal application, setup watcher for .NET and TypeScript code to make changes without manual compilation and ran our project. Quite a bit of work.
CheapASPNETHostingReview.com| Best and cheap ASP.NET Core 1.0 hosting. Suppose you work for a small to midsize company that employs 50-100 workers. The Help Desk — a subsidiary of the Information Services Division — is in charge of trouble tickets regarding general PC issues such as email, viruses, network issues, etc. Initially, the Help Desk team stored this information in Excel spreadsheets, but as the company has grown, managing these spreadsheets has become tedious and time consuming.
The Help Desk has asked you to devise a more efficient solution that could be developed internally, saving the company money. As you start to think about it, the following requirements are apparent: fields for the submitter’s first and last name, as well as their email address. You’ll also need combo boxes for indicating ticket severity (low, medium, high), department, status (new, open, resolved), employee working on the issue, as well as an area for comments. Of all the solutions available, creating an internal help desk Web application with ASP.NET is relatively simple.
In the following article, we’ll see how to implement these features in an ASP.NET help desk Web application using a database-driven approach,
Creating the JavaScript File
Because creating the JavaScript file is the easiest of the work left, we’ll do this next. From the Solution Explorer, follow these steps:
Creating the Help Desk Class
Now that we have our data coming in, we need to be able to record a help desk ticket submission. We need to create an event handler in a class to handle it. Let’s first create a help desk class by doing the following:
Right click the project solution.
Choose Add>New Item.
In the Add New Item window, select Class.cs.
In the name text field, type “HelpDesk” and then click Add.
Double click HelpDesk.cs from the Solution Explorer, which will show the empty class as shown below:
1
2
3
4
5
6
7
8
9
10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespaceHelpDesk
{
publicclassHelpDesk
{
}
}
We need to import three libraries as shown below:
1
2
3
4
5
6
7
8
9
10
11
12
13
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
namespaceHelpDesk
{
publicclassHelpDesk
{
}
}
The first library (System.Data) allows us to work with stored procedures in ADO.NET, the second (System.Configuration) allows us to reference a connection key from configuration file and the last (System.Data.SqlClient) one allows us to connect to SQL Server.