Skip to main content

Posts

Showing posts from December, 2018

How To Set Focus On Text Box In Angular 5.

Here, I will explain how to set focus on text box using ElementRef. Demo.html :  <input type="text" class="form-control" value="" #barcode placeholder="Barcode" [(ngModel)]="Barcode" (blur)="SetFocus()" /> Demo.Component.ts : import { Component, OnInit, ElementRef } from '@angular/core'; export class StockDataTableComponent implements OnInit, OnChanges {     @ViewChild('Barcode') barcode: ElementRef;      constructor(){}     function SetFocus(){            this.barcode = "";            this.barcode.nativeElement.focus();     } }

How To See Logs Of Dropped Tables From The Database in MS SQL.

Here, I will explain you how you can see logs of users. Step 1 : First, create a new database with name "test". Step 2 : Create a new table. Step 3 : Now, go and drop the table by running the following command. Step 4 : Now, select your database under Object Explorer and go to Reports >> Standard Reports >> Schema Changes History. Step 5 : You will then see the schema change history. The report will show you who has dropped this table. Finally, you can locate the user activity with the help of log.

How To Use Fluent Validation In .NET Core.

Sometimes, there are many validation rules in our methods, such as the employee name cannot be null, the age must be greater than 18, etc., and as usual, we may write some code for defining these rules. static void Main(string[] args) { var addEmployee = new AddEmployee(); AddEmployee(addEmployee); Console.ReadKey(); } static void AddEmployee(AddEmployee addEmployee) { if (string.IsNullOrWhiteSpace(addEmployee.EmployeeName)) { Console.WriteLine($"employee name cannot be null"); return; } if (string.IsNullOrWhiteSpace(addEmployee.EmployeePhone)) { Console.WriteLine($"employee phone cannot be null"); return; } if (addEmployee.EmployeeAge <= 0) { Console.WriteLine($"Employee must great than 0"); return; } //code for save values ... } However, this way seems not fluent. Here, I will introduce a s

How To Access Cookie Across Sub Domain In ASP.NET(C#).

Now a days Single Sign-On is a common need of organizations. Organizations want to use the same login details across their all application. Most of the times, internal applications are hosted on the same domain using Sub-Domains. If we observe the application level, all applications are different for every sub-domain. So, for that, we need to persist the Session or User Identity while accessing the applications. Here are some steps to achieve this in ASP.NET. Below are some of the configuration settings which you need to do in Web.config. <authentication mode="Forms">    <forms loginUrl="~/" name=".ASPXFORMSAUTH" timeout="20" domain=".xxxxxxxx.xxx" path="/" protection="All" enableCrossAppRedirects="true" />  </authentication> Here, you need to specify the parent domain with (.) so that it will get access of all sub domains of the parent domain. Add the above line to all applicatio

How To Implement NLog With WebAPI In Asp.Net(C#).

What is NLog? NLog is a flexible and free logging platform for various .NET platforms, including .NET standard. NLog is easy to apply and it includes several targets (database, file, event viewer). Which platform support it? .NET Framework 3.5, 4, 4.5, 4.6 & 4.7 .NET Framework 4 client profile Xamarin Android Xamarin iOS Windows Phone 8 Silver light 4 and 5 Mono 4 ASP.NET 4 (NLog.Web package) ASP.NET Core (NLog.Web.AspNetCore package) .NET Core (NLog.Extensions.Logging package) .NET Standard 1.x - NLog 4.5 .NET Standard 2.x - NLog 4.5 UWP - NLog 4.5 There are several log levels. Fatal : Something terrible occurred; the application is going down  Error : Something fizzled; the application might possibly proceed Warn : Something surprising; the application will proceed  Info : Normal conduct like mail sent, client refreshed profile and so on.  Debug : For troubleshooting; the executed question, the client confirmed, session terminated  Trace : For follow

HTML 5 Web Storage : Local and Session

In HTML 5 the web application can store the data locally within the browser which can’t be transferred to the server. Before HTML 5, the local data in client side was stored in the cookies. There are two types of web storage. Local Storage Session Storage Local Storage :   When we store data in Local storage, It can not be cleared until user manually clears the browser cache or pro-grammatically clears the storage. Add Data: Syntax : localStorage.setItem('key','value') Example : localStorage.setItem('name','Nikhil')  Read Data: Syntax : localStorage.getItem('key') Example : localStorage.getItem('name')  Update Data: Syntax : localStorage.setItem('key','value') Example : localStorage.setItem('name','Niks')  Delete Data: Syntax : localStorage. removeItem ('key') Example : localStorage. removeItem ('name')  Delete All Data From Local Stora

SQL Server Vulnerability Assessment

SQL Server Vulnerability Assessment in SQL Server Management Studio 17 or later lets SQL Server scan your databases for potential security vulnerabilities and it can be run against SQL Server 2012 or higher. If you are not using a new version of SQL Server Management Studio, you can download it from  here . The process is designed to meet the data privacy standards and compliance using knowledge base rules that look for deviations from Microsoft’s best practices. Using this you can improve your SQL Server’s security. To run an assessment simply choose a database, right-click and choose Tasks. Here, you will see Vulnerability Assessment choose that and Scan for Vulnerabilities. If you have run one previously, you can access it here by choosing Open Existing Scan. It will pop up a window to choose where you want the results saved. Once you click ok, the process will run. Here, you can see my results from the "chat"database. It has 3 failed items and 52 ha

Difference Between Undefined And Null In JavaScript

Here, I will explain the difference between Undefined and Null. If you are working with JavaScript then You have to know when we get a variable as undefined and when do we get it as null.  Undefined :  This means that the variable is not declared or variable is declared but the value is not assigned. For example, var abc;   alert(abc); //undefined    alert(typeof abc); //undefined  In the above code, we are able to see that the variable named "abc" is not assigned any value. So, it means that JavaScript considers the variable as undefined. If we check with alert, it will give undefined. We can check the type of the same variable, which is also undefined because the "abc" variable is never assigned a value. So, the unassigned variables are considered as undefined. null : This means that the variable is assigned with a null value. For example, var test= null;   alert(abc); //null   alert(typeof abc); //object  In

Upload And Download Files Using ASP.NET Core 2.0

Here, I will explain how to upload and download files in ASP.NET Core 2.0. First of all create an empty project with ASP.NET Core 2.0 and Update the Startup.cs file to add services and middle ware for MVC. public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddSingleton ( new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"))); services.AddMvc(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseDeveloperExceptionPage(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Demo}/{action=Index}/{id?}"); }); } } Now, Add a Controller with name "DemoController" and copy paste below action methods to upload and download th

Steps For Installing Visual Studio 2019 Preview and its new features.

This article explains how to install Visual Studio 2019 Preview in a step by step way. We can learn about a new feature of Visual Studio 2019 through this link . New Features Visual Studio 2019 Highlights on Develop, Collaboration, Debug, Azure, Technologies. We can know about the new features of Visual Studio 2019 Preview in here . Steps for installing Visual Studio 2019 Preview Step 1 : Using this link we are downloading Visual Studio 2019 Preview. Step 2 :  Click the "Download" button for downloading the VS 2019 executable file. Step 3: Find downloaded "vs_enterprise__1653779055.1544460128.exe". Open it and click on continue button for downloading.           Step 4 :  After completing the download and installation, then workloads will open. We need to select what are the workloads we need. Here, we selected ASP.NET and web development, .NET Core cross-platform development. After sel

Using IIF Logical Function in MS SQL.

The IIF function, which is available in SQL Server 2012, returns one of the two values depending upon whether the Boolean expression evaluates to either True or False. DECLARE @FirstArgument INT = 10 DECLARE @SecondArgument INT = 20 SELECT IIF ( @FirstArgument > @SecondArgument , 'TRUE', 'FALSE' ) AS [Output]

CHOOSE Logical Function in MS SQL.

The CHOOSE function, which is available in SQL Server 2012, will return the item at the specified index from the list of values which are available. In this example we have 3 values and we are asking to select the third value in the list which is "SQL Server 2012". SELECT 'Programming Language' = CHOOSE(3, 'C#', 'Java','Python')

File upload control validation using jQuery.

Here, I will explain how to apply jQuery validation on File Upload control. First of all I have put file upload control. <input type="file" name="passportphoto" id="passportphoto" /> <input type="button" name="submit" id="submit" value="submit" onclick="return CheckValidation();" > Here  I have put jQuery function for check validation. <script type="text/javascript"> var regex = /^([a-zA-Z0-9\s_\\.\-:\)\(])+(.jpg|.jpeg|.png|.pdf)$/; function CheckValidation() { var passportphoto = $('#passportphoto'); if (passportphoto[0].files.length > 0) { if (!regex.test(passportphoto[0].files[0].name.toLowerCase())) { alert('Only .jpg|.jpeg|.png|.pdf files allowed.'); return false; } } else { alert('Please select file.'); return false; } } </script>