Friday, May 08, 2015

An Insight Into Authorization And Securing Websites In ASP.NET

Ensuring a secure and authentic access to the website is a prime concern for the most of the asp.net developers and website owners. If your website is open to everyone and not possessing and security bar, your content and business is at a great risk of malware and hackers. An illegal and unauthentic access can affect your page rank and even spam your website. 
 

Authorization and Securing in ASP.NET



Hence, it is imperative to manage the access to your website while considering the user's need. Generally there are several sections on a website targeted for several administrative and public usage. Therefore, there is a greater need of authorization, as it will help keep the consequences of unauthorized access at the bay. Thus, users will be only able to access the specific sections on the website depending on their role of responsibility. There comes the job of a web developer, who is accountable for implementing a secure and reliable authorization.


Authorization: A Foreword

The very vital information that is required while defining the access limit for a user is to identify the user, that is, whether the user is a consumer (like customer at an e-commerce site) or an administrator. Thus, we can say that a website supports authentication when it can determine the identity of an individual and upon that basis, it personalizes the website for that user by representing the known info about the user after logging in.

Authorization primarily focuses on determining the unique identity of a user and accordingly identifying the actions that the user can perform. And by using the unique identity of users, we can further embrace superior protection on the several sections your website.

Recommended Post : How To Set Up and Use Authentication Filters in ASP.NET

Creating Groups Can Help Manage Access Efficiently
It is quite obvious that managing the access for numerous individuals is a daunting task and may create bottlenecks in the site's performance. To handle this issue in a better fashion, you can create groups for users possessing similar demands or accessing rights. The website administrator can define the limitations and access for each group serving a specific role.

How to protect web pages in ASP.NET site?
Security is the most vital aspect of any website. For ASP.NET-enabled websites, there are basically two methods available. Let's ponder into each approach one by one.

1. Securing The Routing And Web Forms
This approach primarily involves the implementation of the web.config file for securing the access to the web pages.

Basic XML snippet:
<configuration>
<location path="customerhome.aspx">
<system.web>
<authorization>
<allow roles="customer"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
</configuration>

Here, in the aforementioned snippet, the path holds the information of the folder, file or route that you specifically want to secure. If no path is defined, by default it will consider the current directory (web.config). The authorization element will help define the access and denied access attribute of the mentioned path. With the allow element the role or group can be defined.

In this example, first the <allow roles="customer"/> is checked and if a user belongs to the customer group, he will be granted access and that is it, nothing else is required to be checked. However, if the user doesn't belong to the specified role, the next rule will be checked. For instance, here, the users who are not customers will be denied access.

2. Securing The MVC

In this approach the controllers and the actions imposed over those controllers is paramount. Like web forms, that by default facilitates access to all the users, while developing ASP.NET website also allows all users to access controllers and actions.

Here, you are required to implement the Authorize attribute. This can help you limit the access of the defined role. For instance, let's consider a class AdminController that should only be allowed to be accessed by the users possessing the Admin role. This can be done with the following line of code.

[Authorize(Roles = "siteadmin")]
public class AdminController : Controller
{
...

How to handle web pages accessed by multiple roles?
Securing web pages for users exhibiting single role is much simpler than that for users with multiple roles.

The private and sensitive information on the website is needed to be dealt with utmost precision and care. To ensure their security and smooth functioning of the website, all unauthorized access should be prevented. You can follow the aforementioned guide and keep your ASP.NET website safe and secure by precisely configuring the page access, actions and roles for all types of potential users.
Now, once the files, folders, actions, controllers, and routers have been secured, the next thing is to ensure that no conflicts are originating while users assigned with multiple roles are accessing the ASP.NET-enabled website. There is a probability that different roles have been assigned the access to the page while they possess different abilities and rights on the page. In such situations, it is advisable to avoid including the links of URLs, files or action on the page itself. To deny an action for a role, simply remove that action from the page, there is no reason for displaying it either.


Wednesday, April 01, 2015

A Handy Guide on Creating a Service Using AngularJS service() and factory() method



AngularJS (also referred to as Angular) comes with several built-in services that helps to organize and share the code across your web application. Essentially, a service in AngularJS is a singletons object that consists of a set of functions containing logic that is required by the service for performing its work. More importantly, an AngularJS service avoids polluting the object space unnecessarily. For example, Angular '$http' service helps interact with remote HTTP servers through the browser’s XMLHttpRequest object. This means, you just need to communicate with the $http API to connect to the server, and doesn't need to make frequent calls to the XMLHttpRequest object.


Apart from using Angular built-in services, you can even choose to create your own services to meet the needs of any complex application using web development services. With AngularJS, you can easily create custom services by simply registering them. When a service gets registered, it can be referenced by the Angular complier and is loaded at runtime in the form of a dependency.

There are five methods using which an Angular service can be created or registered such as:



  • the value() method

  • the service
() method
  • the factory
() method
  • the provider
() method
  • the constant
() method


In this post, we'll discuss about the two most important methods used for creating a service: the service() method and the factory() method. We will be using some examples to simplify the process of creating and using a service using these methods. But before proceeding further, let's first understand the difference between the service() method and the factory() method.

Note: Once your service is created, you will need to use it inside the controller so that it can be used to perform the operations.

Let us understand how creating a service using the service() method is different from the factory() method.


Getting to Know the Difference Between: the service() and factory() method

The service() method make use of function constructor. And then, this method returns an instance of the function or an object that the service needs to work with.
In contrast, the factory() method uses the value that is returned by the function. This method returns the function value that is returned post the execution of the service function.

We will have to use the service() method, in case we need to register a service with help of the function constructor. Conversely, registering the service using the factory() method will return the value, once the service function has been executed. The value may be returned in the form of a function, a primitive value, or object.

Simply put, while the service() method returns output in the form of function object, the factory() method, on the other hand, returns output in any kind of value.


Creating a Service Using the service() Method

Let's begin with, creating a simple service using the service() method that will help us find the square of a number. When creating a service, it would be better to place all the services in an individual JavaScript file. For our example, let's create a service.js file and then within the file create the service using the service method as follows:

var CalculatorService = angular.module('CalculatorService', [])

.service('Calculator', function () {

this.square = function (a) { return a*a};


});

As we had discussed above, we'll need to use our service in the controller. To do so, we'll have to pass “CalculatorService” service module in the app module as a dependency. And then, we just need to pass the name of our newly created service “Calculator” in the controller as shown below:


var myApp = angular.module('myApp', ['CalculatorService']);

myApp.controller('CalculatorController', function ($scope, Calculator) {


$scope.findSquare = function () {

$scope.answer = Calculator.square($scope.number);

}

});


Creating a Service Using the factory() Method

Let us now take an example to see how we can create a service using the factory() method. For example, let us create a service for reversing the string.



CalculatorService.factory('StringManipulation', function () {


var r= function reverse(s) {

var o = '';

for (var i = s.length - 1; i >= 0; i--)

o += s[i];

return o;

}


return{

reverseString: function reverseString(name)

{

return r(name);

}

}


});

Next, pass the new service “StringManipulationService” in the controller using the following code:


myApp.controller('CalculatorController', function ($scope, Calculator) {


$scope.findSquare = function () {

$scope.answer = Calculator.square($scope.number);

}

});



Wrapping Up!



AngularJS services provides are objects or functions that contains some business logic, using which we can perform some specific tasks. While there are many built-in Angular services available for you, you may need to create your own services to meet your complex web app requirements. In order to create a service or register it, AngularJS provides 5 different ways (or methods) to choose from. Reading this post will help you learn about using the two most important AngularJS methods and how they can be used for creating a service.

Wednesday, December 17, 2014

Android Wear - A smart operating system dedicated to wearables



The era of wearables has arrived. All thanks to the immeasurable success of smartphones, both Apple and Google have announced entering into the world of wearable devices. Recently, the internet giant 'Google' announced the release of a new operating system-Android Wear which is specially designed for wearable devices such as Smartwatches that are originally manufactured by renowned companies including Samsung, LG, Motorola and many more. This blog digs deeper into the significance of Android Wear.

What's the basic aim of Android Wear?


As Google's latest operating system, Android Wear is intended to offer you suggestions based on factors such as your current location, time etc. That means, apart from displaying the time, an Android smartwatch will offer you information that will move with you. For example, if you are wearing an Android smartwatch and just boarded a bus, you can quickly look into your smartwatch to get insights on all the nearby locations that are a must-visit. The best part of Android Wear is that allows you to keep a good check over the apps' usage of battery and storage.

Watch Face API - An excellent addition to Android Wear


There are numerous of perks of Android applications development platform. Similarly, one of the greatest additions to Android Wear is the Watch Face API. Unlike the traditional hacking of custom watch faces that include undocumented APIs, Google has now rendered official support to developers who want to create a watch face. Announcing the launch of a new section within the Play Store for the Watch Face API, Google will be offering developers a complete control over the layout of their specific Watch Face. Additionally, Google has also tweaked the Android Wear app for allowing users to browse, download and swap within multiple watch faces.

Two new modes boost the performance of Android Wear screens

Android Wear comes with two new modes viz: Sunlight mode and Theater mode. While the sunlight mode works as the best fit for boosting the screen brightness for a short duration of time, the theater mode works just the opposite. To put it simple, when you switch on the theater mode, the screen will go completely black, with all the incoming notifications being muted. Plus, there's a handy hardware button that allows you to switch to Theater mode via a double-click and to the Sunlight mode via a triple click.

Blocking App Notifications directly from Android smartwatch is an interesting feature
                                     
To explore this, you can hire Android app programmer or simply contact. However, frequent notifications from apps seem to be quite disturbing for a smartwatch user. Now, with Android Wear, you can choose to block notifications from an app directly from your smartwatch itself. Considered as one of the biggest updates to Android Wear operating system till date, Google is inclined on popularizing Android Wear to an unimaginable level.

Conclusion


With Google leaving no stone unturned in making Android Wear a complete success, it will be interesting to see how the forthcoming updates to this all-new operating system will be embraced by avid Android fans. Here's hoping the information covered in this blog would enlighten you about the best features of Android Wear that can be leveraged for making your life simpler and fun-filled.

NOW READ: An Insight Into The Material Design Of Android L