Skip to main content

Posts

Showing posts from 2018

Custom - Token Based Authentication in Web API

Authentication  is a vital process in system programming. Authentication means verifying the user who is accessing the system. Today we are using modern devices that have different types of Apps or software and sometimes we directly access the website from browser. To access this application, we probably need to pass our credentials and these systems verify it. If you are valid user then it will allow accessing the system otherwise not. We have available different types of authentication in .Net programming like Windows Authentication, Forms Authentication, Claim Based Authentication, Token Based Authentication etc. Today we will discuss about Token Based Authentication in detail. Token Based Authentication is not very different from other authentication mechanism but yes, it is more secure, more reliable and makes your system loosely coupled. It will be a better choice to create REST API using token-based authentication, if your API reached to broad range of devices like mob...

Web API - The type namespace name IdentityUser could not be found

There is no needs for - using IdentityUser ; using IdentityDbContext ; Instead you need to add following - using Microsoft . AspNet . Identity . EntityFramework ; Make sure you have that DLL as a reference as shown below. If it is not available, then you can get that nuget from  here . Ref:  https://stackoverflow.com/questions/21642388/the-type-namespace-name-identityuser-could-not-be-found

SQL Server - How to get first and last day of month

----Today SELECT GETDATE () 'Today' ----Yesterday SELECT DATEADD ( d ,- 1 , GETDATE ()) 'Yesterday' ----First Day of Current Week SELECT DATEADD ( wk , DATEDIFF ( wk , 0 , GETDATE ()), 0 ) 'First Day of Current Week' ----Last Day of Current Week SELECT DATEADD ( wk , DATEDIFF ( wk , 0 , GETDATE ()), 6 ) 'Last Day of Current Week' ----First Day of Last Week SELECT DATEADD ( wk , DATEDIFF ( wk , 7 , GETDATE ()), 0 ) 'First Day of Last Week' ----Last Day of Last Week SELECT DATEADD ( wk , DATEDIFF ( wk , 7 , GETDATE ()), 6 ) 'Last Day of Last Week' ----First Day of Current Month SELECT DATEADD ( mm , DATEDIFF ( mm , 0 , GETDATE ()), 0 ) 'First Day of Current Month' ----Last Day of Current Month SELECT DATEADD ( ms ,- 3 , DATEADD ( mm , 0 , DATEADD ( mm , DAT...

SQL Server - Call a webservice/WebAPI from TSQL code?

Stored Procedure to call Web Service sp_configure 'Ole Automation Procedures', 1 GO RECONFIGURE; GO sp_configure 'show advanced options', 1 GO RECONFIGURE; CREATE PROCEDURE CALLWEBSERVICE AS BEGIN     Declare @Object as Int;     Declare @ResponseText as Varchar(8000);     Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;     Exec sp_OAMethod @Object, 'open', NULL, 'get', 'https://jsonplaceholder.typicode.com/todos/1','false'     Exec sp_OAMethod @Object, 'send'     Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT     Select @ResponseText     Exec sp_OADestroy @Object END Ref: https://stackoverflow.com/questions/33449/can-you-call-a-webservice-from-tsql-code

Merge memorystreams to one iText document

Working code for me :)   Ref - https://stackoverflow.com/questions/8385690/merge-memorystreams-to-one-itext-document The error PDF header signature not found can be fixed in this case by setting the stream's Position back to 0 . Since you're not getting the error Cannot access a closed Stream I'm assuming that you are already correctly setting the PdfWriter 's CloseStream to false . Below is a full working C# 2010 WinForm app targeting iTextSharp 5.1.1.0 that creates three PDFs in MemoryStreams and combines them. Since I don't have a web server handy I'm writing them to disk. using System ; using System . Text ; using System . Windows . Forms ; using System . IO ; using iTextSharp . text ; using iTextSharp . text . pdf ; namespace WindowsFormsApplication1 { public partial class Form1 : Form ...

SQL Server Backup to multiple files (file size is different)

Please Use this Script to Backup your db in 10 files BACKUP DATABASE [Databas_Name] TO DISK = 'C:\MSSQL_Backup\Database_FileName1.bak', DISK = 'C:\MSSQL_Backup\Database_FileName2.bak', DISK = 'C:\MSSQL_Backup\Database_FileName3.bak', DISK = 'C:\MSSQL_Backup\Database_FileName4.bak', DISK = 'C:\MSSQL_Backup\Database_FileName5.bak', DISK = 'C:\MSSQL_Backup\Database_FileName6.bak', DISK = 'C:\MSSQL_Backup\Database_FileName7.bak', DISK = 'C:\MSSQL_Backup\Database_FileName8.bak', DISK = 'C:\MSSQL_Backup\Database_FileName9.bak', DISK = 'C:\MSSQL_Backup\Database_FileName10.bak' WITH INIT , NOUNLOAD , NAME = 'Databas_Name backup', NOSKIP , STATS = 10 , NOFORMAT  

How to Query Comma Separated Value Column in SQL

Introduction This is a small SQL function which will be useful for querying a Table which is having a comma separated value column. Background Sometimes, you encounter a column that stores comma separated values. This solution makes it easy to search such a column. However, it is recommended, if possible, to split the tables into two according to the First Normal Form . For example : Storing the days of week in CSV format [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Sunday], for months in numbers [1,2,3,4,5,6,7,8,9,10,11,12] I came across this requirement for storing the days in CSV format as reminder follow up for the user, and to query it. Problem Sometimes, we used to store a comma separated value in a column and which we will be using for some purpose in order to avoid creating a new table for that functionality. In this case, equals = search or contains Search or Like query will not work as expected to find one or more item presen...

MVC application Optimization

Main points - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1. Enable compression 2. Leverage browser caching 3. Minify CSS and Javascript 4. Minify HTML (GZip compression) 5. Optimize Images 6. Eliminate render-blocking JavaScript and CSS in above-the-fold content - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1. Enable compression HTTP Compression <httpCompression> http://www.iis.net/configreference/system.webserver/httpcompression compression should be enabled from Windows feature Turn On/Off - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - WINDOWS 8 OR WINDOWS 8.1 On the Start screen, move the pointer all th...