Skip to main content

Posts

Showing posts from June, 2018

How to Consume WCF service to Asp.Net Core

In this article we will undestand how we can consume Wcf Service into Asp.Net Core application. In Asp.Net core we cannot create WCF service as core don't support WCF development. but it doesn't mean we can't consume Wcf service in core project. However in Asp.Net Core there is a slight difference in Consuming WCF Service. In Asp.Net core you will notice that, we don’t have the option “Add Service Reference like in the older .Net Framework. Step 1 :  You will find Connected Service into your solution, Double click on Connected Service. show below in ref 1 screen. once you click on Connected Service then ref 1.1 screen will be display. ref 1 ref 1.1  Step 2 :  click on the configure button [Microsoft WCF Web service reference provider]. configure screen will be open. ref 2 Step 3 : In the configure WCF Service reference dialog, you can either provide the URL of the service or you can try the discover option, which will display all the

Multiple Enviroment Support in Asp.net core.

Introduction. ASP.NET Core has introduce new feature and many more performance enhancement. ASP.NET Core configures app behavior based on the runtime environment using an environment variable. We can set any value to ASPNETCORE_ENVIRONMENT but three environment value are in-build supported by framework are Development, Staging, and Production. by default value of ASPNETCORE_ENVIRONMENT is Production. Description. Let use see how we can set ASPNETCORE_ENVIRONMENT using Visual studio. the environment variable settings can be specified in our project's debug profiles. Above image shows current environment is set as Development. when we are modify any settings within the project will be refect in launchSettings.json , launchSettings.json is located into properties folder. The "launchSettings.json" file holds the setting, which is specific to each profile used to launch the Application. Asp.net core read environment variable value at app startup and store

Bundling And Minification Using In ASP.NET Core.

Nowadays no one like to use website which works slowly. Bundling And Minification help us to achive. Bundling and minification are two different performance optimizer you can use for your application to improve overall performance of application. Bundling and minification primarily improve the first page request load time. Once a web page has been requested, the browser caches the static assets (JavaScript, CSS, and images). Bundling : Bundling combines multiple files into a single file. Bundling reduces the number of server requests which are necessary to render a web asset, such as a web page. You can create any number of individual bundles specifically for CSS, JavaScript, etc. It ultimately reduces http request for static content. Minification : Minification removes unnecessary characters from code without altering functionality and also removing white space and commented code. The result is a significant size reduction in requested assets (such as CSS, images, and Ja

ASP.NET Core Startup Class and Program.cs

Introduction. Global.asax is no more in ASP.NET Core application. Startup.cs file is a replacement of Global.asax file in ASP.NET Core. Startup.cs file is entry point of application level it handle request pipeline. Startup class which triggers at first when application launches. Description. Now question is startup.cs file is mandatory or not? Yes, startup.cs is mandatory, it can be decorated with any access modifier like public, private, internal. multiple Startup classes are allowed in a single application. ASP.NET Core will select the appropriate class based on its Enviroment. If a class Startup{EnvironmentName} exists, that class will be called for that EnvironmentName . Should we need to define class name with startup.cs? No it is not necessary that class name should be Startup. We can define two method in startup file like ConfigureServices and Configure. Startup file example : public class Startup { // Use this method to add services to the containe

Custom AuthorizeAttribute in ASP.NET Core.

Introduction. Filter in MVC are attribute which can be apply to controller and action method. filters allow us to write our custom code before and after method execution. filters can be implemented into different level of scope Global, Class, and Method level. MVC provides different types of filters. The Authorization filter will run first and are used to determine whether the current user is authorized or unauthorized for the current request. In this article we will learn how to create custom authorization filter, were you can write your own authorization framework. Description. For creating Authorization filter IAuthorizationFilter interface must be inherited. For example, the following code demonstrate custom Authorization below CustomAuthorization attribute allow only Home controller to access the particular method under home controller class else it will return "error" in response if it is called via ajaxcall, otherwise it will be redirect to Sessi

Filters In ASP.NET MVC Core.

Introduction. Filters in ASP . NET Core MVC  allow you to run code before or after specific stages in the request processing pipeline.  In ASP.net Core MVC user will be routed to appropriate contoller and action if there is need to execute some logic before executing and after executing MVC Filters are used. There are many built-in filters available with ASP.NET Core MVC, and we can create custom filters as well.Filters can avoid duplicating code across actions The following are the list of filter types, interface which must be implemented to create a custom filter class. Filter types Each filter type is executed at a different stage in the filter pipeline. below are list of different filters. Authorization filters: The Authorization filter will run first and are used to determine whether the current user is authorized or unauthorized for the current request. we can also create custom authorization filter. Resource filters: the Resource filter is the first

How to use Log4Net in .Net Core 2.0 Application.

1. Introduction Logging frameworks are important because they make it easy to write your logs to different places by simply changing your configuration. You can write your .NET logs to a file on disk, a database, a log management system 2. Install Nuget Package For nlog  To use Nlog logging you need to first add Nlog pluging for adding pluging you can do it by different way. 1) Manage Nuget Packages. 2) Nuget command. you can find nuget command for Log4Net below. PM> Install-Package log4net -Version 2.0.8 3. Add log4net.config file We need to Add New to your project with name log4net.config Refer below code for log4net.config for logging log into file. Root is neccesary in log4net.config, in which we can define log level and appender-ref in which we can define appender for eg. FileAppender, ConsoleAppender. Layout : In layout we can define custom parameter sh

How to Use Nlog with .Net Core 2.0 Application

1. Introduction Logging is heart of the application. logging is very important for debugging and troubleshooting as well as for smoothness of application. with the help of logging we can have end-to-end visibility for on-premise systems, to only give a fraction of that visibility for cloud-based systems. It can be difficult to instrument the cloud and, thus, alternative approaches, like logging, are required to give visibility into cloud-based components which otherwise can become black boxes from a performance or system monitoring perspective. 2. Install Nuget Package For nlog  To use Nlog logging you need to first add Nlog pluging for adding pluging you can do it by different way. 1) Manage Nuget Packages. 2) Nuget command. you can find nuget command for Nlog on mentioned link :  Click Here 3. Create and add Nlog config file we need to create Nlog.config file at root of project were we can keep nlog related configration. Example :