Saturday, November 27, 2021

Session time in asp.net

 If you want to set the timeout to 20 minutes, use something like this:

    <configuration>
      <system.web>
         <sessionState timeout="20"></sessionState>
      </system.web>
    </configuration>

reference:-  https://stackoverflow.com/questions/1205828/how-to-set-session-timeout-in-web-config
https://www.c-sharpcorner.com/blogs/how-to-set-session-timeout-in-asp-net1

Change the website white background to black in google chrome dark mode - Chrome black extension

 There are two options:-

1)You can change by using

chrome://flags/#enable-force-dark 

>Click on enable(select "enabled with simple cielab based inversion") or (select "enable with selective inversion of everything") and than click on Relaunch.(Screenshot below)

or the best option you can select that I have tested (enabled the selective inversion of non-image elements)


----------------------------------*********************-----------------------------------
2) You can click on Customize Chrome (screenshot below)

>Than click on Colors and themes.(screenshot below)

Friday, November 26, 2021

server.mappath in asp.net

 

  • Server.MapPath(".")1 returns the current physical directory of the file (e.g. aspx) being executed
  • Server.MapPath("..") returns the parent directory
  • Server.MapPath("~") returns the physical path to the root of the application
  • Server.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)

Encryption and decryption of password in asp.net

 //For decryption of password

-----------------------------***************************------------------------------

  1. private string Decrypt(string clearText)  
  2.         {  
  3.             string EncryptionKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";  
  4.             byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);  
  5.             using (Aes encryptor = Aes.Create())  
  6.             {  
  7.                 Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });  
  8.                 encryptor.Key = pdb.GetBytes(32);  
  9.                 encryptor.IV = pdb.GetBytes(16);  
  10.                 using (MemoryStream ms = new MemoryStream())  
  11.                 {  
  12.                     using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))  
  13.                     {  
  14.                         cs.Write(clearBytes, 0, clearBytes.Length);  
  15.                         cs.Close();  
  16.                     }  
  17.                     clearText = Convert.ToBase64String(ms.ToArray());  
  18.                 }  
  19.             }  
  20.             return clearText;  
  21.         }  

------------------------********************--------------------
For encryption of password

  1.  private string Encrypt(string clearText)  
  2.         {  
  3.             string EncryptionKey = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";  
  4.             byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);  
  5.             using (Aes encryptor = Aes.Create())  
  6.             {  
  7.                 Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });  
  8.                 encryptor.Key = pdb.GetBytes(32);  
  9.                 encryptor.IV = pdb.GetBytes(16);  
  10.                 using (MemoryStream ms = new MemoryStream())  
  11.                 {  
  12.                     using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))  
  13.                     {  
  14.                         cs.Write(clearBytes, 0, clearBytes.Length);  
  15.                         cs.Close();  
  16.                     }  
  17.                     clearText = Convert.ToBase64String(ms.ToArray());  
  18.                 }  
  19.             }  
  20.             return clearText;  
  21.         } 

How to create foreign key in SQL server

 >First create two tables Customers and Employee tables

>Customer table with Primary key(ID)(screenshot below)


>Employee table with Foreign key as (customer ID)(Screenshot below)

>Right Click on customer ID(screenshot below)

>Click on Add if key is not added, than click on "Tables and columns specifications){screenshot below}


>Select the primary key table (customer table) and foreign key table (employee table){screenshot below}


reference :- https://www.mssqltips.com/sqlservertip/4790/how-to-create-a-sql-server-foreign-key/