All posts by noumanbhatti

ASP.NET Core logging with NLog and Elasticsearch

Software Engineering

This article shows how to Log to Elasticsearch using NLog in an ASP.NET Core application. NLog is a free open-source logging for .NET.

Code:VS2017 RC3 csproj | VS2015 project.json

2017.02.08 Updated to NLog.Web.AspNetCore 4.3.0 and VS2017 RC3
17.12.2016 Updated to ASP.NET Core 1.1

NLog posts in this series:

  1. ASP.NET Core logging with NLog and Microsoft SQL Server
  2. ASP.NET Core logging with NLog and Elasticsearch
  3. Settings the NLog database connection string in the ASP.NET Core appsettings.json
  4. .NET Core logging to MySQL using NLog
  5. .NET Core logging with NLog and PostgreSQL

NLog.Extensions.Logging is required to use NLog in an ASP.NET Core application. This is added to the dependencies of the project. NLog.Targets.ElasticSearch is also added to the dependencies. This project is at present NOT the NuGet package from ReactiveMarkets, but the source code from ReactiveMarkets and updated to dotnetcore. Thanks to ReactiveMarkets for this library, hopefully the NuGet package will…

View original post 181 more words

Sisense SSO implementation in MVC .net core

We can find a documentation regarding what needs to be done in Sisense BI Elastic cube manager in relation to SSO using JWT.  They also have C# code to use for SSO but one may be scratching his head if he/she wants to use that sample code in MVC .net Core application.

So for that purpose I’ld suggest to make one controller with one action in it, Use that URL of that controller action to configure in Sisense SSO configuration page. The sample code would be

 

public IActionResult Index([FromQuery]string return_to)
{
TimeSpan t = (DateTime.UtcNow – new DateTime(1970, 1, 1));
int timestamp = (int)t.TotalSeconds;
var payload = new System.Collections.Generic.Dictionary<string, object>() {
{ “iat”, timestamp},
{ “sub”, CurrentUser() },
{ “jti”, Guid.NewGuid() }
// Optional properties
// { “exp”, (int)t.Add(TimeSpan.FromMinutes(30)).TotalSeconds } // Expiration time
};
string token = Jwt.JsonWebToken.Encode(payload, “secret key from sisense sso                 configuration”, Jwt.JwtHashAlgorithm.HS256);
string redirectUrl = “http://URL_of_your_sisense_web_app_with_port/jwt?jwt=&#8221; + token;

    if (return_to != null)
{
redirectUrl += “&return_to=” + UrlEncoder.Default.Encode(return_to);
}
return Redirect(redirectUrl);

  }

}

.Net Core 1.0.0 VS 2015 Tooling Preview Installation Issue

If you are trying to install tooling preview for .net Core 1.0.0 particularly or any other version and due to some reasons you are getting errors like you need to reinstall/repair VS 2015 professional with update 3 again, than you are at  the right place

Try running the following command in the command prompt. Don’t forget to go to the directory where the setup is located

NOTE: Change the exe as per your version of the tools

DotNetCore.1.0.0-VS2015Tools.Preview2.exe SKIP_VSU_CHECK=1

Building Single Page Applications using Web API and angularJS (Free e-book)

chsakell's Blog

Single Page Applications are getting more and more attractive nowadays for two basic reasons. Website users have always preferred a fluid user experience than one with page reloads and the incredible growth of several JavaScript frameworks such as angularJS. This growth in conjunction with all the powerful server side frameworks makes Single Page Application development a piece of cake. This post is the online version of the free e-book and describes step by step how to build a production-level SPA using ASP.NET Web API 2 and angularJS. You have two choices. Either grab a coffee and keep going on with this version or simply download the e-book and enjoy it whenever and wherever you want.
spa-webapi-angular-28
There are a lot of stuff to build in this application so I will break this post in the following sections:

View original post 9,862 more words

How to find Azure Subscription ID in the new Azure Portal

Nice thing to know if u r starting learning Azure

PR Code

Just a quick step by step on how to get you Subscription ID from the New Azure Portal.

1) Browse to https://portal.azure.com and Sign into your account.

Screen-Shot-2017-02-18-at-16.26.jpg2) Once you are in the portal you should see the sidepanel with a tab for’Subscriptions’. Click on this to get to the next section. If the tab is not visible, then click on the ‘More services’ tab to find it.

3)In the new open panel you will see all the subscriptions you have access to and in the ‘Subscription ID’ column is the what you are looking for.

Screen-Shot-2017-02-18-at-16.29.jpg

View original post

Getting Started with JMeter

This is a guide for someone who is trying to run JMeter for the very first time. So let’s dive into doing the stuff straight away by following the below steps

  1. First thing we need to do is to download JRT (java runtime environment), if we don’t have it installed already
  2. After installing JRT we need to download the Apache JMeter. I downloaded the .zip file under the binaries. if you can’t find it on the page click here. Please check on the Apache JMeter website there may be a newer version available.
  3. After unzipping the folder go to the bin folder and double click on jmeter.bat file which is highlighted in pic belowcapture
  4. This will start a console application, wait for few seconds and you will see a GUI for the JMeter.JMeter.PNG
  5. Now first thing we need to do is to create a Thread Group under the Test plan. So right click on Test Plan and go to Add -> Thread (Users) -> Thread Group. On this screen we can configure how many times this thread will run and few other things.
  6. Now right click on Thread Group in the tree and go to Add -> Sampler -> HTTP Request. On this pane we can configure the options related to http request.
    1. In the basic tab enter the server name of IP this can be a URL to your API Call
    2. Select implementation, in my case I selected HttpClient4
    3. Enter protocol, in my case I entered https
    4. Select method type i.e GET or POST or as per your api call
    5. In the path use the api function which is being called i.e the text appended after the main server address
    6. In the Body Data enter your json format data if your api call expecting that, otherwise do the needful as per your API implementation
  7. If your api call need some info to be appended in the header than right click on HTTP Request and go to Add -> Config Element -> HTTP Header Manager. Enter the data in key value pair. you can add data like  key = Content-Type, value=applicaiton/json
  8. If you want to validate the response of the API call, you can add Response Assertion by right clicking of HTTP Request and go to Add -> Assertions -> Response Assertion. The sample test is to be check the http response codes in this screen.
  9. If you want to extract the value from http response and use it and another http request. you can add the JSON Extractor or Regular Expression Extractor by right clicking HTTP Request and go to Add -> Post Processors -> JSON Extractor. The key fields in this page would be variable name (where your value will be stored to use in another http request), JSON path expression and match numbers. The format for JSON path expression is shown below. If you want to find only one match than Match Numbers should have 1 against it.json extractor.PNG
  10. Now in the end if someone wants to load sample data from csv for http requests then we need to add CSV data set config. Right click on Test Group and click on Add -> Config Element -> CSV Data Set Config. Key fields in this screen are
    1. Filename (Enter a full file path)
    2. Variable Names which will be use in http requests
    3. Delimiter usedcsv.PNG
    4. to use these variable in http request we need to change our http requests to be like this one. See how we changed the http request as per the variable names declared above.
      body-data
  11. In the end click on RUN to see the test results in View Results Tree

Code Optimization for Ajax JQuery Web Request

When we use ajax calls for consuming web methods we use the following method.

$.ajax({
type: “POST”,
url: url,
data: JSON.stringify(params),
contentType: “application/json; charset=utf-8”,
dataType: “json”,
success: function (result) {
if (result == null || result == undefined || result.d.trim() == ”) return;
successFunc(JSON.parse(result.d), targetObj);
},
failure: function (error)
{ }
});

 

But to use this code on each page and for each web method call is a repetition of  code and we can avoid that if we define it at one place and then consume it from there every time we need to use it.

One way of doing it is to enclose the code in a function like this below.

function ajax_data_loader(url, params, successFunc, targetObj) {
$.ajax({
type: “POST”,
url: url,
data: JSON.stringify(params),
contentType: “application/json; charset=utf-8”,
dataType: “json”,
success: function (result) {
if (result == null || result == undefined || result.d.trim() == ”) return;
successFunc(JSON.parse(result.d), targetObj);
},
failure: function (error)
{ }
});
}

So wherever we need to use it we only need to call the function with the appropriate parameters.

ajax_data_loader(‘FleetInspectionAnalysis.aspx/GetTreeFirstLevel’,{customer_auto:customer_auto},load_firstlevel,$(‘#fleet_tree’));

 

 

Multilingual app in Android

Android considers English as primary language by default and loads the string resources from res ⇒ values ⇒ strings.xml. When you want to add support for another language, you need to create a values folder by appending an Hyphen and the ISO language code. For example if you want to add support for Urdu, you should create a values folder named values-ur and keep a strings.xml file in it with all the strings translated into French language.

So for example if in your strings.xml you have a value like

<string name=”new_equipment”>Nouveau Équipement</string>

the corresponding entry in strings-ur.xml would be

<string name=”new_equipment”> نئی مشین</string>

After created respective strings.xml files for all your supported languages all you have to do is change the Language under the Settings ⇒ Language & Input and it will change the language of the app.