tag:blogger.com,1999:blog-90074983715414270852024-03-16T11:50:30.822-07:00IT Tutorials with ExampleAnoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.comBlogger135125tag:blogger.com,1999:blog-9007498371541427085.post-50414520265877495322022-04-12T08:39:00.000-07:002022-04-12T08:39:14.248-07:00Working with MySQL Database in Google Cloud Platform<p>In this article, we will learn How to create MySQL Database and use gcloud CLI to create databases, tables, and run queries on database objects. </p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiu0axlpPl2LKqlYYUEgtQ2bWUfadZSk80yvIVqVP2BMkHrwds5m-DHD8TbXrgbm6e0yxoW8PA6i23P5irURR5JMIeSam6IqaNkUr6gmQnFl0OdqgQkLUAltCjt69TDJCepT--635Xr8aRyHtIb2jh52LgIxXOTNbsqXnEvYCyEuexqLv2KY3aLdu8K/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiu0axlpPl2LKqlYYUEgtQ2bWUfadZSk80yvIVqVP2BMkHrwds5m-DHD8TbXrgbm6e0yxoW8PA6i23P5irURR5JMIeSam6IqaNkUr6gmQnFl0OdqgQkLUAltCjt69TDJCepT--635Xr8aRyHtIb2jh52LgIxXOTNbsqXnEvYCyEuexqLv2KY3aLdu8K/s16000/Cover.jpg" /></a></div></div><span><a name='more'></a></span><div><div>A few Articles, which I already wrote and might be helpful for you if you are beginning with Google Cloud Platform are:</div>
<div class="clsImportant">
<div><a href="https://www.ittutorialswithexample.com/2020/08/setting-up-lamp-certified-by-bitnami-in.html" target="_blank">Setting Up LAMP Certified by Bitnami in Google Cloud Platform</a> </div>
<div><a href="https://www.ittutorialswithexample.com/2020/08/create-virtual-machine-google-compute-engine.html" target="_blank">Create Virtual Machine Instance in Compute Engine in The Google Cloud Platform</a> </div>
<div><a href="https://www.ittutorialswithexample.com/2020/08/create-storage-bucket-in-google-cloud-platform.html" target="_blank">Create a storage bucket in the Google Cloud Platform</a></div>
<div><a href="https://www.ittutorialswithexample.com/2020/08/getting-started-with-sql-in-google-cloud.html" target="_blank">Getting Started with Cloud SQL in Google Cloud Platform</a> </div>
<div><a href="https://www.ittutorialswithexample.com/2020/08/working-up-with-google-kubernetes-engine.html.html" target="_blank">Working Up With Google Kubernetes Engine In Google Cloud Platform</a> </div>
<div><a href="https://www.ittutorialswithexample.com/2020/09/deployment-manager-and-monitoring-in-google-cloud-platform.html" target="_blank">Deployment Manager and Monitoring in Google Cloud Platform</a> </div>
</div>
</div><div><br /></div><div><div><b>Let’s Begin</b>:</div><div><b>Step 1</b>: Log in with Google Cloud Platform by visiting https://console.cloud.google.com/ (Google provides $300 as a free trial, but for that, you need to link your credit card).</div></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuSjU9697roSYzUevKgt29Xb9FjJFPzPfbG1uGiTnGThPRkAZ7aauMpVVMNzbNe8qVEEwek3RG-dwDXyB-TWn7UejsxDeQRTi0v4lA7ZdxGh0BdNI4rxMVr3kIOSJGdpCUEn-XvcUv3ILrPAUotqfwDCB7UkXgZh6gtoVq1j1oWPl2ir8zI8VTKQSu/s548/Image1.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="548" data-original-width="536" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuSjU9697roSYzUevKgt29Xb9FjJFPzPfbG1uGiTnGThPRkAZ7aauMpVVMNzbNe8qVEEwek3RG-dwDXyB-TWn7UejsxDeQRTi0v4lA7ZdxGh0BdNI4rxMVr3kIOSJGdpCUEn-XvcUv3ILrPAUotqfwDCB7UkXgZh6gtoVq1j1oWPl2ir8zI8VTKQSu/s16000/Image1.png" /></a></div></div>
Once logged in you will be redirected to Google Cloud Dashboard as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAMpf2dqVxhzB8KiAB41BNetJPZrYuFWYUNMP6LHdCl5bqrSG2eTewh6ZVETUDBY1GYTTODLM7utksw8YiMcmgsZ3IQfQKPbEmW-G6y1BtqA7DhXJRWubCk2mfEp15m_fz_YUp4XHtlSIShKj_0aM68UxhCyuX8dtgxwwhF3rsJnl5nveyGepdDzwh/s530/Image2.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="337" data-original-width="530" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAMpf2dqVxhzB8KiAB41BNetJPZrYuFWYUNMP6LHdCl5bqrSG2eTewh6ZVETUDBY1GYTTODLM7utksw8YiMcmgsZ3IQfQKPbEmW-G6y1BtqA7DhXJRWubCk2mfEp15m_fz_YUp4XHtlSIShKj_0aM68UxhCyuX8dtgxwwhF3rsJnl5nveyGepdDzwh/s16000/Image2.png" /></a></div></div><b>Step 2</b>: You can view the menu list of Google Cloud Products and Services by clicking on the Navigation menu on the left side as highlighted. Go to the SQL menu option as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUtarIISE1Kp-D8dieEiyXy_etIvVoiU2j1lnAStwqe-5hz2fCBb-PIaCQhjl7ifjx1zUx702c8sgRvTbmaRZE3ziNplW68uFTQMkdtspQ5kEXxO0o5L8uhsroRwgQxI6CaQqi3-t3NfgzZtGZ0BOstyS3odQ9g57udRtdmlbvjlJyh_N6mmW-bb__/s350/Image3.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="350" data-original-width="286" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUtarIISE1Kp-D8dieEiyXy_etIvVoiU2j1lnAStwqe-5hz2fCBb-PIaCQhjl7ifjx1zUx702c8sgRvTbmaRZE3ziNplW68uFTQMkdtspQ5kEXxO0o5L8uhsroRwgQxI6CaQqi3-t3NfgzZtGZ0BOstyS3odQ9g57udRtdmlbvjlJyh_N6mmW-bb__/s16000/Image3.png" /></a></div></div><b>Step 3</b>: Click on Create Instance button as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_qlQZzkim1ogJ_Kkv7SSyXYOqJCGinLejZlnel65Dxcqez0ul5vqXlU3iXbQDLrQAVEBP6jvk1X7kxr0hEwsOw3tU9sMVk8z_24fymdvJFVtnzJjBrXm14QOoo1ud6leczKoQmvXBxH5SNbWqBm3MnY9GsUxi0txUg42sOtkAcwiY8ohF2DcsV5Xr/s550/Image4.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="296" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_qlQZzkim1ogJ_Kkv7SSyXYOqJCGinLejZlnel65Dxcqez0ul5vqXlU3iXbQDLrQAVEBP6jvk1X7kxr0hEwsOw3tU9sMVk8z_24fymdvJFVtnzJjBrXm14QOoo1ud6leczKoQmvXBxH5SNbWqBm3MnY9GsUxi0txUg42sOtkAcwiY8ohF2DcsV5Xr/s16000/Image4.png" /></a></div></div>Select the database engine for which you want to create the instance. I am selecting MySQL for demonstration.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-UoETy-OPn955DMpSnGT4kJMQfcEJZYlVU5y76f4oNhQeBLlfsb-XBlt2ujibuFF86RF6bFq4FYkrSMDCMtLx46G30GFr1PVL-l4RrqHq-a4xS_tgu_cUHVwZ7CT6owqo_p4GBHeZVRNHJJvLUvNJDlkya6-SZ6XCOZDH7_8p74-vprlSJDXqIRMt/s550/Image5.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="283" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-UoETy-OPn955DMpSnGT4kJMQfcEJZYlVU5y76f4oNhQeBLlfsb-XBlt2ujibuFF86RF6bFq4FYkrSMDCMtLx46G30GFr1PVL-l4RrqHq-a4xS_tgu_cUHVwZ7CT6owqo_p4GBHeZVRNHJJvLUvNJDlkya6-SZ6XCOZDH7_8p74-vprlSJDXqIRMt/s16000/Image5.png" /></a></div></div>Provide the Instance Id, Password, Database engine, Region, and zonal availability while creating the new MySQL Instance.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2yp-j-9o8nKZeC88nQgstViW_h-4s7-Nibv-nqzFOGM7nF_pp8QGoVKoXGRMAgg4eVZZmVCHhPcMiN1mcbaKmX2S4_Tc0v5XsaKsrRqFAM39-s0Q0BqEJsuEmy58LONw3rVCsnDDN00kR_Bv1TjdiYlkJQ-jZaGzU28YHUPxdHKNN_sV04oRY42ia/s550/Image6.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="316" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2yp-j-9o8nKZeC88nQgstViW_h-4s7-Nibv-nqzFOGM7nF_pp8QGoVKoXGRMAgg4eVZZmVCHhPcMiN1mcbaKmX2S4_Tc0v5XsaKsrRqFAM39-s0Q0BqEJsuEmy58LONw3rVCsnDDN00kR_Bv1TjdiYlkJQ-jZaGzU28YHUPxdHKNN_sV04oRY42ia/s16000/Image6.png" /></a></div></div>Select the zonal availability and click on the Create Instance button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidRDjewnkHNzaLxBUkAJPNxnAV2IN8lmOwsDg8vLdFWnsrmu_BCQbNVYXY53rLqHlWNiKjoQf8U1lTbF-twY7Z7xGttclfjdCtq_up1HtiPIVZK_z6Za4SPU03Zydgs8ebmJOiIQ8KvWbnL6qAtGsiFPqyqMlNfJ0dB7e2bQEV_L9EHCagE9KB0gR3/s529/Image7.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="387" data-original-width="529" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidRDjewnkHNzaLxBUkAJPNxnAV2IN8lmOwsDg8vLdFWnsrmu_BCQbNVYXY53rLqHlWNiKjoQf8U1lTbF-twY7Z7xGttclfjdCtq_up1HtiPIVZK_z6Za4SPU03Zydgs8ebmJOiIQ8KvWbnL6qAtGsiFPqyqMlNfJ0dB7e2bQEV_L9EHCagE9KB0gR3/s16000/Image7.png" /></a></div></div><b>Step 4</b>: You will see the instance id with the green tick icon once the instance is ready.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzSYlZmLqtXpv2EhgNevlcGvOVVORv9VO7xi8YixJXhB6U0Ccfb7SVgU_N-lsQWS01o_U3dCq3iPzEp0mRSjI20XEh5Fo2bMDRfUF197QF-Y8Pd3cI3MTFQPNO_TAJr7-6MLvK8VAX8WwRf6BQiTUJAhc9obkOJE1o908wnUjrAXqqlvY5mfki2968/s550/Image8.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="360" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzSYlZmLqtXpv2EhgNevlcGvOVVORv9VO7xi8YixJXhB6U0Ccfb7SVgU_N-lsQWS01o_U3dCq3iPzEp0mRSjI20XEh5Fo2bMDRfUF197QF-Y8Pd3cI3MTFQPNO_TAJr7-6MLvK8VAX8WwRf6BQiTUJAhc9obkOJE1o908wnUjrAXqqlvY5mfki2968/s16000/Image8.png" /></a></div></div>Now open the google cloud shell by clicking on the Cloud shell icon in the top right corner as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVEr7tEj0jOGybJWx4ABFCBPeNJ2ksj4Kru8Z4o-dYdbTGiiaHR_LuI2PKLQHvov2UEXbLnwEjy7yoSnoKDZnlcgZnW0UMwYR4X4bk3qopbuCA5X1ZCffTo9GBazhGPFSR376yUyhfrWvluT8Vcu-04PXV8z3PXof98H_4AQvPbLSqP1W3HqMctqJM/s265/Image18.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="195" data-original-width="265" height="195" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVEr7tEj0jOGybJWx4ABFCBPeNJ2ksj4Kru8Z4o-dYdbTGiiaHR_LuI2PKLQHvov2UEXbLnwEjy7yoSnoKDZnlcgZnW0UMwYR4X4bk3qopbuCA5X1ZCffTo9GBazhGPFSR376yUyhfrWvluT8Vcu-04PXV8z3PXof98H_4AQvPbLSqP1W3HqMctqJM/s1600/Image18.jpg" width="265" /></a></div></div>Run the below command in gcloud CLI to connect with MySQL Instance with the root user.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNv6gjaEjP61XwpT2xoLJT_jNJ3L-eXVTjR3am6qk0dQMKexl-ytdtQiyPe_uiRFOPE4LBjykhtK46S9HOMe6AuMaL1I1rccc1c50Yu1tFbM8NhIQ2coUM0_gYADpn-lIYltzzn9O7er9Q66bgof6LR-sJUYiJnLfU6_WXRopA_xUEeQl86exFK0UY/s370/Image9.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="55" data-original-width="370" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNv6gjaEjP61XwpT2xoLJT_jNJ3L-eXVTjR3am6qk0dQMKexl-ytdtQiyPe_uiRFOPE4LBjykhtK46S9HOMe6AuMaL1I1rccc1c50Yu1tFbM8NhIQ2coUM0_gYADpn-lIYltzzn9O7er9Q66bgof6LR-sJUYiJnLfU6_WXRopA_xUEeQl86exFK0UY/s16000/Image9.png" /></a></div></div>You will see a dialog for Authorizing Cloud Shell. Click on the Authorize button and provide the credential which was passed during the MySQL Instance creation.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibTEAGZ6dvJfQ-qUYrFt49xNH_5qZArrF5LuswbIIVyJxkDGtSzsakBXesoMJBvIOL6ZpYVr5voLMJPfDRzk1RFaybkycUORWZ-w9W5SU4-PreapadJ102tsx19EqDHPWxqpW3JOnWVoi-I5YQ39hSflotGLWlqt4RP9N6_VHwvEZUqILwkBS581AA/s436/Image10.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="234" data-original-width="436" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibTEAGZ6dvJfQ-qUYrFt49xNH_5qZArrF5LuswbIIVyJxkDGtSzsakBXesoMJBvIOL6ZpYVr5voLMJPfDRzk1RFaybkycUORWZ-w9W5SU4-PreapadJ102tsx19EqDHPWxqpW3JOnWVoi-I5YQ39hSflotGLWlqt4RP9N6_VHwvEZUqILwkBS581AA/s16000/Image10.png" /></a></div></div>You will see that MySQL is connected with a command-line shell.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiunNzHCQAwYeHRaEIHZqG-mJyAN1hifgLYBok3AJNSH5xqxFUVGoFauFRYpYALPbfwLU04aRYlJWO8fsTtb_w0h8ihkgPGTiFz1kjVk8UFxUJL3OXQbTXXICyJcAKp6d9pu6zmlBZl6RkuljWru881-0V6gL7meb4kePNqYsuAaRVNuEui64UcJMng/s550/Image11.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="204" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiunNzHCQAwYeHRaEIHZqG-mJyAN1hifgLYBok3AJNSH5xqxFUVGoFauFRYpYALPbfwLU04aRYlJWO8fsTtb_w0h8ihkgPGTiFz1kjVk8UFxUJL3OXQbTXXICyJcAKp6d9pu6zmlBZl6RkuljWru881-0V6gL7meb4kePNqYsuAaRVNuEui64UcJMng/s16000/Image11.png" /></a></div></div><b>Step 5</b>: Let’s try to create a database using the “<b>create database <DB_NAME></b>” command.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2jxBLrsD1kB8VI5LLjtRiyK93zWXEjp0x8PC6OgpVPIEMoe0xGvJRgLSQZ5yAZKzNUqu-4ePMPQycWxwnJ4OTeLNcII7s8uHky0zgfRnsTNcYZHdAThNgfj9dPnH3J-rlcLHMdlXOxBrPfpOnVey8bUW9MvBoeuWNh68VX27HF7UItHgDDuuBLvH9/s500/Image12.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="38" data-original-width="500" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2jxBLrsD1kB8VI5LLjtRiyK93zWXEjp0x8PC6OgpVPIEMoe0xGvJRgLSQZ5yAZKzNUqu-4ePMPQycWxwnJ4OTeLNcII7s8uHky0zgfRnsTNcYZHdAThNgfj9dPnH3J-rlcLHMdlXOxBrPfpOnVey8bUW9MvBoeuWNh68VX27HF7UItHgDDuuBLvH9/s16000/Image12.png" /></a></div></div>Switch to the database using the “<b>use <DB_Name></b>” query.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3ct_azmPMJVAp88TB3jPPtGtqc1sDyz8B4lqVwQItQNTsvCzLc2b15I2tfE87Ftrc7Ad5ZXNtT5t2CyK7ZgAwzS8t98y7It4wLVnjqIyHxfzdbzHYvWrTa1-L6oJOpymVoHtxu6k7Gn5CVBFolYN6cfZz15dNQ90TpSvlmbk3_XCqSuZh1uyLBNXf/s500/Image13.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="33" data-original-width="500" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3ct_azmPMJVAp88TB3jPPtGtqc1sDyz8B4lqVwQItQNTsvCzLc2b15I2tfE87Ftrc7Ad5ZXNtT5t2CyK7ZgAwzS8t98y7It4wLVnjqIyHxfzdbzHYvWrTa1-L6oJOpymVoHtxu6k7Gn5CVBFolYN6cfZz15dNQ90TpSvlmbk3_XCqSuZh1uyLBNXf/s16000/Image13.png" /></a></div></div>Let’s add a table named Users in the MySQL Database created in the above steps.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYmO9GDqmjyLBS-OZh_I5qx4jpakVv9zD2AvC7PpqjGL0-2QQ-t9J-q5lSMtzpHdEw6nwrSIRFiJ9_chaLL3WJOUsvCWAZRHtGYH-lRlwhs6KSrODMgymcviVQl7f37YCEhKrRMWJecr7ChNsTLap4wlubHzouoMHGWJWMxjAxK9yIQPscRQOjH7BA/s448/Image14.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="42" data-original-width="448" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYmO9GDqmjyLBS-OZh_I5qx4jpakVv9zD2AvC7PpqjGL0-2QQ-t9J-q5lSMtzpHdEw6nwrSIRFiJ9_chaLL3WJOUsvCWAZRHtGYH-lRlwhs6KSrODMgymcviVQl7f37YCEhKrRMWJecr7ChNsTLap4wlubHzouoMHGWJWMxjAxK9yIQPscRQOjH7BA/s16000/Image14.png" /></a></div></div>Insert sample data in the table using the Insert command as shown below.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjedPOWcZVO178siL79U0X1N5TXNi74nwcHlfF3oNXprqeCrA2TPW55BruvPQcPaUwG4VpG6Fcbfc5anvCyXoYXsUK9NrmaVHwPn2JRHTsSMIZq0Jbzp31LIHKwHfq5NTDSSzqHli9Vm9KZqibUX2kNGiG6P2i9Owaxa4H8aDf4m8pf9gxY9cMOzcwS/s484/Image15.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="43" data-original-width="484" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjedPOWcZVO178siL79U0X1N5TXNi74nwcHlfF3oNXprqeCrA2TPW55BruvPQcPaUwG4VpG6Fcbfc5anvCyXoYXsUK9NrmaVHwPn2JRHTsSMIZq0Jbzp31LIHKwHfq5NTDSSzqHli9Vm9KZqibUX2kNGiG6P2i9Owaxa4H8aDf4m8pf9gxY9cMOzcwS/s16000/Image15.png" /></a></div></div>Now run the Select query to view the records inserted in the table.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhkWxKowGcFQofAmnIKJcsmUgLKH4F2rMpSM5bay2UF9UM_oMsbfXPuwJuZAGpKPACRwjLvWhWjkjD0Q3BMAC_5eS77ZA4qjrwrylrUT50kaJTBNUzPIGvJ52wBAEd0tOqLhlLsugE5QVex75c95WAUEeNxu5BtsCKiIofM3atTzWa6M1rfDo2XQ1q/s530/Image16.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="112" data-original-width="530" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhkWxKowGcFQofAmnIKJcsmUgLKH4F2rMpSM5bay2UF9UM_oMsbfXPuwJuZAGpKPACRwjLvWhWjkjD0Q3BMAC_5eS77ZA4qjrwrylrUT50kaJTBNUzPIGvJ52wBAEd0tOqLhlLsugE5QVex75c95WAUEeNxu5BtsCKiIofM3atTzWa6M1rfDo2XQ1q/s16000/Image16.png" /></a></div></div>You can also create the database from the Google Cloud Platform User Interface by clicking on the Database menu option as shown in the below image. Users can also be created by clicking on the users’ menu and providing the access details like restricting the host by IP Address or address range.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2S76cP_vbGxbiN2RCsWE6MrLKWmedsCcVJyHUUp-6GnDHSzNmqzDj5LoRR36PpU-dncMnMek4NU5_NipOXdglz2O5xlqHQtZ3m2-i-HrQvKEJDZiMOFxVdreG1_5n6kUZovhjPgdmxehuRq6bPazU159GbyluSkABErK2FWuei16iF-WZP4eEGQ3v/s550/Image17.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="315" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2S76cP_vbGxbiN2RCsWE6MrLKWmedsCcVJyHUUp-6GnDHSzNmqzDj5LoRR36PpU-dncMnMek4NU5_NipOXdglz2O5xlqHQtZ3m2-i-HrQvKEJDZiMOFxVdreG1_5n6kUZovhjPgdmxehuRq6bPazU159GbyluSkABErK2FWuei16iF-WZP4eEGQ3v/s16000/Image17.png" /></a></div></div><div>I hope this article will help you in creating and working with the MySQL database.</div><div>Thanks</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM-pkAh3jB7nxKLpHrWNBgJfM0fgi2KfSl9WUAzyJdVoeAnEDy4MV0C6vCR1qG6UpaaSXvsvdHP_b4uOU6vqHb6wk9NBbVO8txOYP-okwQxer2GdKTGp80rgOsInd_7MLFpF4AOhwtazx4vC4cwFPNeWvKFq9t0c8JItJxxQTzj1WVTAK7GK76KnuT/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div><div><div><div><div><div><br /></div></div></div></div></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-49117001706312558082022-03-19T03:08:00.000-07:002022-03-19T03:08:28.793-07:00Program to remove the duplicate character from the string<p>In this program, we will learn How to remove the duplicate character from the string in C#.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhuFszC9OoXy0FdUDFa09K5hlA0FR5X5fMnS2veGA8UQVCnkdlzGMVTnHxpPdzsOM7NxvnTAxELFPIuQBvNAfqABOgLLaX3kFOajsHF--EYgSPG6c48GVzwMvRiNWdPRyirfdksECT63sOtWbIZtizd2t8LGAnCCQyIwXUyCd7McBFFYg7tC8NsUAoz=s550" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/a/AVvXsEhuFszC9OoXy0FdUDFa09K5hlA0FR5X5fMnS2veGA8UQVCnkdlzGMVTnHxpPdzsOM7NxvnTAxELFPIuQBvNAfqABOgLLaX3kFOajsHF--EYgSPG6c48GVzwMvRiNWdPRyirfdksECT63sOtWbIZtizd2t8LGAnCCQyIwXUyCd7McBFFYg7tC8NsUAoz=s16000" /></a></div></div>
<div class="clsImportant">
<div>I will recommend you to check the below link for Top C# Interview Programs asked during the Interview and Examination.</div>
<div><a href="https://www.ittutorialswithexample.com/2020/09/top-csharp-programs-for-interview.html.html" target="_blank">Top C# Program for Interview</a></div>
</div>
<div><br /></div><div><div><b>Program to remove the duplicate character from the string</b></div><div>As C# in the case-sensitive language, I am converting the string to the lowercase string so that I can compare the characters otherwise capital characters and small alphabetical characters will be treated as different characters.</div><div>Program to remove the duplicate character from the string in C# in mentioned below:</div></div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter a string to remove duplicate character from
it:"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Receive input from the user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> inputString = Console.ReadLine();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Converting the inputString to
lowercase</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//other wise Uppercase and
lowercase will be considered as difference character</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">inputString =
inputString.ToLower();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//result for holding the distinct
characters</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> result = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;">.Empty;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Loop through each character of
the string</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">for</span><span style="font-family: Consolas; font-size: 9.5pt;"> (</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> i = 0; i < inputString.Length;
i++)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">
//If character is not added (contains) in the result variable, Add it
to the result string</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;">
(!result.Contains(inputString[i]))<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> result += inputString[i];<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Show the final result to the
user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(result);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Console.ReadLine() to hold the
screen after the execution of the program</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.ReadLine();</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div><p><b>Output</b>:</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEikcbDI4nwk0Qqa534BEahcUrRnDyKcpEUO_qa30qwd7pp9bH6Ua1Qk0SDhVjxhRXv0RyTMmYMIVyyfjbeqYxRcmkuSDm_UJ9XiNSNC0vdTjgyJSJEvX_uZ8bBrUz2UsVltCkQ3UZATAFK-zjjU6GIKJMe1qkZchV-9XxRkG0l-jMMq8TqwDqACUgJd=s550" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="193" data-original-width="550" src="https://blogger.googleusercontent.com/img/a/AVvXsEikcbDI4nwk0Qqa534BEahcUrRnDyKcpEUO_qa30qwd7pp9bH6Ua1Qk0SDhVjxhRXv0RyTMmYMIVyyfjbeqYxRcmkuSDm_UJ9XiNSNC0vdTjgyJSJEvX_uZ8bBrUz2UsVltCkQ3UZATAFK-zjjU6GIKJMe1qkZchV-9XxRkG0l-jMMq8TqwDqACUgJd=s16000" /></a></div></div><div>I hope this example will help in your interview/exam preparation.</div><div>Thanks</div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img alt="Protected by Copyscape - Do not copy content from this page." border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/a/AVvXsEgh5TdutOZi1O8CnUD5GPPXGcc9wpiYfdHsBq58Fdid2Ui25i7ZxWFwHdLY0qJu8lRSYA3V2n6WAz-Q2L40_DgZXV2tULwyx5_blmld4vo2lPicUNIInW7WDrQcuPV_y0am9sqQ5yJNn8hX4E51SeEDbDQClav3KaAht3rhsl31Qh-JXBM8IXmxYUS-=s16000" /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-86577677805418813872022-02-18T19:44:00.004-08:002022-03-25T12:29:23.503-07:00Learn Angular in Hindi (YouTube Series)<p>Recently, we have begun the “<b>Learn Angular in Hindi</b>” Series on our official YouTube channel. Many people commented/wrote us to start a series in Hindi on it. We need your support to make it successful. Please do like 👍 and <a href="https://www.youtube.com/channel/UCaMFl4Zr4G9eWEpcvPNzLDQ?sub_confirmation=1" target="_blank">subscribe</a> ❤ to our channel if found useful. </p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiWZt0D1d0mye-wsnUqFsHLWuEtDNuWtj_WOnK4I6qyF8g5ncGqONUjoS2jhswdJCTyd-IWOFE6pCbO08TyWfE2hJD40ewxjbobtMehPaMo4TIvC7yuWmB-ylfrPS3ZqCuuvW-HuAZdmZ8SrrTZpYPivxpRD5fq0pQmtqqm9sPF4bB-SROYD88lu-IV=s550" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/a/AVvXsEiWZt0D1d0mye-wsnUqFsHLWuEtDNuWtj_WOnK4I6qyF8g5ncGqONUjoS2jhswdJCTyd-IWOFE6pCbO08TyWfE2hJD40ewxjbobtMehPaMo4TIvC7yuWmB-ylfrPS3ZqCuuvW-HuAZdmZ8SrrTZpYPivxpRD5fq0pQmtqqm9sPF4bB-SROYD88lu-IV=s16000" /></a></div></div><span><a name='more'></a><div>Below are the videos uploaded on YouTube.</div><div><br /></div><div><b>1. Introduction to Angular: </b>In this video, you will get a basic idea about Angular.</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen="" class="BLOG_video_class" height="309" src="https://www.youtube.com/embed/tX3T0TZzJEY" width="550" youtube-src-id="tX3T0TZzJEY"></iframe></div><br /><div>Below is the presentation used in the above video.</div>
<iframe allowfullscreen="" frameborder="0" height="420" marginheight="0" marginwidth="0" scrolling="no" src="//www.slideshare.net/slideshow/embed_code/key/CryWqW3GV0RcxR" style="border-width: 1px; border: 1px solid #CCC; margin-bottom: 5px; max-width: 100%;" width="510"> </iframe>
<div><br /></div><div><b>2. Step by Step Node.js installation: </b>In this video, you will learn How to install Node.js (Step by Step) .</div><div><br /></div>
<iframe allowfullscreen="" class="BLOG_video_class" height="309" src="https://www.youtube.com/embed/YL2FUQNLg-Q" width="550" youtube-src-id="YL2FUQNLg-Q"></iframe>
<div><b><br /></b></div><div><b>3. Angular CLI Installation: </b>In this Video, You will How to Install Angular CLI with npm i.e. Node Package Manager.</div><div><br /></div>
<iframe allowfullscreen="" class="BLOG_video_class" height="309" src="https://www.youtube.com/embed/Wq5t_j16OKs" width="550" youtube-src-id="Wq5t_j16OKs"></iframe>
<div><b><br /></b></div><div><b>4. Create Angular Application using Angular CLI: </b>In this video, you will learn How to create a new Angular Application using Angular CLI (Command Line Interface).</div><div><br /></div>
<iframe allowfullscreen="" class="BLOG_video_class" height="309" src="https://www.youtube.com/embed/hxRWtfRaaMA" width="550" youtube-src-id="hxRWtfRaaMA"></iframe>
<div><br /></div><div><b>5. Install Visual Studio Code</b>: In this video, you will learn How to Install Visual Studio Code (VS Code) step-by-step in Hindi.</div><div><br /></div>
<iframe allowfullscreen="" class="BLOG_video_class" height="309" src="https://www.youtube.com/embed/7ngfOkmw2tI" width="550" youtube-src-id="7ngfOkmw2tI"></iframe>
<div><br /></div><div><b>6. Understand Angular Project Structure in Hindi</b>: In this video, you will learn and understand the File and Folder structure of an Angular Project in Hindi.</div><div><br /></div>
<iframe allowfullscreen="" class="BLOG_video_class" height="309" src="https://www.youtube.com/embed/Xmz_wnO9aPk" width="550" youtube-src-id="Xmz_wnO9aPk"></iframe>
<div><br /></div><div><b>7. Bootstrapping an Application in Angular in Hindi</b>: In this video, you will learn How Angular Applications load or bootstraps. </div><div><br /></div>
<iframe allowfullscreen="" class="BLOG_video_class" height="309" src="https://www.youtube.com/embed/XwXnLAVFINU" width="550" youtube-src-id="XwXnLAVFINU"></iframe>
<div><br /></div><div><b>8. Text Interpolation in Angular</b>: In this video, you will learn about Text Interpolation or String Interpolation in Angular in Hindi.</div><div><br /></div>
<iframe allowfullscreen="" class="BLOG_video_class" height="309" src="https://www.youtube.com/embed/g4leV_UDh5c" width="550" youtube-src-id="g4leV_UDh5c"></iframe>
<div><br /></div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" height="16" src="https://blogger.googleusercontent.com/img/a/AVvXsEhESCPfAij-QyNtRkbVnPaiWDmZh8msGYmBGqEfnKRhCO_QdfmyoGC7hSBR7M9AEIuhAARWRRlTt27T-RN2qSN67F-Sd3rqWlpVvZqQDMpOw34dtHdNYkXGoDQlM52DRYHpElHxQnvkNSKm0WbyFNuB3Op3p6_xk1NRgVydz0IYN7OtoRlokMDbcxFO" width="234" /></a></div><div><br /></div></span>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-64037641541533803802022-01-15T10:40:00.000-08:002022-01-15T10:40:03.182-08:00How to Install SQLyog Community Edition<p>In this article, we will learn How to install SQLyog Community Edition in Windows Operating System. Currently, I am using it to access the MySQL Database. In case you are looking to install MySQL or MySQL Workbench then please check the below article.</p><p></p><ul style="text-align: left;"><li><a href="https://www.ittutorialswithexample.com/2021/05/how-to-install-mysql-in-windows.html" target="_blank">How to Install MySQL in Windows Operation System</a></li></ul><p></p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEg5s-tIRBioh9R5C66PK5L5oqshIxX5TSnbDELAgoc2eDX0-QmJXBaK8PRX_GtgmVlKKfPnSb8_a3jFl4mgRfRVF6fP-Gv-EXtKjKYv_GtSHXnaIzNL0rB_CmChuzqOb68MYiCAQrmWHhEKBlm6eBfsCd8OH9KvHCCMUhk0YvoXGABtK716tUM-k3TM=s550" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/a/AVvXsEg5s-tIRBioh9R5C66PK5L5oqshIxX5TSnbDELAgoc2eDX0-QmJXBaK8PRX_GtgmVlKKfPnSb8_a3jFl4mgRfRVF6fP-Gv-EXtKjKYv_GtSHXnaIzNL0rB_CmChuzqOb68MYiCAQrmWHhEKBlm6eBfsCd8OH9KvHCCMUhk0YvoXGABtK716tUM-k3TM=s16000" /></a></div></div><p><span></span></p><a name='more'></a><p></p><p><b>Let’s Begin:</b></p><p>Go to Google and search for the SQLyog Community. Click on GitHub’s link to download the community edition.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgEfsOKOqjRBuYklenCDDdgATuvOQ8FWmXL8bMHq8LV4NgawZbuFU0L8d36J3lU7U-t074nEjTnrOnpk-yGPws0v8kI517VKykyztOcuTQgzgRdXFYyou1JV6f5RBroN9afHhd78mE6KP-iEq4IA1i96r5gpCKkzLaCeH6IJUySLEfNEbRB_IdeQHsh=s550" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="254" data-original-width="550" src="https://blogger.googleusercontent.com/img/a/AVvXsEgEfsOKOqjRBuYklenCDDdgATuvOQ8FWmXL8bMHq8LV4NgawZbuFU0L8d36J3lU7U-t074nEjTnrOnpk-yGPws0v8kI517VKykyztOcuTQgzgRdXFYyou1JV6f5RBroN9afHhd78mE6KP-iEq4IA1i96r5gpCKkzLaCeH6IJUySLEfNEbRB_IdeQHsh=s16000" /></a></div></div>Download the SQLyog Community edition as per your system architecture.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhb9zR_-eU744zWFhkfF_uqgqZZlrwJBYzBjplKXNvsN74QIDvGay7lDi1Z1msXGSHIgw-i29uvIY8bt02_M4o2f8we0xpWaZ5X2wxhKeWOREiUMIZhxbUTHdMyZzS2Bs0AtD3JG3kbwUPmFvuqLVTTHRTohcl8XRFnaBhLvGLRjNwLRrFsunHEkSHE=s550" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="408" data-original-width="550" src="https://blogger.googleusercontent.com/img/a/AVvXsEhb9zR_-eU744zWFhkfF_uqgqZZlrwJBYzBjplKXNvsN74QIDvGay7lDi1Z1msXGSHIgw-i29uvIY8bt02_M4o2f8we0xpWaZ5X2wxhKeWOREiUMIZhxbUTHdMyZzS2Bs0AtD3JG3kbwUPmFvuqLVTTHRTohcl8XRFnaBhLvGLRjNwLRrFsunHEkSHE=s16000" /></a></div></div>Double click on the downloaded SQLyog setup file to proceed with the installation.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjJYutfqenLNBhP_mOIZ0tps_5p5NKJz3HNgze-qvS5rFjnbQlf_bs1aQgRLDiy1H8ZYGbixn8EerZLBEGly9LG5a3KGhDHJjW8jE2K0cqFIDiM6XyImcUbfnhXHT6pMR2OvR2oToN8dcSB-qNqgeULOoaAOK9H-VDXPNtXIrBpiOrRM2WSuXNcfZQu=s516" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="55" data-original-width="516" src="https://blogger.googleusercontent.com/img/a/AVvXsEjJYutfqenLNBhP_mOIZ0tps_5p5NKJz3HNgze-qvS5rFjnbQlf_bs1aQgRLDiy1H8ZYGbixn8EerZLBEGly9LG5a3KGhDHJjW8jE2K0cqFIDiM6XyImcUbfnhXHT6pMR2OvR2oToN8dcSB-qNqgeULOoaAOK9H-VDXPNtXIrBpiOrRM2WSuXNcfZQu=s16000" /></a></div></div>Select the Installer language and click on the Ok button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEj9OX3MhxgdpWcnwMvpCLRhtYazLemR94XlXCezcUGca9L0Gdl6nV8Y1goUEDHTo49rn5XCpQHZU8PmiIjJVOn4P9V_jh3BbnJXhi2PDmPyjHzu_nsTGZXiytNOcXukLkFLO9WCJrsoQ4Zb4HMfaTQw4Mrsja3g74DPF7hxXZ6ReZO-kRWDwumPIrb6=s290" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="155" data-original-width="290" src="https://blogger.googleusercontent.com/img/a/AVvXsEj9OX3MhxgdpWcnwMvpCLRhtYazLemR94XlXCezcUGca9L0Gdl6nV8Y1goUEDHTo49rn5XCpQHZU8PmiIjJVOn4P9V_jh3BbnJXhi2PDmPyjHzu_nsTGZXiytNOcXukLkFLO9WCJrsoQ4Zb4HMfaTQw4Mrsja3g74DPF7hxXZ6ReZO-kRWDwumPIrb6=s16000" /></a></div></div>In the installation wizard, you will see a welcome message and some guidelines which need to be followed before starting the installation.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi8yYlmVj_WTahvxX1QVEPrqR_E_ObZzhIXr_Vh11nayTZwYViRS0Kfy4qFB_5LIt5DLI0z2yj8HNYPMWMz9rf5L5nCmMXfKd0UdtiGCERWiHc7T6TxxNRLg6qwNtkA2UFoJab9Q56y92p68dVXBXNpvp4yHbgU7XJmwuvJFTjvdu3F2tq8RCWzDumn=s499" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="388" data-original-width="499" src="https://blogger.googleusercontent.com/img/a/AVvXsEi8yYlmVj_WTahvxX1QVEPrqR_E_ObZzhIXr_Vh11nayTZwYViRS0Kfy4qFB_5LIt5DLI0z2yj8HNYPMWMz9rf5L5nCmMXfKd0UdtiGCERWiHc7T6TxxNRLg6qwNtkA2UFoJab9Q56y92p68dVXBXNpvp4yHbgU7XJmwuvJFTjvdu3F2tq8RCWzDumn=s16000" /></a></div></div>Go through the license agreement, accept the term of the license agreement and click on the next button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi3XQLxRACfuUWORuLIUau27Sqi1drLD6NzQ9uBsKDXN8zPjoKm-H5cGG6iHSN1lq6M9TCXoazbehASIwkNcGUt-OIbC0q2HR7OQQQoXeSv6vm223kfybBxSXqoZA7FPUG7BxDj8ymm80dUnGntM8CLmOl3bCuyPs3ipOsWQ9hDYKTVDLUvRlNpQMHQ=s499" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="388" data-original-width="499" src="https://blogger.googleusercontent.com/img/a/AVvXsEi3XQLxRACfuUWORuLIUau27Sqi1drLD6NzQ9uBsKDXN8zPjoKm-H5cGG6iHSN1lq6M9TCXoazbehASIwkNcGUt-OIbC0q2HR7OQQQoXeSv6vm223kfybBxSXqoZA7FPUG7BxDj8ymm80dUnGntM8CLmOl3bCuyPs3ipOsWQ9hDYKTVDLUvRlNpQMHQ=s16000" /></a></div></div>Select the components you want to install and click on the Next button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiLVhiwaezzcyajeLm1dWizsZhNxklw4-N0aqhaOsmvUn5C2p267SrOCLxA2q_vrXDH3AADe0T7DG8ikmoA7iKi5XaTnDqZEqguxDusoV4ODnOYM83ucb6YmlPEspgGQ0vSJSWL8tno7lYcd1va_lHfDCjRLnKRtvHeT36UniU-b_jwSWOx62y8mCZi=s499" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="388" data-original-width="499" src="https://blogger.googleusercontent.com/img/a/AVvXsEiLVhiwaezzcyajeLm1dWizsZhNxklw4-N0aqhaOsmvUn5C2p267SrOCLxA2q_vrXDH3AADe0T7DG8ikmoA7iKi5XaTnDqZEqguxDusoV4ODnOYM83ucb6YmlPEspgGQ0vSJSWL8tno7lYcd1va_lHfDCjRLnKRtvHeT36UniU-b_jwSWOx62y8mCZi=s16000" /></a></div></div>Choose the destination folder where you want to install the SQLyog community edition. Click on the install button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjX_GERW4-wv9noNvjshVrcUihmlQB4aeaIN1mJTVo0oq0ZlmfX-vNwQE85t0n240igrWA5qXT-did4y4C2BUA5Jh4Vt8r0JlZRhY6of425oGvBQBYfEXBnVJRmrslrElnDzAj01_WwH9SRrw2vX8Q6ILD1PGJx_MQcbhNw9gM4os_M82dO4gEOqPKQ=s499" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="388" data-original-width="499" src="https://blogger.googleusercontent.com/img/a/AVvXsEjX_GERW4-wv9noNvjshVrcUihmlQB4aeaIN1mJTVo0oq0ZlmfX-vNwQE85t0n240igrWA5qXT-did4y4C2BUA5Jh4Vt8r0JlZRhY6of425oGvBQBYfEXBnVJRmrslrElnDzAj01_WwH9SRrw2vX8Q6ILD1PGJx_MQcbhNw9gM4os_M82dO4gEOqPKQ=s16000" /></a></div></div>Within a few moments, Installation will be completed. Click on the Next button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiA6kszJM-ryXiRuzqmX9WhHEPZVU2JRpjludik3_1leZqvJORu4IIX5lKTWQo3e2FxaTm7Ca8k76OpHHWxOWHjjueZ78tvSuk2CyTQruJdGLwrjjAAfTjfKJlygFZZlItFTQ2AWo4_WJuc5iKHKBSkNt1lLznrpo-X3Ik44DW8r4KyKXrf7ULQe3IK=s499" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="388" data-original-width="499" src="https://blogger.googleusercontent.com/img/a/AVvXsEiA6kszJM-ryXiRuzqmX9WhHEPZVU2JRpjludik3_1leZqvJORu4IIX5lKTWQo3e2FxaTm7Ca8k76OpHHWxOWHjjueZ78tvSuk2CyTQruJdGLwrjjAAfTjfKJlygFZZlItFTQ2AWo4_WJuc5iKHKBSkNt1lLznrpo-X3Ik44DW8r4KyKXrf7ULQe3IK=s16000" /></a></div></div>Click on the Finish button and run the SQLyog Community edition application.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgwSOgp9na_W8ZKeQFb-n6nb7HfrGsTb5nZ3-W22-A5S9ZgpygFS8BlgEWSVGngiq7q9bBUAvuYNrgq2lctxWr2mNiabm6dqfqfjEafqd3QGy5Jq18F_-KMoeADuJ-gyXLH-m181Q_pTO0x4o6-X1ciyGPqNJ6kTO72g0CzlgU-mL_olkdYz5z3KREN=s499" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="388" data-original-width="499" src="https://blogger.googleusercontent.com/img/a/AVvXsEgwSOgp9na_W8ZKeQFb-n6nb7HfrGsTb5nZ3-W22-A5S9ZgpygFS8BlgEWSVGngiq7q9bBUAvuYNrgq2lctxWr2mNiabm6dqfqfjEafqd3QGy5Jq18F_-KMoeADuJ-gyXLH-m181Q_pTO0x4o6-X1ciyGPqNJ6kTO72g0CzlgU-mL_olkdYz5z3KREN=s16000" /></a></div></div>For the first time, SQLyog will ask you to select the UI language for your application. Select the language as per your requirement and click on the OK button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhMLxYUT6DgegKylHBg6EurisFtvx4uNfQYAxQQy1iczwActwev1Uv7AFewcYuuyuc8oEQ-HMPAO8jQaPmvEcJaRvG9o7G9CL8t0VfUfYZHBKQYFt3i5IOmqEYkdllQmvywn5uiyNpd4lfeIqFvjEcn-kS9Sv6RC2An8gC3gY6wFOqUUKk6KJenJKb4=s320" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="128" data-original-width="320" src="https://blogger.googleusercontent.com/img/a/AVvXsEhMLxYUT6DgegKylHBg6EurisFtvx4uNfQYAxQQy1iczwActwev1Uv7AFewcYuuyuc8oEQ-HMPAO8jQaPmvEcJaRvG9o7G9CL8t0VfUfYZHBKQYFt3i5IOmqEYkdllQmvywn5uiyNpd4lfeIqFvjEcn-kS9Sv6RC2An8gC3gY6wFOqUUKk6KJenJKb4=s16000" /></a></div></div>Click the New button in Connect to MySQL Host dialog and provide the MySQL database connection details which include MySQL Hostname, username, password, port, database, etc. Once all the fields are provided, click on the connect button.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjRZhaKyRWcweDlRbEdd4nZTo370yoCS4c_yM4z-VDcd1DQ84DFPHXt7-dPnstg1Lw29bEtQoHV_dkD4KcxNzPvyTrTVJ1grzg0KqAJtN6_Ty-gEGNIR4cBjbP-sGSvl_kTuF1Qtou6C7Fs-rbK4ZBxLqosPVBlQCVJS6EEaCq9GutCvp0wnAJYxHiV=s550" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="447" data-original-width="550" src="https://blogger.googleusercontent.com/img/a/AVvXsEjRZhaKyRWcweDlRbEdd4nZTo370yoCS4c_yM4z-VDcd1DQ84DFPHXt7-dPnstg1Lw29bEtQoHV_dkD4KcxNzPvyTrTVJ1grzg0KqAJtN6_Ty-gEGNIR4cBjbP-sGSvl_kTuF1Qtou6C7Fs-rbK4ZBxLqosPVBlQCVJS6EEaCq9GutCvp0wnAJYxHiV=s16000" /></a></div></div>I already have a Sample Database on my local MySQL database server. For demonstration, I ran some queries which are returning result set successfully.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgLT0XkM6mCW_Mf1ObS9aZaHFQboo0mJckBj8vHzFfn0qlNDIX5DzWVR0D52dcuIvhfuE-SNl3fVr9ljbJYoKqNdn8sNcZa0tL9Vi5b5r1aT0VaU7ilr_U4eVEipxWJqlVLeXAqAgxjuMt8q5QSHAV7gBOrvQqcr3GPwFfNreScjD7sWmndsyISo8EY=s550" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="366" data-original-width="550" src="https://blogger.googleusercontent.com/img/a/AVvXsEgLT0XkM6mCW_Mf1ObS9aZaHFQboo0mJckBj8vHzFfn0qlNDIX5DzWVR0D52dcuIvhfuE-SNl3fVr9ljbJYoKqNdn8sNcZa0tL9Vi5b5r1aT0VaU7ilr_U4eVEipxWJqlVLeXAqAgxjuMt8q5QSHAV7gBOrvQqcr3GPwFfNreScjD7sWmndsyISo8EY=s16000" /></a></div></div>I hope this article will help you in the installation of the SQLyog.<br /><div>Thanks.<br /><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" rel="nofollow" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" height="16" src="https://blogger.googleusercontent.com/img/a/AVvXsEg636W9E3VPUAMiabTvE-YaXJYO_m80UpAOSPxLkBay6jh5y-2cZo4Tb-BA3-_fRiIuAmUPJ-6pQTEmz876XUsyj4yk6PmcEOsDJRxyBgTf4r361bhmv2wErdYXz8JQD92GkMDzc_CDpeWsngNZcXG6sZFWgMb0R7jTsBLhFLEYiTW8MVE6qat0zyTP" width="234" /></a></div></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-13661531709556161352021-05-23T06:30:00.002-07:002021-05-23T06:36:09.125-07:00How to Install MySQL in Windows Operating System<p>In this article, we will see How to install MySQL in Windows operating system step by step. MySQL is one of the popular open-source RDBMS (Relational database management system).</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQfCiKKYzRurDDfKgfg2MOQR3wEe8b5qbegxIG_JGHAaxV_-JHjhLdxep9KqpW2DwOn8TywdFKKyJoBMvXPDx9KQvfmDV2zyNeIizrGhlukTo5qzAO1HQ6s382Rr7DLeUQELyq1u0B5P8/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQfCiKKYzRurDDfKgfg2MOQR3wEe8b5qbegxIG_JGHAaxV_-JHjhLdxep9KqpW2DwOn8TywdFKKyJoBMvXPDx9KQvfmDV2zyNeIizrGhlukTo5qzAO1HQ6s382Rr7DLeUQELyq1u0B5P8/s16000/Cover.jpg" /></a></div></div><span><a name='more'></a></span><div><br /></div>
<div class="clsImportant">
<h3 style="text-align: left;"><b>What is MySQL</b>?</h3>
<div>MySQL is one of the popular open-source RDBMS (Relational database management system). It is so used by many popular websites like Facebook, Twitter, YouTube, Flickr, etc. MySQL was owned and sponsored by the Swedish company, MySQL AB, which was brought by Sun Microsystems, now Sun Microsystem is acquired by Oracle Corporation.</div></div>
<div><br /></div><div><div><b>Let’s begin</b>:</div><div>Go to the official website of MySQL in order to download the MySQL Installer for Windows. You can also search for “MySQL Database Installation” in Google as shown in the below image. Click on the Download MySQL Installer link.</div></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHYLVK9MNBjEkMwOOiq67dHRgVWsORD-9oI-93Tf0XEOhtYIKfL4DDrTBxcI5_NHKCAj2PhgQH66My6fxX8qmwPDWo2cAZ6HEwiPDoKQewwFgkyKFDe0chhyphenhyphenimRioAXEQG1bYgjk4aOZA/s550/Image1.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="187" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHYLVK9MNBjEkMwOOiq67dHRgVWsORD-9oI-93Tf0XEOhtYIKfL4DDrTBxcI5_NHKCAj2PhgQH66My6fxX8qmwPDWo2cAZ6HEwiPDoKQewwFgkyKFDe0chhyphenhyphenimRioAXEQG1bYgjk4aOZA/s16000/Image1.png" /></a></div></div>In MySQL Community Downloads, Choose the setup as per your system. I am downloading the mysql-installer-community-8.0.25.0.msi (Windows x86, 32 bit) setup file. Click on the Download button in order to download the MSI Installer.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWmbYh_ZWFjgNhnoaQELmYVxz_MRkXGYu-SlU6tj_vCE5ojUU9IJvcdk4mRKVjBY7bXjaMW7dVYlIeMv8Gs6_AJVZyexoVDzWy7qUjlVgbplWXgCsfVH9l5YO8kNQk_faCcfwouFJrI7k/s550/Image20.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="321" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWmbYh_ZWFjgNhnoaQELmYVxz_MRkXGYu-SlU6tj_vCE5ojUU9IJvcdk4mRKVjBY7bXjaMW7dVYlIeMv8Gs6_AJVZyexoVDzWy7qUjlVgbplWXgCsfVH9l5YO8kNQk_faCcfwouFJrI7k/s16000/Image20.png" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><br /></div></div>MySQL msi installer will be downloaded in few minutes.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVD4PjYUPj-RW0Ge6-IAQC8N-jVl-Oml9EvQP0h5xtf9RfxDNrBIchLqUu98TFAsCNistPNfWG9WWPmG3OWJTgViZht5M4rv7301ych9b4WHR8ozqosKyOO1TNHsDIjl4Vei1UXbeEtmU/s385/Image2.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="216" data-original-width="385" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVD4PjYUPj-RW0Ge6-IAQC8N-jVl-Oml9EvQP0h5xtf9RfxDNrBIchLqUu98TFAsCNistPNfWG9WWPmG3OWJTgViZht5M4rv7301ych9b4WHR8ozqosKyOO1TNHsDIjl4Vei1UXbeEtmU/s16000/Image2.png" /></a></div></div>Double click on the downloaded installer file in order to start the installation.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwQHxmU0z3soUHLIzHzEhjl9uShsOM6T9an4c3queozDXmXeGDZV1239QvgxHcgxT73J8q4bCb9FC8TOgptmcWurVQ9_Zo6u86EdFxkPGol2IDhnrUK_EX9H0m1czKPaKXgDHAOhD9aFc/s394/Image3.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="149" data-original-width="394" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwQHxmU0z3soUHLIzHzEhjl9uShsOM6T9an4c3queozDXmXeGDZV1239QvgxHcgxT73J8q4bCb9FC8TOgptmcWurVQ9_Zo6u86EdFxkPGol2IDhnrUK_EX9H0m1czKPaKXgDHAOhD9aFc/s16000/Image3.png" /></a></div></div>In the next MySQL Installer screen, click on Add button. If some product already installed in your system, those will be shown in the grid.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhGezswR_GrouvIF6mnSAgC2Kt-SGAF-OupLlq848C8Q7zzxlqlrSs1l-DrGzocNLnky2VA1JIhqRCylLQqbRYJd6-qkz6n0dD-vfTE6GXnYBP1tVspTFhcVvxncQumFqJfQwov-SSf-Q/s550/Image4.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhGezswR_GrouvIF6mnSAgC2Kt-SGAF-OupLlq848C8Q7zzxlqlrSs1l-DrGzocNLnky2VA1JIhqRCylLQqbRYJd6-qkz6n0dD-vfTE6GXnYBP1tVspTFhcVvxncQumFqJfQwov-SSf-Q/s16000/Image4.png" /></a></div></div>Select the products you want to install in your system.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuEDxuHkoPVnKgzLoVadZEG1SpbjdMkbSpVHSiBVOF3vV3NJPANWdMZipAAFANS8rjEdolhflSWXiJTTK-lkjk49Npzfbe50o469zLezuJgk8H7hUL7Hk1f_4UL6FQN-gS6J7cFE7lVBQ/s550/Image5.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuEDxuHkoPVnKgzLoVadZEG1SpbjdMkbSpVHSiBVOF3vV3NJPANWdMZipAAFANS8rjEdolhflSWXiJTTK-lkjk49Npzfbe50o469zLezuJgk8H7hUL7Hk1f_4UL6FQN-gS6J7cFE7lVBQ/s16000/Image5.png" /></a></div></div>As you can see in the below image, I have selected MySQL Server, MySQL Workbench, Connector for .Net, Documentation, and examples. Click on Next to continue. You can select products as per your need.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixXygZsuaU0sg8Pf_VwtBWd3MmWaYVkwlw0J8WesU-GlMuxouR6f78QSzV5Nmo5DRdgBJbbWWNHrH13GWiJFfyYunXTV2zyjOhSpdboTN_KNUGles6DRb9qwqJ2fdK2HkjAcXIxY2GzbE/s550/Image6.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixXygZsuaU0sg8Pf_VwtBWd3MmWaYVkwlw0J8WesU-GlMuxouR6f78QSzV5Nmo5DRdgBJbbWWNHrH13GWiJFfyYunXTV2zyjOhSpdboTN_KNUGles6DRb9qwqJ2fdK2HkjAcXIxY2GzbE/s16000/Image6.png" /></a></div></div>Click on Execute button in order to install the selected products.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVhkp27zp3TtresF3K9yxusClTX9U-dmcGxmpPVZ6f7NO2u6VToArY3QzTp9pI94WYIYBM_OrBS_QAvdEb-9Jabl1W0wSfu-5O65KQNrASZxPuNfHWDXq9kq2GEsVF2J3WnjPx4wm2u_o/s550/Image7.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVhkp27zp3TtresF3K9yxusClTX9U-dmcGxmpPVZ6f7NO2u6VToArY3QzTp9pI94WYIYBM_OrBS_QAvdEb-9Jabl1W0wSfu-5O65KQNrASZxPuNfHWDXq9kq2GEsVF2J3WnjPx4wm2u_o/s16000/Image7.png" /></a></div></div>Once installation completed, click on Next in order to configure the installed products. In my case, I have to configure the MySQL Server & Sample and Examples.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyOcF-bxBDE-10H6R4qsTx9ir_45pVMLo-IJMkJAKajcpzPCsbL9WsI3vSIYhd8o7ap23UK0azHqpqb6Vye9s9kqjkBwUxZIxvT5fvI3KAciUXggGFuy3Uw5Ct9zg_pNPh00ct9_7S-Yo/s550/Image8.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyOcF-bxBDE-10H6R4qsTx9ir_45pVMLo-IJMkJAKajcpzPCsbL9WsI3vSIYhd8o7ap23UK0azHqpqb6Vye9s9kqjkBwUxZIxvT5fvI3KAciUXggGFuy3Uw5Ct9zg_pNPh00ct9_7S-Yo/s16000/Image8.png" /></a></div></div>In the next step, select the config type and other connectivity details. I selected config type as Development Computer as I need MySQL for development purpose. Selected TCP/IP with Port is 3306 and X Protocol Port value is 33060 (Keeping the default values) then Click on next button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtTe7iP9ZJMXk9aFJlt0VpbnnDe39XCmB2AhzyRX0_s-BVUp1poBPxXQRShsgGC90YHH6NG8UjXH5XtN-UGuLhGPqkzMjTqRESaPNCv745tyUXGgUlKFGres6E0tzHah8gVuoN61wzD3o/s550/Image9.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtTe7iP9ZJMXk9aFJlt0VpbnnDe39XCmB2AhzyRX0_s-BVUp1poBPxXQRShsgGC90YHH6NG8UjXH5XtN-UGuLhGPqkzMjTqRESaPNCv745tyUXGgUlKFGres6E0tzHah8gVuoN61wzD3o/s16000/Image9.png" /></a></div></div>Select the Authentication method. I have selected the use of Strong Password Encryption for Authentication which is recommended.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTbl4lkpeD34E1cwUyJf2i9Suo3l-UoiLgfOWlfEnaB00U1IUEA-UjqqddwqFo6DjT1-xSQ-D14fWuHJOY9xL_PdQdvy3DGe3YnwfFpKRJuWZxgcg-gwBltuJhr26G4BlmLzQsCp6vdw8/s550/Image10.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTbl4lkpeD34E1cwUyJf2i9Suo3l-UoiLgfOWlfEnaB00U1IUEA-UjqqddwqFo6DjT1-xSQ-D14fWuHJOY9xL_PdQdvy3DGe3YnwfFpKRJuWZxgcg-gwBltuJhr26G4BlmLzQsCp6vdw8/s16000/Image10.png" /></a></div></div>Enter the password for the root account and Click on the Next button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZHqEuq6vYu0efnApmOviyAOAYJ63DF1k2UilGm_TXDym7eyQ2Ho5JcHOlkDrQn2j37j4kPUaPXCDR7WrZzC5z00D9fO2ow6wFfgI-zvEMjvi318ipgLP-1TT8tgjibXQWxe3_Kk68t1w/s550/Image11.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZHqEuq6vYu0efnApmOviyAOAYJ63DF1k2UilGm_TXDym7eyQ2Ho5JcHOlkDrQn2j37j4kPUaPXCDR7WrZzC5z00D9fO2ow6wFfgI-zvEMjvi318ipgLP-1TT8tgjibXQWxe3_Kk68t1w/s16000/Image11.png" /></a></div></div>The next screen is about registering MySQL as Windows Service. Keep the selected values (default) as shown in the below image and then click on the Next Button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4cT7_HA8_bpdNda2y0N43rK65GGQ2TcmxXrR0_NsE-DTNxHBFa5AvIjOwl0_vWHZlU0LVYLLndrnSOViSWqoD_q17lVOl9RqSqgJS4s6D8oxND5pRm8HVfbKsxoVO_e7tDLkK3ck-IJw/s550/Image12.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4cT7_HA8_bpdNda2y0N43rK65GGQ2TcmxXrR0_NsE-DTNxHBFa5AvIjOwl0_vWHZlU0LVYLLndrnSOViSWqoD_q17lVOl9RqSqgJS4s6D8oxND5pRm8HVfbKsxoVO_e7tDLkK3ck-IJw/s16000/Image12.png" /></a></div></div>Click on the Execute button in order to apply the configuration selected in above steps.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8oqi2BXNGcGG9Tl-RN8zULCuiq-Wt3yGjDGpzoE2esDwVfS5w3E9eIHHTGzmFKaoV4nQSb2qu_MHddyl7h-9cMzJKtC0cWkGUNOpzSbQQNrRCmXEx6bB5yrd0Z3fT-0oLruYXfnqeNU8/s550/Image13.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8oqi2BXNGcGG9Tl-RN8zULCuiq-Wt3yGjDGpzoE2esDwVfS5w3E9eIHHTGzmFKaoV4nQSb2qu_MHddyl7h-9cMzJKtC0cWkGUNOpzSbQQNrRCmXEx6bB5yrd0Z3fT-0oLruYXfnqeNU8/s16000/Image13.png" /></a></div></div>Once the configuration operation completed successfully, Click on the Finish button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxL13Pm7HTRmhOlHPhHcw1TetB7Wn07XZLfdwDFKB9zznIb2YVK8LR3ugVXYREIJ47an14wpj3s39M0Fq8pPWhg2jG0RaPnXGPTz_cDO8KklfnUGd_JkFrgBRw1UFOwYyLMbu_IMnbgcc/s550/Image14.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxL13Pm7HTRmhOlHPhHcw1TetB7Wn07XZLfdwDFKB9zznIb2YVK8LR3ugVXYREIJ47an14wpj3s39M0Fq8pPWhg2jG0RaPnXGPTz_cDO8KklfnUGd_JkFrgBRw1UFOwYyLMbu_IMnbgcc/s16000/Image14.png" /></a></div></div>You can see that the Product Configuration completed. Click on the next button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3Wzc5nOF-Anc4L0moHxCFq1Jc1Dn-NVyiUw__Dhp3_xIBHmRYLcbBxdJwn2n9x3xzE4-qiUOPeJKxen-o5Ujwy_YpGH6ke0Ji_cgTNrsRlQwXBAPAv5BvGU_Qz-iIrYlbpQAZ19QBMl4/s550/Image15.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3Wzc5nOF-Anc4L0moHxCFq1Jc1Dn-NVyiUw__Dhp3_xIBHmRYLcbBxdJwn2n9x3xzE4-qiUOPeJKxen-o5Ujwy_YpGH6ke0Ji_cgTNrsRlQwXBAPAv5BvGU_Qz-iIrYlbpQAZ19QBMl4/s16000/Image15.png" /></a></div></div>Select Start MySQL Workbench after setup and Start MySQL Shell after the setup in case you want to run just after Workbench and MySQL shell just after the installation. Click on the finish button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0J9ixx53dsYGWnPuUNulEZcYh6MZ0mSDqf1SevvMng0bJhGO4eoRV0VJd4PjkrF94EEA1Q6USjADschIsIcmDgrwgZxfd713M0JcyaBOFE_Iz0xEEDFiqLquDaNWkA5hTJZ1ZDxT2abo/s550/Image16.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="415" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0J9ixx53dsYGWnPuUNulEZcYh6MZ0mSDqf1SevvMng0bJhGO4eoRV0VJd4PjkrF94EEA1Q6USjADschIsIcmDgrwgZxfd713M0JcyaBOFE_Iz0xEEDFiqLquDaNWkA5hTJZ1ZDxT2abo/s16000/Image16.png" /></a></div></div>As I have opted for the MySQL Workbench, it will open just after the completion of the setup. You can also run it from the start menu by searching MySQL Workbench. Click on the Local Instance (You can set up the new connection with the server details as well).
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhuKKy3xJNJ5bcWcO96rBpDSx77kyjBofdMkjcceZVRwdO860Vjthal-jsAoboLHUbBJ44JO58TznGAjBrozrgM3BfCS_ikQFjaBll3_xcNwMt1w3MkZoUZoPXXp1jUyKiN_DrSNH23nk/s550/Image17.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="289" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhuKKy3xJNJ5bcWcO96rBpDSx77kyjBofdMkjcceZVRwdO860Vjthal-jsAoboLHUbBJ44JO58TznGAjBrozrgM3BfCS_ikQFjaBll3_xcNwMt1w3MkZoUZoPXXp1jUyKiN_DrSNH23nk/s16000/Image17.png" /></a></div></div>Provide the root password configured during the installation.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkq8v-FQFzSnMWx0YnE9L0pnjo71xlIkO40emPO7smCEvPECO_9tq7rGLm_jjOMYbcOG5D3_ItdqZo1gBMhMqvJs1mCHzFhvxJmijdiYVPxhm1wJ9Wwtt2aA_XMH1q6CYN1PemOgC6G-c/s550/Image18.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="260" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkq8v-FQFzSnMWx0YnE9L0pnjo71xlIkO40emPO7smCEvPECO_9tq7rGLm_jjOMYbcOG5D3_ItdqZo1gBMhMqvJs1mCHzFhvxJmijdiYVPxhm1wJ9Wwtt2aA_XMH1q6CYN1PemOgC6G-c/s16000/Image18.png" /></a></div></div>You can see the Sample & Examples are configured in the Schema. You can create your own new Database or Import the existing one.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVEqzynKYTwXuvVVRGZ-a2rCctrLm9CGYkex9ovIlBcsCkI-iF5r_0RsF0cXgtJ-nhs6GHG_hp8YL3XEWR1wZ_3LTbrT9pXHIsy8BkC1bWAY1m-Uo62RHps0QmbrRrWEsZXC7K3Vh5Uqc/s516/Image19.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="341" data-original-width="516" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVEqzynKYTwXuvVVRGZ-a2rCctrLm9CGYkex9ovIlBcsCkI-iF5r_0RsF0cXgtJ-nhs6GHG_hp8YL3XEWR1wZ_3LTbrT9pXHIsy8BkC1bWAY1m-Uo62RHps0QmbrRrWEsZXC7K3Vh5Uqc/s16000/Image19.png" /></a></div></div><div>I hope this article will help you in setting up MySQL in the windows operating system.</div><div>Thanks.</div><div><br /></div>
<div class="clsImportant"><b>Also read</b>: <a href="https://www.ittutorialswithexample.com/2021/04/how-to-install-visual-studio-2019.html" target="_blank">How to install Visual Studio 2019</a> </div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-15613943565451027592021-04-26T11:14:00.002-07:002021-04-26T11:49:56.569-07:00Cookie Authentication in ASP.NET Core<p>In this article, we will learn How to implement Cookie Authentication in ASP.NET Core without using Identity. I will try to cover every step so that beginners can easily understand.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBnKcZSYVhKuuyM3Mx9tMxcUuhYaCKiEIrrlxjudk09l-oNNQiDw10VGB_OOy_bbWuoPTB-HX1LuPLoCFsHO0LBshVH-UqUpDJQAYEp4hGEtNPzny5vQZmimq8imqBNIH-ttU9DSFYyQ4/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBnKcZSYVhKuuyM3Mx9tMxcUuhYaCKiEIrrlxjudk09l-oNNQiDw10VGB_OOy_bbWuoPTB-HX1LuPLoCFsHO0LBshVH-UqUpDJQAYEp4hGEtNPzny5vQZmimq8imqBNIH-ttU9DSFYyQ4/s16000/Cover.jpg" /></a></div></div><span><a name='more'></a></span><div>This article is the part of ASP.NET Core learning series. If you are new to ASP.NET Core, then I will recommend you to go through the previous article of this series:</div><div><ul style="text-align: left;"><li><a href="https://www.ittutorialswithexample.com/2021/02/create-first-application-with-asp-dot-net-core.html" target="_blank">Create your first application with ASP.NET Core 3.1</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/project-structure-in-aspnet-core-web-application.html" target="_blank">Project Structure in ASP.NET Core 3.1 Web Application</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/create-aspnet-core-web-application-with-vs-code.html" target="_blank">Create ASP.NET Core Web Application with Visual Studio Code</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/understanding-inprocess-hosting-model-aspnet-core.html" target="_blank">Understanding InProcess Hosting Model in ASP.NET Core</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/understanding-outofprocess-hosting-in-aspnet-core.html" target="_blank">Understanding OutOfProcess Hosting Model in ASP.NET Core</a></li></ul></div><div>Authentication is the process of verifying the identity of the user. In this article, we will authenticate the user by verifying the user’s credentials. I am using Visual Studio 2019 to demonstrate this example.</div><div class="clsImportant"><a href="https://www.ittutorialswithexample.com/2021/04/how-to-install-visual-studio-2019.html" target="_blank">How to install Visual Studio 2019</a></div><div><div><br /></div><div>Let’s implement the Cookie Authentication in ASP.NET Core step by step:</div><div>Open the Visual Studio and click on Create a new Project.</div></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOXol-s54h8TEQYkrFe4y8cOlsAItdH3dfkfGXY7gN1rjlqDCldD3MURm8dWQypQXxgTnppm-vaIzz7p0Gjw2p4-eDz2ja4SqAVhdxr4fwQYlmvguyR099JW5rcT0i-3WTc7rAa-ILVXo/s550/Image1.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOXol-s54h8TEQYkrFe4y8cOlsAItdH3dfkfGXY7gN1rjlqDCldD3MURm8dWQypQXxgTnppm-vaIzz7p0Gjw2p4-eDz2ja4SqAVhdxr4fwQYlmvguyR099JW5rcT0i-3WTc7rAa-ILVXo/s16000/Image1.png" /></a></div></div>Select ASP.NET Core Empty project and click on next.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipMr0vTp8b3pq1tMEsNMKG45LSTuvett7-SeiL-Wm-8z29jipKRzznX7H7pBqVHLPpElWZ_NVhllkNW_VK-9b84W5Bvq9UTTOf6C1ESISnmEYgiYYliqns2RO5dT3uFdi6i481Bohp2fY/s550/Image2.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipMr0vTp8b3pq1tMEsNMKG45LSTuvett7-SeiL-Wm-8z29jipKRzznX7H7pBqVHLPpElWZ_NVhllkNW_VK-9b84W5Bvq9UTTOf6C1ESISnmEYgiYYliqns2RO5dT3uFdi6i481Bohp2fY/s16000/Image2.png" /></a></div></div>Give a name to your Project, select the location for the project creation, and click on Next.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_p4H94yj5h3fth0OdYCSV5T6WrecZq5rdweLzpw_cZPpdod891u1nADf8TG817fxAJ_myMqBSbmFmQUHCX8Jm1G4jWoOBSrsGNmmiKZt_bci75v9TEnfqrygS8dKbXMc1QrqLNFYCPmE/s550/Image3.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_p4H94yj5h3fth0OdYCSV5T6WrecZq5rdweLzpw_cZPpdod891u1nADf8TG817fxAJ_myMqBSbmFmQUHCX8Jm1G4jWoOBSrsGNmmiKZt_bci75v9TEnfqrygS8dKbXMc1QrqLNFYCPmE/s16000/Image3.png" /></a></div></div>Select the Target Framework. I am using .Net Core 3.1 (LTS) and click on create.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_s03YsmHqk7YKq21QUh-OXAOlu6a90CPZQ-le41wKQACKrY6RzCVbf4gm3_Lz-a_TQTNNIzkajSMfya3WD7oyOZK-iRZavv-7hRtRXhBMi9LLozq2GqiqHLampvMBvZ__Ask20Wj5i-k/s550/Image4.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_s03YsmHqk7YKq21QUh-OXAOlu6a90CPZQ-le41wKQACKrY6RzCVbf4gm3_Lz-a_TQTNNIzkajSMfya3WD7oyOZK-iRZavv-7hRtRXhBMi9LLozq2GqiqHLampvMBvZ__Ask20Wj5i-k/s16000/Image4.png" /></a></div></div>A similar kind of project as shown in the below image will be created.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVrp5UooTTrEOUMxn5w11DOIz5XB-ZyRc77SEgsQ6cid-vdIcu5XVmArPQ2PP1CMhk_KlCpvEXOEEF3QIZTTb8riLsl9lTDNfWn_pNm8GYrr1u85cW_C9f-DIIcH-z_k5HOZErugWyTpk/s347/Image5.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="232" data-original-width="347" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVrp5UooTTrEOUMxn5w11DOIz5XB-ZyRc77SEgsQ6cid-vdIcu5XVmArPQ2PP1CMhk_KlCpvEXOEEF3QIZTTb8riLsl9lTDNfWn_pNm8GYrr1u85cW_C9f-DIIcH-z_k5HOZErugWyTpk/s16000/Image5.png" /></a></div></div>As we have created an empty project, let's open the Startup.cs file and add the highlighted code. In the ConfigureServices method, I have added the AddControllersWithViews service and added the UseEndpoints middleware in Configure method as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVfYi0OVhry2Y9_tNJO5h-ojagXzhtu6PoBSrmnEFwhEvKuisg1vpgM9cXEIyIafjH7U_bypLNndGjZsR-RBl-IyXSurllwwQZhXOLbd20SGwt7gaA_dZ1pkOBy0evWiRc8lWXEWFmygo/s550/Image6.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="301" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVfYi0OVhry2Y9_tNJO5h-ojagXzhtu6PoBSrmnEFwhEvKuisg1vpgM9cXEIyIafjH7U_bypLNndGjZsR-RBl-IyXSurllwwQZhXOLbd20SGwt7gaA_dZ1pkOBy0evWiRc8lWXEWFmygo/s16000/Image6.png" /></a></div></div>Add a Controllers folder in the project in which we will create all the controllers.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-DJ-D3geT4ZGuV7tiUC9O1oacvuZaUNBUu35JqcHrjKtue7W6U5RZczJtM-A6iw366bu82pWYYIOMsyXvRe740ATu4zmyYkYC6VDqpMZY-fWagbtAqGGGFgMnGZbCVNu88BsTWiFP45k/s316/Image7.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="224" data-original-width="316" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-DJ-D3geT4ZGuV7tiUC9O1oacvuZaUNBUu35JqcHrjKtue7W6U5RZczJtM-A6iw366bu82pWYYIOMsyXvRe740ATu4zmyYkYC6VDqpMZY-fWagbtAqGGGFgMnGZbCVNu88BsTWiFP45k/s0/Image7.png" /></a></div></div>Let’s add a HomeController by right-clicking on the Controller folder. Go to Add and click on Controller. Select the empty controller as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4V2zWG1bFTh6x6arFVx_Xd1dBT2hNUVI9Suzqkvxtj_TeZLD9BBiTROvlMOOKA2-OlDPQa0JzAMEaAZ29WxUKvKlxGpJ7Yj0OTiSitzPy8X7Sk80URtDj164bWOdEuLw4-ijI_nWyOlA/s550/Image8.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="380" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4V2zWG1bFTh6x6arFVx_Xd1dBT2hNUVI9Suzqkvxtj_TeZLD9BBiTROvlMOOKA2-OlDPQa0JzAMEaAZ29WxUKvKlxGpJ7Yj0OTiSitzPy8X7Sk80URtDj164bWOdEuLw4-ijI_nWyOlA/s16000/Image8.png" /></a></div></div><div class="separator" style="clear: both; text-align: center;"><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGghxsZgDaleMKGs_Cl141xqMPY_qSFBabt1M8C2gxv0udC_2frgieTu7XBiUFupBkyLihztQXDpt0kDfh1Opq5L1Gm6W3iNzTKY-AsaGrXy8ynQWkrF7IMo23PWDdUDWF-hdhKz-ZH54/s550/Image9.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="336" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGghxsZgDaleMKGs_Cl141xqMPY_qSFBabt1M8C2gxv0udC_2frgieTu7XBiUFupBkyLihztQXDpt0kDfh1Opq5L1Gm6W3iNzTKY-AsaGrXy8ynQWkrF7IMo23PWDdUDWF-hdhKz-ZH54/s16000/Image9.png" /></a></div></div>Right-click on the project and click on manage NuGet Packages. Browse Bootstrap (only required for the UI Style) and click on Install.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd_hJwVvUoptXAv0qNw6hufyzuBEg1WYm_5GrjkOzvh2aKZuUH7Gtcls0SlkQSt4HanjviRP2W1o8OcHjlJNJ2c7cOTKA0C3sN4xb2YErgEzUJ4GMwnhXBffDrHiK-FpaynlUMYVJOx-U/s550/Image10.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="205" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd_hJwVvUoptXAv0qNw6hufyzuBEg1WYm_5GrjkOzvh2aKZuUH7Gtcls0SlkQSt4HanjviRP2W1o8OcHjlJNJ2c7cOTKA0C3sN4xb2YErgEzUJ4GMwnhXBffDrHiK-FpaynlUMYVJOx-U/s16000/Image10.png" /></a></div></div>In order to serve the static files like js, css, images, etc., we need to UseStaticFiles middleware in Configure method.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrevpjzeu8DZNuLcsAjcNx7wkxE6X0NJwBroFJJm2X1pgXQs11TlrvIZZhPHjRKguXlMYNNh8mbrvTEd5G9fSa3sirrZvPAR53q8WLkLV9rszIoxR0yjF1l5xdGrRHELHFNqoy0xBFvz4/s529/Image11.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="307" data-original-width="529" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrevpjzeu8DZNuLcsAjcNx7wkxE6X0NJwBroFJJm2X1pgXQs11TlrvIZZhPHjRKguXlMYNNh8mbrvTEd5G9fSa3sirrZvPAR53q8WLkLV9rszIoxR0yjF1l5xdGrRHELHFNqoy0xBFvz4/s16000/Image11.png" /></a></div></div>I have added to Action methods in HomeController i.e., Index and ConfidentialData.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVJKPjZRz6ITvf7C_bm-IGk0dd55t9K7Tk1Elt_leRwo0GgNJigwqNpI8ZkKNhqTrQS8rgojz_G-sUXLWbEkFg6sUxdWY0xBOJll1CORZbH0F8y8fMst9HZaB75QCOXquH56MtSlTzDDg/s343/Image12.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="234" data-original-width="343" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVJKPjZRz6ITvf7C_bm-IGk0dd55t9K7Tk1Elt_leRwo0GgNJigwqNpI8ZkKNhqTrQS8rgojz_G-sUXLWbEkFg6sUxdWY0xBOJll1CORZbH0F8y8fMst9HZaB75QCOXquH56MtSlTzDDg/s16000/Image12.png" /></a></div></div>So, on clicking on the Home and confidential Data link in the navigation below screen will be shown.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7Bq0ocBDZtdzmOcA3H-EiLrrO8lQGimm_pt8UONRdxkrtUQjopt9EyAtOLD14nf_75Oy3RF6LgT3ix8RI59SULoXFSyeD8vELVNvV0BcSMxiE2B_bwHCchTsqsTY2E6ANAXvx3HwWShM/s550/Image13.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="208" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7Bq0ocBDZtdzmOcA3H-EiLrrO8lQGimm_pt8UONRdxkrtUQjopt9EyAtOLD14nf_75Oy3RF6LgT3ix8RI59SULoXFSyeD8vELVNvV0BcSMxiE2B_bwHCchTsqsTY2E6ANAXvx3HwWShM/s16000/Image13.png" /></a></div></div><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoAk1Fize9w3PXfXQ5Jndh3MjbvryoX9gehiJT9GFa8a5Q8wvbazRx417j0y1FTRkx9QBTda5UPb4L7a0aD9OCbr0OcW_MFryy-H25jLgO1gMAlNX3gw2nmMGDemMs3nO_qIQSWL4a_Sk/s550/Image14.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="186" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoAk1Fize9w3PXfXQ5Jndh3MjbvryoX9gehiJT9GFa8a5Q8wvbazRx417j0y1FTRkx9QBTda5UPb4L7a0aD9OCbr0OcW_MFryy-H25jLgO1gMAlNX3gw2nmMGDemMs3nO_qIQSWL4a_Sk/s16000/Image14.png" /></a></div></div>Another controller i.e., AccountController with a Login page as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKuNdDfQgbztgJ_jiFYHrALX8ZHSb3iMuccLEZBVspxF2ZywQCF2IFcT_QJ2oDxXadIpWGqf8_47nIlgzCXqWh0P1zuqtl8bKOE7DYNLh9Qx1YXdoYcYd8QTcuCGpv0hxzJctP6Gir9bk/s550/Image15.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="258" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKuNdDfQgbztgJ_jiFYHrALX8ZHSb3iMuccLEZBVspxF2ZywQCF2IFcT_QJ2oDxXadIpWGqf8_47nIlgzCXqWh0P1zuqtl8bKOE7DYNLh9Qx1YXdoYcYd8QTcuCGpv0hxzJctP6Gir9bk/s16000/Image15.png" /></a></div></div>In ConfigureServices method of Startup.cs, create an Authentication Middleware Services with the AddAuthentication and AddCookie method. Authentication scheme passed to AddAuthentication sets to the default authentication scheme for the app. CookieAuthenticationDefaults.AuthenticationScheme provides “Cookies” for the scheme. In AddCookie extension method, set the LoginPath property of CookieAuthenticationOptions to “<b><span style="color: #cc0000;">/account/login</span></b>”. CookieAuthenticationOptions class is used to configure the authentication provider options.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG0SHR5-IJFQKNJTHiKLo7H55d50qeg4xRh1tBE4Cm02TdHjXX-SVKkzchR9Atp3A-Jbfi_uCC8QNt-rCDwkMlcN9i7v2j-yWhE5Jq0zlxeczwEoJs4KTj_JTZxbMc8LDIEB5JR827mMo/s550/Image16.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="102" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG0SHR5-IJFQKNJTHiKLo7H55d50qeg4xRh1tBE4Cm02TdHjXX-SVKkzchR9Atp3A-Jbfi_uCC8QNt-rCDwkMlcN9i7v2j-yWhE5Jq0zlxeczwEoJs4KTj_JTZxbMc8LDIEB5JR827mMo/s16000/Image16.png" /></a></div></div>In Configure method of Startup.cs, call UseAuthentication and UseAuthorization method before calling the endpoints.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBsiuO0Neink-_U1MwGyPRspt-8hE16Vhyeap-MZ_EQlWAClEV3xvUdmXx3IEHwQKLvADNqKStSKleF4gBv6no6AzMDMruxARhvnEizSToUSGjx4P1-EXC_52EMwaPmuNO0ALvwL4YL6A/s515/Image17.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="354" data-original-width="515" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBsiuO0Neink-_U1MwGyPRspt-8hE16Vhyeap-MZ_EQlWAClEV3xvUdmXx3IEHwQKLvADNqKStSKleF4gBv6no6AzMDMruxARhvnEizSToUSGjx4P1-EXC_52EMwaPmuNO0ALvwL4YL6A/s16000/Image17.png" /></a></div></div>Now let’s add the Authorize attribute, on ConfidentialData action method. Now only authenticate methods can access that ActionMethod.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtLKOvUCfOB1JbRwH62BV8r09bWel7n6xvPC0vUcCuXAsDX5ql92x2SD5KsbsRqFAcLCz7kQyLWMwxXa__lmQlRknK7ZBVHiN2QelpG5lNnm2pePM7T4XBe2gUy_C7-kl8Ev95IyeQPPs/s316/Image18.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="221" data-original-width="316" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtLKOvUCfOB1JbRwH62BV8r09bWel7n6xvPC0vUcCuXAsDX5ql92x2SD5KsbsRqFAcLCz7kQyLWMwxXa__lmQlRknK7ZBVHiN2QelpG5lNnm2pePM7T4XBe2gUy_C7-kl8Ev95IyeQPPs/s16000/Image18.png" /></a></div></div>Let’s click on Confidential Data link in the navbar. It will redirect to “<span style="color: #cc0000;">Account/Login</span>” page as the user is not authenticated yet.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLBdpA0iH6mJK8qu8xuls_sASvy0KFC-jjsQsdS7ZVogHixMWiKtzV2YpUYKV1wD0SzqwwXFpv_a9axVXSUd3y9IAfd1AcI5aPsxX7b146PzyRTbKb0miS9xIO3-djh3v5h0CQGUpR4Gg/s550/Image19.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="403" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLBdpA0iH6mJK8qu8xuls_sASvy0KFC-jjsQsdS7ZVogHixMWiKtzV2YpUYKV1wD0SzqwwXFpv_a9axVXSUd3y9IAfd1AcI5aPsxX7b146PzyRTbKb0miS9xIO3-djh3v5h0CQGUpR4Gg/s16000/Image19.png" /></a></div></div>In AccountController, the Login action method receives the returnurl as a parameter to which the user needs to be redirected after the successful authentication. Below is the <b>Login.cshtml</b> code used in the example.<div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="background: yellow; font-family: Consolas; font-size: 9.5pt;">@model</span><span style="font-family: Consolas; font-size: 9.5pt;">
CookieAuthentication.Models.LoginModel<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="background: yellow; font-family: Consolas; font-size: 9.5pt;">@{</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
ViewData[</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Title"</span><span style="font-family: Consolas; font-size: 9.5pt;">] = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Login"</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
Layout = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"~/Views/Shared/_Layout.cshtml"</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="background: yellow; font-family: Consolas; font-size: 9.5pt;">}</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">h2</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;">Login</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">h2</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">hr</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">/></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="row"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="col-md-4"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">form</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><b><span style="color: purple; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">asp-action</span></b><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="Login"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><b><span style="color: purple; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">asp-validation-summary</span></b><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="</span><span style="font-family: Consolas; font-size: 9.5pt;">ModelOnly</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="text-danger"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="background: yellow; mso-highlight: yellow;">@</span></span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (!</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;">.IsNullOrEmpty(ViewBag.Message))<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">span</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="text-danger"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="background: yellow; mso-highlight: yellow;">@</span>ViewBag.Message<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">span</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="background: yellow; mso-highlight: yellow;">@</span>Html.HiddenFor(x => x.ReturnUrl)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="form-group"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">label</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><b><span style="color: purple; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">asp-for</span></b><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="</span><span style="font-family: Consolas; font-size: 9.5pt;">UserName</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="control-label"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">label</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">input</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><b><span style="color: purple; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">asp-for</span></b><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="</span><span style="font-family: Consolas; font-size: 9.5pt;">UserName</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="form-control"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">/></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">span</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><b><span style="color: purple; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">asp-validation-for</span></b><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="</span><span style="font-family: Consolas; font-size: 9.5pt;">UserName</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="text-danger"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">span</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="form-group"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">label</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><b><span style="color: purple; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">asp-for</span></b><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="</span><span style="font-family: Consolas; font-size: 9.5pt;">Password</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="control-label"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">label</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">input</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><b><span style="color: purple; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">asp-for</span></b><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="</span><span style="font-family: Consolas; font-size: 9.5pt;">Password</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="form-control"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">/></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">span</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><b><span style="color: purple; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">asp-validation-for</span></b><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="</span><span style="font-family: Consolas; font-size: 9.5pt;">Password</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="text-danger"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">span</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="form-group"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="checkbox"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">label</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">input</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><b><span style="color: purple; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">asp-for</span></b><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="</span><span style="font-family: Consolas; font-size: 9.5pt;">RememberLogin</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">/></span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="background: yellow; mso-highlight: yellow;">@</span>Html.DisplayNameFor(model
=> model.RememberLogin)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">label</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="form-group"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">input</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">type</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="submit"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">value</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="Login"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">="btn
btn-default"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">/></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">form</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">div</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">></span><o:p></o:p></p>
</td>
</tr>
</tbody></table><div>LoginModel.cs file:</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">LoginModel</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> [Required]<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> [Display(Name =</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Username"</span><span style="font-family: Consolas; font-size: 9.5pt;">)]<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> UserName { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> [Required]<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> [DataType(DataType.Password)]<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> Password { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">bool</span><span style="font-family: Consolas; font-size: 9.5pt;">
RememberLogin { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> ReturnUrl { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">}</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div><div>On clicking on the login button, the Login Post action will be triggered. In Post action, we are verifying the username and password (In this example, I am using the hardcoded user details, but in actual you can verify the user details with an ORM like EntityFramework, Dapper, etc. If entered credentials are not valid then an Invalid credential message will be shown to the user. If credentials are correct create a ClaimsIdentity with the required Claims. Call the SignInAsync to sign in the user.</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">AccountController</span><span style="font-family: Consolas; font-size: 9.5pt;"> : Controller<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Sample
Users Data, it can be fetched with the use of any ORM</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> List<UserModel> users = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">null</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">AccountController</span><span style="font-family: Consolas; font-size: 9.5pt;">()<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> users = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> List<UserModel>();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> users.Add(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> UserModel() { UserId = 1,
Username = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Anoop"</span><span style="font-family: Consolas; font-size: 9.5pt;">, Password = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"123"</span><span style="font-family: Consolas; font-size: 9.5pt;">, Role = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Admin"</span><span style="font-family: Consolas; font-size: 9.5pt;"> });<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> users.Add(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> UserModel() { UserId = 2,
Username = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Other"</span><span style="font-family: Consolas; font-size: 9.5pt;">, Password = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"123"</span><span style="font-family: Consolas; font-size: 9.5pt;">, Role = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"User"</span><span style="font-family: Consolas; font-size: 9.5pt;"> });<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> IActionResult Login(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> ReturnUrl = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"/"</span><span style="font-family: Consolas; font-size: 9.5pt;">)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> LoginModel objLoginModel = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> LoginModel();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> objLoginModel.ReturnUrl =
ReturnUrl;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> View(objLoginModel);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> [HttpPost]<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">async</span><span style="font-family: Consolas; font-size: 9.5pt;">
Task<IActionResult> Login(LoginModel objLoginModel)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (ModelState.IsValid)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> user = users.Where(x =>
x.Username == objLoginModel.UserName && x.Password ==
objLoginModel.Password).FirstOrDefault();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (user == </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">null</span><span style="font-family: Consolas; font-size: 9.5pt;">)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Add logic here to display some message to user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> ViewBag.Message = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Invalid Credential"</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> View(objLoginModel);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//A claim is a statement about a subject by an issuer and</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//represent attributes of the subject that are useful in the
context of authentication and authorization operations.</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> claims = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> List<Claim>() {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;">
Claim(ClaimTypes.NameIdentifier,Convert.ToString(user.UserId)),<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;">
Claim(ClaimTypes.Name,user.Username),<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> Claim(ClaimTypes.Role,user.Role),<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> Claim(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"FavoriteDrink"</span><span style="font-family: Consolas; font-size: 9.5pt;">,</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Tea"</span><span style="font-family: Consolas; font-size: 9.5pt;">)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> };<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Initialize a new instance of the ClaimsIdentity with the
claims and authentication scheme</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> identity = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> ClaimsIdentity(claims,
CookieAuthenticationDefaults.AuthenticationScheme);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Initialize a new instance of the ClaimsPrincipal with
ClaimsIdentity</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> principal = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> ClaimsPrincipal(identity);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//SignInAsync is a Extension method for Sign in a principal for
the specified scheme.</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">await</span><span style="font-family: Consolas; font-size: 9.5pt;">
HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> principal, </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> AuthenticationProperties() {
IsPersistent = objLoginModel.RememberLogin });<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">return</span><span style="font-family: Consolas; font-size: 9.5pt;">
LocalRedirect(objLoginModel.ReturnUrl);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> View(objLoginModel);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">async</span><span style="font-family: Consolas; font-size: 9.5pt;">
Task<IActionResult> LogOut() {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//SignOutAsync
is Extension method for SignOut</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">await</span><span style="font-family: Consolas; font-size: 9.5pt;">
HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Redirect
to home page</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> LocalRedirect(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"/"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">}</span><o:p></o:p></p>
</td>
</tr>
</tbody></table><div>Once the user is successfully logged in to the application, a cookie will be generated as shown in the below image. This encrypted cookie will be sent to the server in each request and validated on the server with its key.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg16iJqhyphenhyphenYlEFUdDEP7gvWnImCOoHGpZ8SNDvgibWaIJWCTNOMsP5siNjo28thnpUOim-vPMIVBBJaFOdyOzTyQdgLHao8Yfvd1h4Vxp575c48cELDtOsSHQ0DUBGJZnZMB1jW4gMBSfN8/s550/Image20.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="201" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg16iJqhyphenhyphenYlEFUdDEP7gvWnImCOoHGpZ8SNDvgibWaIJWCTNOMsP5siNjo28thnpUOim-vPMIVBBJaFOdyOzTyQdgLHao8Yfvd1h4Vxp575c48cELDtOsSHQ0DUBGJZnZMB1jW4gMBSfN8/s16000/Image20.png" /></a></div></div>In order to show the Claims information on Confidential Data view, code, as shown in the below, is used. In the below code, we are checking that the user must be Authenticated before looping through each Claims.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiROWt4DJtmAjrn0_I-pMmM70NcPdU356s1lcXzOYunQB7GZZzO4Jv5DXOaKMtKiRnAwcI-2Qr1-mQEotn3HiEVvLP09hfNT8rzhfLVslkAEw1SXebzWyFAi5iFttE8P4i_8rJbir9Lhxg/s440/Image21.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="249" data-original-width="440" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiROWt4DJtmAjrn0_I-pMmM70NcPdU356s1lcXzOYunQB7GZZzO4Jv5DXOaKMtKiRnAwcI-2Qr1-mQEotn3HiEVvLP09hfNT8rzhfLVslkAEw1SXebzWyFAi5iFttE8P4i_8rJbir9Lhxg/s16000/Image21.png" /></a></div></div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV2Y_AlSVz0UNUMGmO_FNZrKzf-7sHuBepFhZiX9XRJDsPppZZnyVZ_V2h62wuJY1Fm4a9AZSf4BJsOrfjDeYr3kWBWoQxBbU5XlYEcvZvxAvaLqxLFTTIu3DiUKIeq93zBmR-tBU_GlA/s550/Image22.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="229" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgV2Y_AlSVz0UNUMGmO_FNZrKzf-7sHuBepFhZiX9XRJDsPppZZnyVZ_V2h62wuJY1Fm4a9AZSf4BJsOrfjDeYr3kWBWoQxBbU5XlYEcvZvxAvaLqxLFTTIu3DiUKIeq93zBmR-tBU_GlA/s16000/Image22.png" /></a></div></div>Logout link is shown to the user who is already signed in. On Clicking on the Logout link, we are calling the SignOutAsync method which signs out the user and deletes their cookie.<br /><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">async</span><span style="font-family: Consolas; font-size: 9.5pt;">
Task<IActionResult> LogOut() {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//SignOutAsync
is Extension method for SignOut</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">await</span><span style="font-family: Consolas; font-size: 9.5pt;">
HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Redirect
to home page</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> LocalRedirect(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"/"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">}</span><o:p></o:p></p>
</td>
</tr>
</tbody></table><div><b>Final Preview</b>:</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZjI2NqOjU5opIHxMUhwAgI-o2X5sPlCxUZ3iZFfD1ai-IREdhQykq3XZInfM0xgYBD-YoPbTfE-N4nLS1bSKJPlq1atAVmNYV1jzl0bfcds7_JvKruoOhgv3YRRvHe2Ve7g0spbHr7J8/s550/Image23.gif" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="303" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZjI2NqOjU5opIHxMUhwAgI-o2X5sPlCxUZ3iZFfD1ai-IREdhQykq3XZInfM0xgYBD-YoPbTfE-N4nLS1bSKJPlq1atAVmNYV1jzl0bfcds7_JvKruoOhgv3YRRvHe2Ve7g0spbHr7J8/s16000/Image23.gif" /></a></div></div><p class="MsoNormal"><span lang="EN-US">I hope this
article helped you in implementing Cookie Authentication in ASP.</span></p><div><div><div><div><div><div class="separator" style="clear: both; text-align: left;">Thanks,</div></div></div></div></div></div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s234/cs-wh-234x16.gif" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://drive.google.com/file/d/1CIRVQ64dymBB-102jWWLv3QcgAN9iugD/view?usp=sharing" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="60" data-original-width="303" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1Sve_ZYuFyy4mLzqQ_WoGvrhlV0VqcO_hf4st6mIEYnOWpNHjvw-zCtEnoUY8XQ-HwCIwdxawDxOI4cSI6ty-J7iA20a1yK_Fnj9PwqY4r0smL5GXA_vp_k5-FL_LlWS3wbigks-qQqY/s0/Download-Blue.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><b>[Download Source code via Google Drive]</b></div><div class="separator" style="clear: both; text-align: center;"><b><br /></b></div><div class="separator" style="clear: both; text-align: center;"><b>You can also get the code through the GitHub</b></div><div class="separator" style="clear: both; text-align: center;"><a href="https://github.com/AnoopKrSharma/CookieAuthentication" target="_blank">https://github.com/AnoopKrSharma/CookieAuthentication</a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-35786805354177839242021-04-14T08:15:00.001-07:002021-04-14T08:21:15.091-07:00How to install Visual Studio 2019<p>In this article, we will see How to install Visual Studio 2019 in the windows 10 operating system.</p>
<div class="clsImportant"><p><b>Microsoft Visual Studio</b> is an Integrated Development Environment (IDE) which is used to develop computer programs, websites, web applications, web services, mobile applications, etc. It supports around 36 different programming languages with a code editor having IntelliSense (code completion component). One of the most basic and popular editions of Visual Studio is Community Edition. Visual Studio includes a debugger that works both as a source-level debugger and as a machine-level debugger. Debugger allows setting the breakpoints and watches to monitor the value of the variables as the execution progresses.</p></div><br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq-PZNWFYuiYPxSyQDhTziN7XpMSp0lNdytul0zcptLnQkeZDZ5_1DmYa6kb8uO6d4eTyaHUWbNuleT8kN0NUyWyaNaAaABtwVozclvwL4VnCxVTGOFCnP4LAtzIshg0UZZ8nns67_WAk/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq-PZNWFYuiYPxSyQDhTziN7XpMSp0lNdytul0zcptLnQkeZDZ5_1DmYa6kb8uO6d4eTyaHUWbNuleT8kN0NUyWyaNaAaABtwVozclvwL4VnCxVTGOFCnP4LAtzIshg0UZZ8nns67_WAk/s16000/Cover.jpg" /></a></div></div><div>Visit <a href="https://visualstudio.microsoft.com/" target="_blank">https://visualstudio.microsoft.com/</a> in order to download Visual Studio as per your system architecture as well as requirement.</div><div>Choose Visual Studio Edition which you want to install in your machine. I will recommend you to download Community Edition, which is best for Students or Individual Developers.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt2i7WLHMVa4rzmRVfQmOt9U-fzKmR-x_o7IwmP1qp9HpCUKok2abWn3TKiiWY1Yy8d6nCTtRPly8_u2-sJO6waFsd7C_gnbaA4_h73qWOfO49ko36hcUS9t7FpkJFieoGzbbxTDDpZVc/s550/Image1.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="263" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt2i7WLHMVa4rzmRVfQmOt9U-fzKmR-x_o7IwmP1qp9HpCUKok2abWn3TKiiWY1Yy8d6nCTtRPly8_u2-sJO6waFsd7C_gnbaA4_h73qWOfO49ko36hcUS9t7FpkJFieoGzbbxTDDpZVc/s16000/Image1.png" /></a></div></div>On selecting the edition, an executable setup of Visual Studio is downloaded. Click on the .exe file in order to start the installation process. On the first screen, you can see the privacy and license terms, click on continue.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNRw_-5SvZcx-qesegvj9qyZiSCaYvgIGIvLNHtEjdopziXaHBprgTJauf1DFW-WGYlDQ7ZJgmW_ZBrTPTYd9cXLZvLpi2wU-GaHk5jwK1HDxelxbA7SFYG550CW2ChgtZLA9p1zocnO4/s480/Image2.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="280" data-original-width="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNRw_-5SvZcx-qesegvj9qyZiSCaYvgIGIvLNHtEjdopziXaHBprgTJauf1DFW-WGYlDQ7ZJgmW_ZBrTPTYd9cXLZvLpi2wU-GaHk5jwK1HDxelxbA7SFYG550CW2ChgtZLA9p1zocnO4/s16000/Image2.png" /></a></div></div>In the next step, it will download the files required to proceed with the installation.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf8KCht2CL3pauc1dmWq6W6BCErP6AXPTqPauI-cMYbiNam5bwJ8jGDYqS3piLqWWHzJJQrFqwWL9pHHNFr1U82A8UsE6wdpze47sDlGdgXV4c9wAKEwitB_DyehgFXl4gjEBq-QYHyuk/s480/Image3.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="280" data-original-width="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf8KCht2CL3pauc1dmWq6W6BCErP6AXPTqPauI-cMYbiNam5bwJ8jGDYqS3piLqWWHzJJQrFqwWL9pHHNFr1U82A8UsE6wdpze47sDlGdgXV4c9wAKEwitB_DyehgFXl4gjEBq-QYHyuk/s16000/Image3.png" /></a></div></div>Once all files are downloaded, a screen as shown in the below image will appear. Select the workload as per your development requirement. You can also select the Individual components; language packs, etc., and then click on Install. On the right-hand side, it will show the total space required for the installation.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk4rYo0JuIKKJ7IRJgPHVtQm5iF1LBzCBBaVP0oymUKt6Dh4GhZVaixBm9nCG_sSgs0EfyDbgVpfL9PSg4PjSEP62fNEHWuZTsEg9Gf2p9DSniZYWedxaeYVS5PrOG0-6LBGCBx0gwiv0/s550/Image4.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="293" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk4rYo0JuIKKJ7IRJgPHVtQm5iF1LBzCBBaVP0oymUKt6Dh4GhZVaixBm9nCG_sSgs0EfyDbgVpfL9PSg4PjSEP62fNEHWuZTsEg9Gf2p9DSniZYWedxaeYVS5PrOG0-6LBGCBx0gwiv0/s16000/Image4.png" /></a></div></div>Selected workloads, components will start downloading. Select the start after installation checkbox option in case if you want to start the Visual Studio after the installation.<div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhulZyLfyxYflsR9Guxkmec3sKwb8zbJiRWjReZT-bYrGukT8NTasQNGW315CSi0JrLgveG_ZEZjh6gyR1MWSNtsYxt6ic_YUFuUaTTE_-yjlpOhvn0MVSDkrSxFsyZ_9SURAtsdaHHnlU/s550/Image5.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="293" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhulZyLfyxYflsR9Guxkmec3sKwb8zbJiRWjReZT-bYrGukT8NTasQNGW315CSi0JrLgveG_ZEZjh6gyR1MWSNtsYxt6ic_YUFuUaTTE_-yjlpOhvn0MVSDkrSxFsyZ_9SURAtsdaHHnlU/s16000/Image5.png" /></a></div></div>Once installation is done, search for the Visual Studio (in my case it's Visual Studio 2019) in the Start Button. Click on it in order to launch the application.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS7_APhyphenhyphen6Hs8N9Ypo_dvjFg5-_X6BAokEE6rI_y9hXFH7N82IKbyeVIjSFiOPvKbCVd3JZuCvJQhUjsh07qnRZ5HIcXeyIJhAsBjxxoDTFllwjhZQURpAr2zAr-cXm3-FNrdqxRflWXyg/s550/Image6.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="340" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS7_APhyphenhyphen6Hs8N9Ypo_dvjFg5-_X6BAokEE6rI_y9hXFH7N82IKbyeVIjSFiOPvKbCVd3JZuCvJQhUjsh07qnRZ5HIcXeyIJhAsBjxxoDTFllwjhZQURpAr2zAr-cXm3-FNrdqxRflWXyg/s16000/Image6.png" /></a></div></div>You are now ready to develop cool applications. Create a new project or open an existing project or solution.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC2y3A37Jv3v9k_7jt841SRZaSdBuHaJW60p9JcROf6kTJcYtwbqokKvkwr2BV1TUkGQs4ID8wRz8K4n-jEQJ7sfQDZ9PR063mxZNM8uDoyCJ-QXJalCBAnVX_MIdlg_I4eu5aq9yErN4/s550/Image7.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC2y3A37Jv3v9k_7jt841SRZaSdBuHaJW60p9JcROf6kTJcYtwbqokKvkwr2BV1TUkGQs4ID8wRz8K4n-jEQJ7sfQDZ9PR063mxZNM8uDoyCJ-QXJalCBAnVX_MIdlg_I4eu5aq9yErN4/s16000/Image7.png" /></a></div></div><div>I hope this article will help you in installing Visual Studio.</div><div>Thanks.</div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-42506858267008215852021-03-31T11:17:00.001-07:002021-03-31T11:18:54.588-07:00Understanding OutOfProcess Hosting Model in ASP.NET Core<p>In this article, we will learn OutOfProcess Hosting Model in ASP.NET Core. If you are new to ASP.NET Core, then I will recommend you to go through the below articles of this series:</p><p></p><ul style="text-align: left;"><li><a href="https://www.ittutorialswithexample.com/2021/02/create-first-application-with-asp-dot-net-core.html" target="_blank">Create your first application with ASP.NET Core 3.1</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/project-structure-in-aspnet-core-web-application.html" target="_blank">Project Structure in ASP.NET Core 3.1 Web Application</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/create-aspnet-core-web-application-with-vs-code.html" target="_blank">Create ASP.NET Core Web Application with Visual Studio Code</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/understanding-inprocess-hosting-model-aspnet-core.html" target="_blank">Understanding InProcess Hosting Model in ASP.NET Core</a></li></ul>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUP8wMc9iqix6mrf57gG44hlnRzUHmPQchyphenhyphenjdUyXYUxg2bbeZw0nuVuA1Tx-Wf2vdnwnainYjIHR5mmTAs2Pno6r587Zu67Liw0gCirgKQK2tjZYD9VK6L2UIkl4KRknOahtCfu-VTZs8/s550/Cover.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUP8wMc9iqix6mrf57gG44hlnRzUHmPQchyphenhyphenjdUyXYUxg2bbeZw0nuVuA1Tx-Wf2vdnwnainYjIHR5mmTAs2Pno6r587Zu67Liw0gCirgKQK2tjZYD9VK6L2UIkl4KRknOahtCfu-VTZs8/s16000/Cover.png" /></a></div></div><div>In the previous article, we learned, How to configure InProcess hosting model in ASP.NET Core. We configured the <b>AspNetCoreHostingModel </b>value as InProcess in the .csproj file and saw that the application is hosted through IISExpress / wpw3.exe worker process.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFBCgcg1ejLkN5dh_imZG115RGtYElH8LOBXcah5xGpWnGo9QGjrQfgBAu7vuiKcxUeCV0goV3XuCiB17ta293DAEIjBPcO-06k_GVscAkYiaY2-QiSJd6gDA18JsxJw2_vZYRnj8aK6Q/s550/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="375" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFBCgcg1ejLkN5dh_imZG115RGtYElH8LOBXcah5xGpWnGo9QGjrQfgBAu7vuiKcxUeCV0goV3XuCiB17ta293DAEIjBPcO-06k_GVscAkYiaY2-QiSJd6gDA18JsxJw2_vZYRnj8aK6Q/s16000/Image1.jpg" /></a></div></div>In this article, we will see how to host an application on the <b>OutOfProcess</b> hosting model. In OutOfProcess hosting model, there are two web servers, one is <b>Internal Web Server</b> which is basically a Kestrel server and another is External Web Server which can be either IIS, Ngnix, Apache, etc. dotnet.exe is the process that runs and hosts the application with the Kestrel Web Server.<div><br /></div><div>1. <b>Internal Web Server</b>: In an internal web server, the Kestrel web server is the internet-facing web server as all the HTTP requests are directly processed by it.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiA0pfUyBOWPQ9hLSskT1mGHNrH4E5LndE3U8sTUOuxuTyhG9HbT1_yVCj6C2UF6e_Vau4JdTbpzdBIiHCiVJkaJhD3b6G9xUfTzqwHMcKldBn1XbMDwaKz3qGGbEQSdfofcnhT7Fpi28w/s492/Image9.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="200" data-original-width="492" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiA0pfUyBOWPQ9hLSskT1mGHNrH4E5LndE3U8sTUOuxuTyhG9HbT1_yVCj6C2UF6e_Vau4JdTbpzdBIiHCiVJkaJhD3b6G9xUfTzqwHMcKldBn1XbMDwaKz3qGGbEQSdfofcnhT7Fpi28w/s16000/Image9.jpg" /></a></div></div>2. <b>External Web Server</b>: In External Web Server, Reverse proxy server which can be either IIS, Ngnix, Apache, etc. is used along with Kestrel web Server. A reverse Proxy server provides additional security as well as configurations that are not available in Kestrel Server. It also provides load balancing functionality.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg334wCSTwOgp3IV8yWKr416I4wqTOwYHoiyLpsxHB1z4n_nCf-rP-moqqW62IXSsT-YxhYMbW9Gpu16O_AG1k2N9CZouxWbSRLYceSkcCf1jQBTq9j3rx6Dz_CSWCctmERKEzbWju8bVk/s488/image10.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="200" data-original-width="488" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg334wCSTwOgp3IV8yWKr416I4wqTOwYHoiyLpsxHB1z4n_nCf-rP-moqqW62IXSsT-YxhYMbW9Gpu16O_AG1k2N9CZouxWbSRLYceSkcCf1jQBTq9j3rx6Dz_CSWCctmERKEzbWju8bVk/s16000/image10.jpg" /></a></div></div><div><br /></div>Let’s edit the .csproj file and set AspNetCoreHostingModel value as OutOfProcess (Value of AspNetCoreHostingModel is case-insensitive)<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkOzn55DXQaFvzGNiSIsfaKw-Wcw_HEY1dSCktK3GcWytPliHGCNLZV8rrmBi4UGIcvhac8iwE8u-l05-NOIMzk82KS6oYowXGy6mYKSTOsn0svPocvetEq4QQthu9X9ILGLdV4GBIdbo/s516/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="395" data-original-width="516" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkOzn55DXQaFvzGNiSIsfaKw-Wcw_HEY1dSCktK3GcWytPliHGCNLZV8rrmBi4UGIcvhac8iwE8u-l05-NOIMzk82KS6oYowXGy6mYKSTOsn0svPocvetEq4QQthu9X9ILGLdV4GBIdbo/s16000/Image2.jpg" /></a></div></div><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPeKuIUGbd1D65pcjMuUNALleageyo6cy6-1ph1itWON1FFnLIhWxUsf3lgNcmT8PBDHSLhKlEY_Cs2Lq5PnWwAhITbfpujOvqz1R-3c2bdziLv4iGUmNCqN0ToAWCPIyJiBRrAZza5Uk/s550/Image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="164" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPeKuIUGbd1D65pcjMuUNALleageyo6cy6-1ph1itWON1FFnLIhWxUsf3lgNcmT8PBDHSLhKlEY_Cs2Lq5PnWwAhITbfpujOvqz1R-3c2bdziLv4iGUmNCqN0ToAWCPIyJiBRrAZza5Uk/s16000/Image3.jpg" /></a></div></div>Or we can also change its value by right-clicking on the project and click on the properties as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh02_0SyFZYvzEp96TzSqr5ZIQIea0M-8T2qLq0Oe1WfmXDoIQga_Ww1EqeWKIVCP0biU83tfyiQ1cgDr5eBGGZP3-tqQs56nYzvapt1pBd8f3jrg1NV23nEMykupZUIxp65yAn_NcKVQU/s676/Image4.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="676" data-original-width="518" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh02_0SyFZYvzEp96TzSqr5ZIQIea0M-8T2qLq0Oe1WfmXDoIQga_Ww1EqeWKIVCP0biU83tfyiQ1cgDr5eBGGZP3-tqQs56nYzvapt1pBd8f3jrg1NV23nEMykupZUIxp65yAn_NcKVQU/s16000/Image4.jpg" /></a></div></div>Click on debug menu, and change the value of the Hosting Model from the dropdown to OutOfProcess. We can use any one method in order to change the Hosting Model.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_Sj3A2SIgGwe5gNDsA3hA9C0ybU9xgTja5_bkxDIdAsmCcdTTsLd1copvyKPINty9kVGe1qPNRlez1O5NEg7bvv_B126NqZH0DJGsURNMV1tauKZlyzYtxhaZnqD8CBY0bqXVOMctKGU/s550/Image5.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="302" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_Sj3A2SIgGwe5gNDsA3hA9C0ybU9xgTja5_bkxDIdAsmCcdTTsLd1copvyKPINty9kVGe1qPNRlez1O5NEg7bvv_B126NqZH0DJGsURNMV1tauKZlyzYtxhaZnqD8CBY0bqXVOMctKGU/s16000/Image5.jpg" /></a></div></div>Now let’s run the application through IIS Express. You can see that the application is served through Kestrel Server (with DotNet.exe process)<br /><br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPeCqEqxr_sbpL5vMZhjFSUUrW6GuN2194RuDoLXly7NShZ5rzcQZbXYrV5pZW_uz8uTPqPoFDDhAe3e5hJeABjqeIPNkpYaq2_vUryEZ6MP_ZzMKLJGvaZ9RcSy0lan-Hp_ILEXGbE_I/s550/Image6.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="124" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPeCqEqxr_sbpL5vMZhjFSUUrW6GuN2194RuDoLXly7NShZ5rzcQZbXYrV5pZW_uz8uTPqPoFDDhAe3e5hJeABjqeIPNkpYaq2_vUryEZ6MP_ZzMKLJGvaZ9RcSy0lan-Hp_ILEXGbE_I/s16000/Image6.jpg" /></a></div></div>
<br /><div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIKO3Q_ELh0Haph20So3mGuqxAWN7KaYrTHfeo2ybjiVtG52V-mKxg7BsU4rCn0mGH_QypYbXmSRocKHXW8Fgio7HCrUXLTBQuCnzhyphenhyphen0bLh2wM0t-7H6Yyi6AHauH3HmXi6pruVk5f-AA/s550/image11.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="270" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIKO3Q_ELh0Haph20So3mGuqxAWN7KaYrTHfeo2ybjiVtG52V-mKxg7BsU4rCn0mGH_QypYbXmSRocKHXW8Fgio7HCrUXLTBQuCnzhyphenhyphen0bLh2wM0t-7H6Yyi6AHauH3HmXi6pruVk5f-AA/s16000/image11.jpg" /></a></div></div>Now let’s run the Application through Launch Application by selecting the profile to run the application with DotNet CLI or by the DotNet CLI command in order to check the Worker Process / Server serving the application. As we can see Kestrel server is serving the application.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFuwS1vRDvMB-mUlfDiRfScPh-Q9Lr3kFs3yLeVG83prpyZR2hWhsqkA1C82pDWE6F9ESVf7DX2LotdI3vmBkb3RfFAvjACMOBNZAtgVTJKBzK3hiD8UlDFWJH0BsO3jC6kQBI3hZ6Brc/s550/image7.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="457" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFuwS1vRDvMB-mUlfDiRfScPh-Q9Lr3kFs3yLeVG83prpyZR2hWhsqkA1C82pDWE6F9ESVf7DX2LotdI3vmBkb3RfFAvjACMOBNZAtgVTJKBzK3hiD8UlDFWJH0BsO3jC6kQBI3hZ6Brc/s16000/image7.jpg" /></a></div></div><div class="separator" style="clear: both; text-align: center;"><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3ruPzaI1XNmLYZW7CYB2BU4NfkCDdmTtUWfwHHcuh031N4K3VJfp2HCOhDxRZIeAJe338lK_s0YEaQ5EDIBZrSZWxR85Oh7aReaScaEJ0NiO6VEc2ZgH_d2a75VCyvbBskIuM6musr60/s550/Image8.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3ruPzaI1XNmLYZW7CYB2BU4NfkCDdmTtUWfwHHcuh031N4K3VJfp2HCOhDxRZIeAJe338lK_s0YEaQ5EDIBZrSZWxR85Oh7aReaScaEJ0NiO6VEc2ZgH_d2a75VCyvbBskIuM6musr60/s16000/Image8.jpg" /></a></div></div><div class="separator" style="clear: both; text-align: left;"><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;">Some of the difference between the InProcess vs OutOfProcess hosting model are:</div><div class="separator" style="clear: both;"><b>1.</b> In InProcess hosting model, request and response are served through w3wp.exe or IISExpress whereas in the OutOfProcess worker process involved is dotnet.exe</div><div class="separator" style="clear: both;"><b>2.</b> In InProcess hosting model, single web server is used whereas, In OutOfProcess hosting model, two web servers can be used.</div><div class="separator" style="clear: both;"><b>3.</b> InProcess hosting model provides better performance as compared to OutOfProcess hosting model. </div><div class="separator" style="clear: both;"><br /></div><div class="separator" style="clear: both;">I hope this article helped you in understanding the OutOfProcess hosting model.</div><div class="separator" style="clear: both;">Thanks.</div><div><br /></div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-48667111622928779292021-03-27T10:58:00.000-07:002021-03-27T10:58:31.317-07:00Understanding InProcess Hosting Model in ASP.NET Core<p>In this article, we will learn about one of the AspNetCoreHostingModel i.e. InProcess Hosting Model. If you are new to this ASP.NET Core tutorials series then I will recommend you to check the below articles:</p><p></p><ul style="text-align: left;"><li><a href="https://www.ittutorialswithexample.com/2021/02/create-first-application-with-asp-dot-net-core.html" target="_blank">Create your first application with ASP.NET Core 3.1</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/project-structure-in-aspnet-core-web-application.html" target="_blank">Project Structure in ASP.NET Core 3.1 Web Application</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/create-aspnet-core-web-application-with-vs-code.html" target="_blank">Create ASP.NET Core Web Application with Visual Studio Code</a></li></ul><p></p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHm7hzLqKYaF7VRQ8HyBp3I9OF8hA7txTSwIxCGOwFNrbHz8Jb-Cef86ILS4mKBowCVlMd3ipaC_G75atvvzof67Uc6Y_RRMhwRqqR-uNq0QDhunA_3gUP5NknhnaNXEWPYxPxrmCJ_fI/s550/Cover.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHm7hzLqKYaF7VRQ8HyBp3I9OF8hA7txTSwIxCGOwFNrbHz8Jb-Cef86ILS4mKBowCVlMd3ipaC_G75atvvzof67Uc6Y_RRMhwRqqR-uNq0QDhunA_3gUP5NknhnaNXEWPYxPxrmCJ_fI/s16000/Cover.png" /></a></div></div><div><span><a name='more'></a></span>In ASP.NET Core, there are two types of AspNetCoreHostingModel, one is <b>InProcess </b>and another is <b>OutOfProcess </b>hosting model. In InProcess hosting model, the ASP.NET Core application is hosted inside of the IIS Worker Process i.e. w3wp.exe. In OutOfProcess hosting model, Web Requests are forwarded to the ASP.NET Core app running on the Kestrel Server. In this article, we are covering the InProcess hosting model. InProcess hosting model provides better performance over OutOfProcess hosting because the request is not proxied over the loopback adapter in InProcess hosting model.</div><div><br /></div><div><b>Understanding the general architecture for the InProcess hosting model</b>:</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikPnXFSsZIXr431zV39LYql2ClwB_jJ4ZuMq7hD6LU7hcy1vPNfipfl-Gi3iXfmnpfczqFXXtGx8zuj_5X9jimzVYIE5DAqnQj2aPmhcjICZSt1pI3eqotPc-0NihF8YqjGec6oAinMsw/s550/Image11.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="266" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikPnXFSsZIXr431zV39LYql2ClwB_jJ4ZuMq7hD6LU7hcy1vPNfipfl-Gi3iXfmnpfczqFXXtGx8zuj_5X9jimzVYIE5DAqnQj2aPmhcjICZSt1pI3eqotPc-0NihF8YqjGec6oAinMsw/s16000/Image11.png" /></a></div></div>As you can see in the above image, A request came from the user to IIS through the internet over HTTP or HTTPS protocol. ASP.NET Core Module receives the request which is passed to IIS HTTP Server. After IIS HTTP Server, the request is sent to the ASP.NET Core application’s middleware pipeline. Middleware handles the request and passes it to the HttpContext instance to the application’s logic. Then application response is passed to IIS through the IIS HTTP Server. Further, IIS sends the response back to the user who initiated the request.<div><div><br /></div><div><b>Let’s do the hands-on in order to understand the hosting model</b>:</div><div>I am using the same application that we have created in the previous article of this series which was basically an Empty ASP.NET Core Application. Click on Startup.cs class.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKPyzSgEdYfByRbF-_j_zWwI1R7k68w10t95F3u7bO7YUIUvFkT3wxteb7zhMVdcHZOxh1eM5FoAtzrPrtiQMoa_kAir59pxRIXUuNoFmTm6KM3dfl9jfxZUCSD1GLKvJHVHF4AIe6PK0/s346/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="261" data-original-width="346" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKPyzSgEdYfByRbF-_j_zWwI1R7k68w10t95F3u7bO7YUIUvFkT3wxteb7zhMVdcHZOxh1eM5FoAtzrPrtiQMoa_kAir59pxRIXUuNoFmTm6KM3dfl9jfxZUCSD1GLKvJHVHF4AIe6PK0/s16000/Image1.jpg" /></a></div></div>Change the code in Configure method as highlighted in the below image which is for finding the ProcessName on which application is running.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi97JLExJKo5679srZTvu9FgSA6CyN-dw_yT_S-4XED4xQlkZNp3AAisYxLlK2wEYn9xVojFGOTrSXe2tbgvD6up7b5ZfDX8Ec7ghu-vHvnpNG20j0J4C9fQt_Q1qIMiTX40BcqeIh5XnI/s550/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="223" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi97JLExJKo5679srZTvu9FgSA6CyN-dw_yT_S-4XED4xQlkZNp3AAisYxLlK2wEYn9xVojFGOTrSXe2tbgvD6up7b5ZfDX8Ec7ghu-vHvnpNG20j0J4C9fQt_Q1qIMiTX40BcqeIh5XnI/s16000/Image2.jpg" /></a></div></div>Now right click on the project in order to view the properties.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvCqStYo4Y2MTEHDq9MA05Q4ga4Zb5eH9vOaQR9r62kOlmqfYWOwSjNFjLuULz5DHvLF8qGdkxv2aKyAtDldyoPkNoB1pfCyDqQNAQCmEh7WsXLW8OjSLsTRnfbKa1dOJfoM0_rz1C4rI/s654/Image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="654" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvCqStYo4Y2MTEHDq9MA05Q4ga4Zb5eH9vOaQR9r62kOlmqfYWOwSjNFjLuULz5DHvLF8qGdkxv2aKyAtDldyoPkNoB1pfCyDqQNAQCmEh7WsXLW8OjSLsTRnfbKa1dOJfoM0_rz1C4rI/s16000/Image3.jpg" /></a></div></div>Click on Debug tab in order to see the Hosting Model for the selected launch profile. We can change the hosting model from here (Dropdown contains three values that are Default (InProcess), InProcess, OutOfProcess) as well as by editing the .csproj file.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLKg31CYuauDnt_x3pFtLoRBkmN1mLRZD5QBnp251Kusl5cEVVIUB-RtxyMksw7aW68HU-qjm5I3_2gdyvpBOn-EZh_NOw4fon63JJ9R78HGZjUI1UoU5AX8BLaEi6wc9WAs95Q8l42Qg/s550/Image4.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="346" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLKg31CYuauDnt_x3pFtLoRBkmN1mLRZD5QBnp251Kusl5cEVVIUB-RtxyMksw7aW68HU-qjm5I3_2gdyvpBOn-EZh_NOw4fon63JJ9R78HGZjUI1UoU5AX8BLaEi6wc9WAs95Q8l42Qg/s16000/Image4.jpg" /></a></div></div>Right-click on the project in order to edit the .csproj file.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNJ4elWznQYpupVX0__xko-DviaXNzE1P78ZqSKy_jL2YY-Uu6mGeEcEW5KOr_eW9Y2LK4moQeKPYrbkyAg7tXpFQlfQZiFmg-a0B0uU7MoqqCmU0Tux6Gv9_Nu-r9_35A1gR6qKb2_0c/s550/Image5.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="401" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNJ4elWznQYpupVX0__xko-DviaXNzE1P78ZqSKy_jL2YY-Uu6mGeEcEW5KOr_eW9Y2LK4moQeKPYrbkyAg7tXpFQlfQZiFmg-a0B0uU7MoqqCmU0Tux6Gv9_Nu-r9_35A1gR6qKb2_0c/s16000/Image5.jpg" /></a></div></div><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-swkyTRK6Htb4rcCGS2zy1RKJR57lGsxAqhlOpb_k_dbmpZTLFmkSuYvItaNQmShkZILimpxHQi4nnfBSje3FKgJPMLB3O8rK2S97Wa83llgsZRoa5HfHusHyy8iReYKyAarH8HQpe3A/s550/Image6.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="203" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-swkyTRK6Htb4rcCGS2zy1RKJR57lGsxAqhlOpb_k_dbmpZTLFmkSuYvItaNQmShkZILimpxHQi4nnfBSje3FKgJPMLB3O8rK2S97Wa83llgsZRoa5HfHusHyy8iReYKyAarH8HQpe3A/s16000/Image6.jpg" /></a></div></div>In order to configure the application for InProcess hosting, set the value of AspNetCoreHostingModel property to InProcess as shown below.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHQhSaahlnic0XIHjK89VB2G9ZTjvxnMWggvjVNtdkO4o8hP-gpmTVcnz3Nfl00ifG0TgGpykUH081EQBXWqN__9bu7JUsiR8m6uoUr2_cTWt01VNjeZAEWyE4HUxUuPyq-tSAovgawsY/s550/image7.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="183" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHQhSaahlnic0XIHjK89VB2G9ZTjvxnMWggvjVNtdkO4o8hP-gpmTVcnz3Nfl00ifG0TgGpykUH081EQBXWqN__9bu7JUsiR8m6uoUr2_cTWt01VNjeZAEWyE4HUxUuPyq-tSAovgawsY/s16000/image7.jpg" /></a></div></div>Now run the application on the IIS Express profile, application is run on the iisexpress worker process. As we are using InProcess hosting model for the application and in InProcess hosting model, the ASP.NET Core application is hosted inside of the IIS Worker Process i.e. w3wp.exe in case the application is hosted on IIS or IISExpress (if the application is launched through the IIS Express).<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvZzKwrh11MkgeIOFbKjzYNVe6m9o8TyyXEyTs_h2qR40Do9Fp5o9zJxjIoT2uX50JBf9Sl30izXjgOqgnq5Vqw6PAy0Ca16q8kcihJsOq1no0rmagx-sYiEDR3Zo3Hxv2JZVJtDw5C6o/s550/Image8.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="199" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvZzKwrh11MkgeIOFbKjzYNVe6m9o8TyyXEyTs_h2qR40Do9Fp5o9zJxjIoT2uX50JBf9Sl30izXjgOqgnq5Vqw6PAy0Ca16q8kcihJsOq1no0rmagx-sYiEDR3Zo3Hxv2JZVJtDw5C6o/s16000/Image8.jpg" /></a></div></div>Go to Developer tools by clicking on Inspect element, then click on the Network tab in order to see the request and response header details. In the response header, it's clearly visible that the server which is sending the response is Microsoft-IIS.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkSgDRfeIkq3PFGig-5NePTiMpO9EWleL-N1nmKlMGEvtb0x8k-8aoZEsSJ_96_jIpBBOjqSy7bSF6ybzZbDMbjums1ae8h2vBwziiCGV-MZnip2MNTbQrr9zePP-AIUCavTg4Dre6S4s/s548/Image13.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="326" data-original-width="548" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkSgDRfeIkq3PFGig-5NePTiMpO9EWleL-N1nmKlMGEvtb0x8k-8aoZEsSJ_96_jIpBBOjqSy7bSF6ybzZbDMbjums1ae8h2vBwziiCGV-MZnip2MNTbQrr9zePP-AIUCavTg4Dre6S4s/s16000/Image13.jpg" /></a></div></div>Now let’s run the application through the Profile i.e. FirstCoreApplication (this can be as per your project) which will host the application on the Kestrel server.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIoZpSjVfJj2LMXSy_uLuP6hqsl-5Zr2KoLpgGlcr5jstC64FcP3mokSXZ-lTx04JLHm-JoVpRefy2BrIw-P4LwwdH2m0yBi_ZRDRM8IT3LqdZZMkNLWz_AoWmrzNpUUDH5Sy06wa_2w0/s550/Image9.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="265" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIoZpSjVfJj2LMXSy_uLuP6hqsl-5Zr2KoLpgGlcr5jstC64FcP3mokSXZ-lTx04JLHm-JoVpRefy2BrIw-P4LwwdH2m0yBi_ZRDRM8IT3LqdZZMkNLWz_AoWmrzNpUUDH5Sy06wa_2w0/s16000/Image9.jpg" /></a></div></div><br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8actP-PTAEQVUKp4GguZrIYAmBcj1Pn3ctjqQIOnBd-xMPTmnl7AmLV3ybcZ0gS_8r45t4cZ6_wPch6sz_F9uIB_uvofT0VRZDkm6voe2z-XICLUDjXk2ND2NHW9doh01JEUGR3_QeiI/s550/Image10.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="212" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8actP-PTAEQVUKp4GguZrIYAmBcj1Pn3ctjqQIOnBd-xMPTmnl7AmLV3ybcZ0gS_8r45t4cZ6_wPch6sz_F9uIB_uvofT0VRZDkm6voe2z-XICLUDjXk2ND2NHW9doh01JEUGR3_QeiI/s16000/Image10.jpg" /></a></div></div>Go to Developer tools by clicking on Inspect element, click on the Network tab in order to see the request and response header details. In the response header, it's clearly visible that the server is Kestrel. On running the application through the DotNet CLI, the application does not follow the InProcess hosting model, as Worker Process is dotnet.exe. dotnet.exe is the process which runs and host application with the kestrel server.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYqIhju6dDhZIvwyf32-otr5PjEf060YE-_vjcBjnhWErIsIvvT-RraeH_f8je5guIYKM05WfvpOMCyHVncfIo7SYtoaeQgckaC45h5YopPz8rjyvCTStSb_UHNsHl2W1uzU0dRm9OTjc/s550/Image12.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="352" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYqIhju6dDhZIvwyf32-otr5PjEf060YE-_vjcBjnhWErIsIvvT-RraeH_f8je5guIYKM05WfvpOMCyHVncfIo7SYtoaeQgckaC45h5YopPz8rjyvCTStSb_UHNsHl2W1uzU0dRm9OTjc/s16000/Image12.jpg" /></a></div></div><div>I hope this article will help you in understanding InProcess hosting model. In the next article, we will understand the OutOfProcess hosting model.</div><div>Thanks.</div><div><br /></div><div><div><div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s0/cs-wh-234x16.gif" /></a></div></div></div></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-19731580493084342862021-03-20T08:30:00.000-07:002021-03-20T08:30:11.012-07:00Evolution / History of ASP.NET<p>Recently, I posted a video on our <a href="https://www.youtube.com/c/ITTutorialswithExample/" target="_blank">YouTube channel</a> in which I have given brief information about the Evolution / History of ASP.NET. In this post, I am going to share the content which is shown during the presentation.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitf3inITARYerlQHpwVArqf0KdHZoaCZxjqJ_N4FaytibEbR4wR4v3F7xCSwPUAH1DNedHUJJJCmnyxzFLVOLduK7vfQqCGcpE-fzQsnw4DDCzSxCE19JKcPEUFQRP1VoXLdjsxFLJL4E/s550/EvolutionCover.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitf3inITARYerlQHpwVArqf0KdHZoaCZxjqJ_N4FaytibEbR4wR4v3F7xCSwPUAH1DNedHUJJJCmnyxzFLVOLduK7vfQqCGcpE-fzQsnw4DDCzSxCE19JKcPEUFQRP1VoXLdjsxFLJL4E/s16000/EvolutionCover.png" /></a></div></div><span><a name='more'></a></span><div>If you have not seen the video yet, I am adding the link so that you can watch it here. </div><div><br /></div>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="309" src="https://www.youtube.com/embed/4M8_1VLRe8Q" width="550"></iframe>
<div><br /></div><div><b><u>Evolution of ASP.NET (Quick Discussion on some of the popular Version(s) of ASP.NET)</u></b></div><div><div><b><br /></b></div><div><b>Evolution of ASP.NET</b></div><div><ul style="text-align: left;"><li>ASP (Active Server Pages) - 1996</li><li>ASP.NET Web Forms - 2002</li><li>ASP.NET MVC - 2009</li><li>ASP.NET Core - 2016</li><li>ASP.NET Core 2 - 2017</li><li>ASP.NET Core 3.1 - 2019</li><li>ASP.NET Core 5.0 - 2020</li></ul></div></div><p><br /></p><p><b>1. ASP (Active Server Pages)</b></p><p></p><ul style="text-align: left;"><li>Known as Microsoft’s First Server Side Language.</li><li>ASP was released in 1996 as part of IIS 3.0.</li><li>ASP Pages are currently supported by all the version of IIS (Internet Information Services)</li><li>ASP pages have .asp file extension.</li><li>ASP is interpreted language means the compiler interprets the compiling code. </li></ul><p></p><p><br /></p><p><b>2. ASP.NET Web Forms</b></p><p></p><ul style="text-align: left;"><li>ASP.NET Web Forms lets us to build dynamic websites using a drag and drop, event-driven model.</li><li>ASP.NET WebForms was released in 2002.</li><li>ASP.NET Web Forms have efficient error handling support as compared to ASP.</li><li>ASP Web Form pages have .aspx file extension.</li><li>Validations in ASP.NET Web Forms can be easily implemented by setting up properties on the control. </li></ul><p></p><p><b>Drawbacks</b></p><p></p><ul style="text-align: left;"><li>Code-behind and tightly coupled code make unit testing almost impossible.</li><li>ViewState stored on the page which increases the size of the page and reduces the overall performance.</li><li>Lack of separation of concerns (SoC).</li><li>Lack of Code Reusability due to Code behind file and tightly coupled approach.</li></ul><p></p><p><br /></p><p><b>3. ASP.NET MVC</b></p><p></p><ul style="text-align: left;"><li>ASP.NET MVC is a web application framework developed by Microsoft that implements MVC i.e. Model-View-Controller Pattern.</li><li>It was released in 2009.</li><li>It is Open Source Software.</li><li>It is lightweight as compared to ASP.NET WebForms.</li><li>Separation of Concerns and provides better support for the test-driven development.</li><li>It does not use view state or server-based forms.</li></ul><p></p><p><b>Drawbacks</b></p><p></p><ul style="text-align: left;"><li>ASP.NET MVC uses .NET Framework and it requires Windows OS/Server for the build or deployment purpose.</li></ul><p></p><p><br /></p><p><b>4. ASP.NET Core</b></p><p></p><ul style="text-align: left;"><li>ASP.NET Core is a Cross-Platform (Windows, Mac, and Linux), high-performance, open-source framework for building modern, cloud-enabled, Internet-connected applications.</li><li>It was released in 2016.</li><li>Built-in Dependency Injection.</li><li>It is lightweight and has a modular HTTP request pipeline.</li><li>ASP.NET Core applications can run on the .NET Core Framework as well as on full .NET Framework (ASP.NET Core is composed of the .NET Standard Libraries). ASP.NET Core 2.X</li><li>It was released in 2017.</li><li>ASP.NET Core 2.0 has introduced the Razor Pages to create dynamic web applications.</li><li>It comes with the “Microsoft.AspNetCore.All” package which is a meta-package for all the dependencies which are required to create ASP.NET Core 2.0 application.</li><li>ASP.NET Core 2.0 target .NET Standard 2.0.</li></ul><p></p><p><br /></p><p><b>5. ASP.NET Core 3.1</b></p><p></p><ul style="text-align: left;"><li>It was released in 2019.</li><li>It has Partial class support for the Razor components.</li><li>Pass parameter to top-level components.</li><li>New component tag helper.</li><li>Detailed error during Blazer Application Development.</li><li>Breaking Changes for SameSite Cookies etc. </li></ul><p></p><p><br /></p><p><b>6. ASP.NET Core 5.0</b></p><p></p><ul style="text-align: left;"><li>It was released in 2020.</li><li>.NET Core MVC & Razor page improvements.</li><li>MVC Model binding improvements.</li><li>Auto browser refresh with dotnet watch.</li><li>Build-in OpenAPI and Swagger UI Support for Web APIs.</li></ul><p></p>
<p>I am also sharing the presentation with the content (mentioned above) as well so that you can easily refer to it whenever required.</p>
<div>
<iframe allowfullscreen="" frameborder="0" height="420" marginheight="0" marginwidth="0" scrolling="no" src="//www.slideshare.net/slideshow/embed_code/key/nv8vLOJB85j48" style="border-width: 1px; border: 1px solid #CCC; margin-bottom: 5px; max-width: 100%;" width="510"></iframe>
</div>
<p>I hope this post will help you to understand the Evolution / History of ASP.NET.</p><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s0/cs-wh-234x16.gif" /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-13600190227093354182021-03-11T06:11:00.001-08:002021-03-11T06:11:27.908-08:00Create ASP.NET Core Web Application with Visual Studio Code<p>In this article, we will see How to create an empty ASP.NET Web Application with .NET CLI and Visual Studio Code. In the previous article of this series, we already covered the below articles. </p><p></p><ul style="text-align: left;"><li><a href="https://www.ittutorialswithexample.com/2021/02/create-first-application-with-asp-dot-net-core.html" target="_blank">Create your first application with ASP.NET Core 3.1</a></li><li><a href="https://www.ittutorialswithexample.com/2021/03/project-structure-in-aspnet-core-web-application.html" target="_blank">Project Structure in ASP.NET Core 3.1 Web Application</a></li></ul><p></p><div>I recommend you to go through these articles first if you are new to this series or new to .Net Core Technology.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLHbWn2_6LpBJ2tFQsbv8svWI86U255mcOWi9-VwhN9tsGrpSKG7spKaugKR6KBpg26R3UpeubBBDmnygOEMn9e0cu2HAC15gP9uahK2zJ0Nr2DZhVzHwefLPHLqe6Ra6rMuPth25_z00/s550/Cover.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLHbWn2_6LpBJ2tFQsbv8svWI86U255mcOWi9-VwhN9tsGrpSKG7spKaugKR6KBpg26R3UpeubBBDmnygOEMn9e0cu2HAC15gP9uahK2zJ0Nr2DZhVzHwefLPHLqe6Ra6rMuPth25_z00/s16000/Cover.png" /></a></div></div>In order to create the .Net Core application, we must have .Net Core SDK installed in the system. (In this example, I am using .Net Core 3.1). Go to the Microsoft official website in order to download the .Net Core SDK.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgde6bn-e1pZh7iannAhzlZthduz76zeU_3MMmYnhg4opCoPqclAWR1APe3lW7Ox5XjgcS26o2qCbOycRzYg3yX1ViYB8iyycg1TfO-BbTLHakR4o2V9tOIV9fjzWuzUCerqID5PQoI2Os/s550/image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="274" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgde6bn-e1pZh7iannAhzlZthduz76zeU_3MMmYnhg4opCoPqclAWR1APe3lW7Ox5XjgcS26o2qCbOycRzYg3yX1ViYB8iyycg1TfO-BbTLHakR4o2V9tOIV9fjzWuzUCerqID5PQoI2Os/s16000/image1.jpg" /></a></div></div>Once SDK is installed, Open Visual Studio Code Editor. If you don’t have it already installed in your system, then go to the Microsoft official site in order to download it free of cost. Once downloaded and installed, Go to the Terminal menu, click on New Terminal.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLZbFSDijjzAUUeHE5hM5ozaWpjzP73JXhLd3a5bpdJU1IqrNIgwfzJrObUcv4y2jH4NOVz7Vf8LpL2rDn20yZfR7P7rMTpoUSqytI67PDDGQCV9EFhDG2kFNANueIZH5RNCQWuhQxHkw/s550/image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="354" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLZbFSDijjzAUUeHE5hM5ozaWpjzP73JXhLd3a5bpdJU1IqrNIgwfzJrObUcv4y2jH4NOVz7Vf8LpL2rDn20yZfR7P7rMTpoUSqytI67PDDGQCV9EFhDG2kFNANueIZH5RNCQWuhQxHkw/s16000/image2.jpg" /></a></div></div>You will see the terminal as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB6eveYOxvgl-evkW1q3BhEZZHw8SepEDRaI57itOwEvJM5m5jzTOvmCGp2RpRPoe_TQQVV86JGUeHCo4wNZz2cVu69q3ez6e9I6QSaY0gluuuqVLAfn5iqL0OQgCunAFRoXwTq2LZ9ZQ/s550/image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="191" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB6eveYOxvgl-evkW1q3BhEZZHw8SepEDRaI57itOwEvJM5m5jzTOvmCGp2RpRPoe_TQQVV86JGUeHCo4wNZz2cVu69q3ez6e9I6QSaY0gluuuqVLAfn5iqL0OQgCunAFRoXwTq2LZ9ZQ/s16000/image3.jpg" /></a></div></div>Change the directory to the location where you want to create your first ASP.NET Core Web Application with .Net CLI. In my case, I already created a folder on the desktop (and named it as Project).<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkFy86X0nwhOu8kyyhbYPjz6nYfxx_Ki5EWDc0hUgLsni8TTzVTQrF95s0PyOP2coDFdrpP8qz86PSDieZzrL0E9sMQd4TjYJovRhvUw3lY4Cx6C5TB_j15BfO3D46FOoPD4FWs6bifbo/s550/image4.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="152" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkFy86X0nwhOu8kyyhbYPjz6nYfxx_Ki5EWDc0hUgLsni8TTzVTQrF95s0PyOP2coDFdrpP8qz86PSDieZzrL0E9sMQd4TjYJovRhvUw3lY4Cx6C5TB_j15BfO3D46FOoPD4FWs6bifbo/s16000/image4.jpg" /></a></div></div>Run the <b>dotnet</b> command in the terminal. If dotnet core is already installed in your system, then you will see the options as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbaHUBTINuK54yCyWo3Z3dS1UhD2V-GcJ8CRSC2yC58hnVcxQ-87aFJzlIFyRHws0GyqjjJWB6pm94zq9QxmhpWrNc9MEiJrsnSBMw8SjuAz9lC4NGiCMTdHlxl29EZw4foDnsVx1IhY4/s550/image5.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="237" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbaHUBTINuK54yCyWo3Z3dS1UhD2V-GcJ8CRSC2yC58hnVcxQ-87aFJzlIFyRHws0GyqjjJWB6pm94zq9QxmhpWrNc9MEiJrsnSBMw8SjuAz9lC4NGiCMTdHlxl29EZw4foDnsVx1IhY4/s16000/image5.jpg" /></a></div></div>Run the <b>dotnet --version</b> command in order to check the version of .Net Core SDK installed in your system. In my system, I have .Net Core 3.1.402 Version.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh04rifo-bOYhgsZJMK5kPzKxSQHeqxTbOpLigu97zD1L_DEFDvxomH7TIEUVkR_Rx8cXlyqYlbStxFYenw2ATWFGGU_y2geOo54Y3XdQq5oYkXITCuDt4OV_bNcEk_k04a9Ah0FXEHQ04/s550/image6.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="56" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh04rifo-bOYhgsZJMK5kPzKxSQHeqxTbOpLigu97zD1L_DEFDvxomH7TIEUVkR_Rx8cXlyqYlbStxFYenw2ATWFGGU_y2geOo54Y3XdQq5oYkXITCuDt4OV_bNcEk_k04a9Ah0FXEHQ04/s16000/image6.jpg" /></a></div></div>You can use <b>--help</b> in order to check the options and commands in case of any help required. Use the <b>dotnet new</b> command in order to create a new project and pass the short name for the type of project/solution you want to create. You can use the--help in order to the available projects as well as options related to .Net Core CLI.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY5CmJbQijKBUVJm-sDyGq3Wy_18ebCPTaTVFj12kIHjNjP8sq98otaWw4ifHO8DbeaDhWb8Pxu7zQsVgRXaoUCq69xWTuJBR2nMtoQaBpZrzl1i-ddqvPPuwmjUVF9psTU7AaPejEqEc/s550/image7.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="24" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY5CmJbQijKBUVJm-sDyGq3Wy_18ebCPTaTVFj12kIHjNjP8sq98otaWw4ifHO8DbeaDhWb8Pxu7zQsVgRXaoUCq69xWTuJBR2nMtoQaBpZrzl1i-ddqvPPuwmjUVF9psTU7AaPejEqEc/s16000/image7.jpg" /></a></div></div>As you can see, we can create several kinds of projects through .Net Core CLI. In this example, I am going to create an ASP.NET Core Empty project.<div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1NtuHk0xZ28ueYpSh7zP41SEl9ozcrFgyGxrlPvbqKFJdIIJBIQ1Hor_RjFgvcUBfCVn0x2e9HFCNMmF-1hu3Idtb7bIyaqW1prp5B8VbzI8R26CgTQo1WUN5uuVyHVtxiAec2ykHCpQ/s550/image8.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="294" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1NtuHk0xZ28ueYpSh7zP41SEl9ozcrFgyGxrlPvbqKFJdIIJBIQ1Hor_RjFgvcUBfCVn0x2e9HFCNMmF-1hu3Idtb7bIyaqW1prp5B8VbzI8R26CgTQo1WUN5uuVyHVtxiAec2ykHCpQ/s16000/image8.jpg" /></a></div></div>Run <b>dotnet new web --name <NAME_OF_PROJECT></b> in order to create an empty ASP.NET Core web application. On executing the command, ASP.Net Core Empty template will be created followed by the <b>dotnet restore</b> command.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKv9DI1yRuW34rkLjUkYmIIcn_q1i5iiqZQ43arQvh0Z0XleCIl54pO6XA-L2vF5KJeKxITghXWedG65xUOg8soEvQW27ZE3wGt0LymOuTxe-7uS_goF3JignH2Sd6MSuwThM1mMoj6d4/s550/image9.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="103" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKv9DI1yRuW34rkLjUkYmIIcn_q1i5iiqZQ43arQvh0Z0XleCIl54pO6XA-L2vF5KJeKxITghXWedG65xUOg8soEvQW27ZE3wGt0LymOuTxe-7uS_goF3JignH2Sd6MSuwThM1mMoj6d4/s16000/image9.jpg" /></a></div></div>Now change the directory to the project location. In my case, I have created a project i.e. AspNetCoreEmptyWebApp so I am changing the directory through the terminal to that folder as it contains the .csproj file which is required to run the .Net Core project through the CLI. Once the directory is changed, run <b>dotnet run</b> command in the terminal in order to launch the web application.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYVWpTY4vIhlEV-Vgh4dQ_929tw3o2yVGDlm55zsU-hoSMcFPKp4_Gh_AAg3otVeXIYiYsdqQ521tDXsyWhnYLb6V_NF1IVl3eERgvOuwL7tSh-eILvV_Mt7pneqsMVW4JKbuJHsG5H3I/s550/image10.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="177" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYVWpTY4vIhlEV-Vgh4dQ_929tw3o2yVGDlm55zsU-hoSMcFPKp4_Gh_AAg3otVeXIYiYsdqQ521tDXsyWhnYLb6V_NF1IVl3eERgvOuwL7tSh-eILvV_Mt7pneqsMVW4JKbuJHsG5H3I/s16000/image10.jpg" /></a></div></div>Once the application is launched successfully, copy or click on the URL on which your application is running. You can see Hello World! on the screen which is basically coming from the startup.cs class.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmum8pAXvAmUkYVPv5FF4LbSh71Jqh6EwM3dCVAC9a9uZvIkeVS8sidXag98VDoDbVsUATfve7TiClGFnjDyJjaeujIo9lx9OOhl9ehtcXS4OpXu4_0oDspy9_gAU0ZJYNw1vis4-4R7E/s550/image11.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="177" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmum8pAXvAmUkYVPv5FF4LbSh71Jqh6EwM3dCVAC9a9uZvIkeVS8sidXag98VDoDbVsUATfve7TiClGFnjDyJjaeujIo9lx9OOhl9ehtcXS4OpXu4_0oDspy9_gAU0ZJYNw1vis4-4R7E/s16000/image11.jpg" /></a></div></div>Now let’s open that project into Visual Studio Code. We can directly open the folder through the File menu and clicking on the open folder menu option or by running “<b>code .</b>” in the terminal as shown in the below image.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM7EWonzqFjwHG2SPohCd0QxvUumS_LoNhX6IxY8hTB7ieaeT5VXKN__fZyrYfI-kgItwzPFVJ_lia-QgnRq64ze_Ro238zWCHEEvz5NCVxJN0lPPSnjxj3LtvN47ZI2ovCrlC2E0_Ip8/s550/image12.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="43" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM7EWonzqFjwHG2SPohCd0QxvUumS_LoNhX6IxY8hTB7ieaeT5VXKN__fZyrYfI-kgItwzPFVJ_lia-QgnRq64ze_Ro238zWCHEEvz5NCVxJN0lPPSnjxj3LtvN47ZI2ovCrlC2E0_Ip8/s16000/image12.jpg" /></a></div></div>On opening the project for the first time, A message is prompted to add the required assets to build and debug the application. Click on Yes. On clicking on Yes, a folder i.e. <b>.vscode</b> will be created in the project.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJwi2FpZ5JhjRH4-knf8LXaZCF4WkpUZSDy1ggk426eXVj_5oq1D_7GDCErxZmVzxsKJo1Xe7DzVoSgyunV4af4eQ0a_Z155IH90CGhKfYy5OxiymepxjMsSOf8jm-WzYT_l79DYpQoAE/s474/image13.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="121" data-original-width="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJwi2FpZ5JhjRH4-knf8LXaZCF4WkpUZSDy1ggk426eXVj_5oq1D_7GDCErxZmVzxsKJo1Xe7DzVoSgyunV4af4eQ0a_Z155IH90CGhKfYy5OxiymepxjMsSOf8jm-WzYT_l79DYpQoAE/s16000/image13.jpg" /></a></div></div>You can see that our ASP.NET Core project is opened in the Visual Studio Code editor with the structure as shown in the below image. (Please check, <a href="https://www.ittutorialswithexample.com/2021/03/project-structure-in-aspnet-core-web-application.html" target="_blank">Project Structure in ASP.NET Core 3.1 Web Application</a> in case you want to understand the project as well as files structure and its role)<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitC2ciN0Y3L-mIMDhjoBBQCNF7ei9CGsgQ4Hz2RR3g5Kt2FE7BnIwlrCRsLGjH5OvhPLoztBYRPC6SuYXfJYN83V8FUl-wm22Vglx8zGOhu99VWZSp-i-ngacbeU4jTwmHYql60_iZHoo/s345/image14.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="316" data-original-width="345" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitC2ciN0Y3L-mIMDhjoBBQCNF7ei9CGsgQ4Hz2RR3g5Kt2FE7BnIwlrCRsLGjH5OvhPLoztBYRPC6SuYXfJYN83V8FUl-wm22Vglx8zGOhu99VWZSp-i-ngacbeU4jTwmHYql60_iZHoo/s16000/image14.jpg" /></a></div></div>Now, go to the Run menu, click on Run without debugging in order to run the application without debugging it. In a few seconds application is launched with the ports specified in the launchsettings.json file.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRozMWkwOs6OfHc-IA5MoKy1FVvXpFPWFMUkEzmt3eP68yWPXVBXwS5A_7V0Q22csEruJE29r7tRjUFr_V908EkMU-IuiX4ZFz3dsABhHM6URNcZjtlMVh0RsYYWubRH8HBrSnWYXXAJE/s532/image15.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="317" data-original-width="532" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRozMWkwOs6OfHc-IA5MoKy1FVvXpFPWFMUkEzmt3eP68yWPXVBXwS5A_7V0Q22csEruJE29r7tRjUFr_V908EkMU-IuiX4ZFz3dsABhHM6URNcZjtlMVh0RsYYWubRH8HBrSnWYXXAJE/s16000/image15.jpg" /></a></div></div><br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEuv5cWNuKXPqsDbN1ppsWR74Q5TeIIT93Dw6iMpLYylZuhhyphenhyphenPszFcNuW-XgzW2W7d65T3AsqUJZ4GYACIwMDsYbSNdGfXcuGLLvscm22vKrvB5sUTmmFiA0u7UfskhxcaeuFQ4yiP3OI/s550/image16.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="231" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEuv5cWNuKXPqsDbN1ppsWR74Q5TeIIT93Dw6iMpLYylZuhhyphenhyphenPszFcNuW-XgzW2W7d65T3AsqUJZ4GYACIwMDsYbSNdGfXcuGLLvscm22vKrvB5sUTmmFiA0u7UfskhxcaeuFQ4yiP3OI/s16000/image16.jpg" /></a></div></div>In case you want to debug the application, add the breakpoint where you want to test and debug the application.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9BDF9H81RbRgdM39J6GPluS6cqnewB27K0a3bORvPhG4S-8gCha-Y7EeOzVTvy6M13yQi2L9TpQPiErJeqxALYNfJAUr2bxbICjGsYXuhBXJ4DQ4iDmZ27GIiqIRQBTlziqyMx5w4UGw/s550/image17.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="215" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9BDF9H81RbRgdM39J6GPluS6cqnewB27K0a3bORvPhG4S-8gCha-Y7EeOzVTvy6M13yQi2L9TpQPiErJeqxALYNfJAUr2bxbICjGsYXuhBXJ4DQ4iDmZ27GIiqIRQBTlziqyMx5w4UGw/s16000/image17.jpg" /></a></div></div>And then go to the Run menu & then click on the Start Debugging option. Once the application reached the breakpoint, it will be highlighted (in a similar manner as in Visual Studio IDE). You can do step in, step out, add items to the watch window, etc.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNNwEw3yQbecQqOToONTCThULiNVH0F_ZM49G62g8JrDJWUe73uXelaKiSmk0L8unPNCtd9EEOMCbgFYQm6AWgR4kTEgbgKkk29C1XqzwsPXTIrQtKo3gWj9g4kYAxXg-o1k8SbmsEUNQ/s317/image18.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="205" data-original-width="317" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNNwEw3yQbecQqOToONTCThULiNVH0F_ZM49G62g8JrDJWUe73uXelaKiSmk0L8unPNCtd9EEOMCbgFYQm6AWgR4kTEgbgKkk29C1XqzwsPXTIrQtKo3gWj9g4kYAxXg-o1k8SbmsEUNQ/s0/image18.jpg" /></a></div></div><br /><div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoaG5B-5hUvGWtf8ZAagaKZtH7otek01mGKrZngYvzpzjwpU6WUkQB0ICPDpQdJF0EPwVwPv7BQEuVuN898xsogky36n9nW_RTO4eFoJ_edNvt5Qv1DctzcC8ugyf88H0gpitZO7s7X7A/s550/image19.jpg" style="margin-left: 1em; margin-right: 1em;"><br /><img border="0" data-original-height="273" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoaG5B-5hUvGWtf8ZAagaKZtH7otek01mGKrZngYvzpzjwpU6WUkQB0ICPDpQdJF0EPwVwPv7BQEuVuN898xsogky36n9nW_RTO4eFoJ_edNvt5Qv1DctzcC8ugyf88H0gpitZO7s7X7A/s16000/image19.jpg" /></a></div></div></div></div>
<div>I hope this article will help you in getting started with creating and managing the ASP.NET Core web application with .Net CLI and launching & debugging it through Visual Studio Code.</div><div>Thanks.</div><div><br /></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-46138095211005660942021-03-06T23:40:00.000-08:002021-03-06T23:40:15.200-08:00Project Structure in ASP.NET Core 3.1 Web Application<p>In this article, we will learn about the Project Structure of the ASP.NET Core 3.1 Web Application. This is the continuation of the ASP.NET 3.1 Tutorials series. I will recommend you to go through the below article of this series if not already gone through that:</p><p></p><ul style="text-align: left;"><li><a href="https://www.ittutorialswithexample.com/2021/02/create-first-application-with-asp-dot-net-core.html" target="_blank">Create your first application with ASP.NET Core 3.1</a></li></ul><p></p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEXB5zFoNo-haVG7OH5rSNErsZbk1qzZLhIJTjgQaSuDqcaQMxDtVkdnKo-wABXdrhiT6KOxB38TaRAGxajWywS7Nr1gxptYSyXlnTyK79ElYn1ahFTAoICLMIRai54AbqRdFuv_hXclE/s550/Cover.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEXB5zFoNo-haVG7OH5rSNErsZbk1qzZLhIJTjgQaSuDqcaQMxDtVkdnKo-wABXdrhiT6KOxB38TaRAGxajWywS7Nr1gxptYSyXlnTyK79ElYn1ahFTAoICLMIRai54AbqRdFuv_hXclE/s16000/Cover.png" /></a></div></div>As in the previous article, we created an empty ASP.NET Core Project and the structure of the project is as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8_jNRjdPpZpoABTGdsmJunkpxj6dfMh0j93fEOVwkh52vl7RfUkMK5lyD7vZ-fCetD-eZh7xGxQ0ZPNM5oKXQkZhulOdnMMbMZm5oLOoBpoqlTUtrgkSUrf2GrDXPjegiOXmlnbBXJRo/s335/image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="257" data-original-width="335" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8_jNRjdPpZpoABTGdsmJunkpxj6dfMh0j93fEOVwkh52vl7RfUkMK5lyD7vZ-fCetD-eZh7xGxQ0ZPNM5oKXQkZhulOdnMMbMZm5oLOoBpoqlTUtrgkSUrf2GrDXPjegiOXmlnbBXJRo/s16000/image1.jpg" /></a></div></div><div>Let’s start exploring each folder and file that exists in the Project Structure for ease of understanding.</div><div><b><br /></b></div><div><b>.csproj File</b>: Right-click on the project and then click on Edit Project File in order to edit the .csproj file (In .NET Framework we can’t see that option until the project is unloaded from the solution explorer and the content of .csproj was quite difficult to understand).</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqNhZ-3yd96xq_QUJ0SY_6UO5AYMxqWW96X2Fb5L8C1MCirBlT4js_M4-AtOzwejosNDWRYEwBJGr6nbLehkSGc-MqMKMkr69cJdHQYIeYhH2tTKfZpKHFIeyt31uNkaQsfs5lYdOQLG4/s770/image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="770" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqNhZ-3yd96xq_QUJ0SY_6UO5AYMxqWW96X2Fb5L8C1MCirBlT4js_M4-AtOzwejosNDWRYEwBJGr6nbLehkSGc-MqMKMkr69cJdHQYIeYhH2tTKfZpKHFIeyt31uNkaQsfs5lYdOQLG4/s16000/image2.jpg" /></a></div></div>Once clicked on Edit Project File, .csproj file will be opened in Visual Studio as shown below.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqsnePNYXXvrosk1GoncC88XBq7hhh2w5TlQH1D5PSJFRGaGzJXp1Oyt4GuyvHJ9AeNGXSh1AXzvNqq0plZDcE4IwVxcW9lf7o0DwaDzQ_7OGQANb7EskgsyXqRq9K7_S4N8H0ZcOQZsk/s533/image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="149" data-original-width="533" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqsnePNYXXvrosk1GoncC88XBq7hhh2w5TlQH1D5PSJFRGaGzJXp1Oyt4GuyvHJ9AeNGXSh1AXzvNqq0plZDcE4IwVxcW9lf7o0DwaDzQ_7OGQANb7EskgsyXqRq9K7_S4N8H0ZcOQZsk/s16000/image3.jpg" /></a></div></div><div>As you can see TargetFramework element specifies the target framework of our ASP.NET Core application. Netcoreapp3.1 is the TFM that stands for the Target Framework Moniker. On adding the dependencies through NuGet, it will add another ItemGroup element which contains the details of the Package in PackageReference element.</div><div><br /></div><div><b>launchSettings.json</b>: Properties folder contains a file i.e. launchSettings.json file which contains all the information required to launch the application. It contains the profiles through which the application can be run, each profile is mapped to a commandName, applicationUrl on which application is launched, environmentVariables, etc.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0j_UVnW1uLtrhcl7eb1NxgnNJ-OMxKg2UWjl0gmsHxOxZExcs4sX4aRaYmahHccvFCmxwyNgbICMSEwxXflecxVDdN8pi22wZo_MB2L_24XfHzsO26drToL4-UgKuiSV0_oVoyIoObIw/s550/image4.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="485" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0j_UVnW1uLtrhcl7eb1NxgnNJ-OMxKg2UWjl0gmsHxOxZExcs4sX4aRaYmahHccvFCmxwyNgbICMSEwxXflecxVDdN8pi22wZo_MB2L_24XfHzsO26drToL4-UgKuiSV0_oVoyIoObIw/s16000/image4.jpg" /></a></div></div>As you can see, In the above launch setting we have two profiles. One will launch the application on IIS Express and another through the Kestral Server (used in the case when the application is run through the DotNet CLI or profile is selected through the Visual Studio Launch icon).<br /><div><br /></div><div><b>appsettings.json</b>: In .Net Framework, we store application-level settings or configuration in the web.config. In the .Net Core framework, appsettings.json will do the same work. All the connection strings, application-related settings are stores in the appsettings.json file in JSON format.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0b83eRKGsI0iHGSBa9OpWFrmIUBkqbaxb4XUqpmQmhJlwMo3kJKZsTc0BDENAcYWFS0oKEy0V5EUpDN4kCyb_aMokXyIaM1o1X1st1wxh_htM1RLn6ohsQerqzvx7CKibKWDKDjGF_YQ/s550/image5.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="223" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0b83eRKGsI0iHGSBa9OpWFrmIUBkqbaxb4XUqpmQmhJlwMo3kJKZsTc0BDENAcYWFS0oKEy0V5EUpDN4kCyb_aMokXyIaM1o1X1st1wxh_htM1RLn6ohsQerqzvx7CKibKWDKDjGF_YQ/s16000/image5.jpg" /></a></div></div><div><br /></div><b>Program.cs</b>: Program.cs file contains the main method which is the entry point for the application. It will create a web host builder and configure the services defined in Startup.cs file.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirbPDlXHXyN5Lt_qoMQGzSeI52tJJqP2G_zCR5vGUcpJuU1HF84UHSJIRbP0CAKio-QdqKhbrloadRyiil7dCZWRJCPC6hewKxQmLxuBLh9Kq56d-9Un6fYXchZ6_9iIPZyB0DaUifGw4/s550/image6.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="437" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirbPDlXHXyN5Lt_qoMQGzSeI52tJJqP2G_zCR5vGUcpJuU1HF84UHSJIRbP0CAKio-QdqKhbrloadRyiil7dCZWRJCPC6hewKxQmLxuBLh9Kq56d-9Un6fYXchZ6_9iIPZyB0DaUifGw4/s16000/image6.jpg" /></a></div></div><b><div><b><br /></b></div>Startup.cs</b>: Startup.cs file used to define all services used in the application and configure the HTTP Request pipeline with the use of middleware components. It contains ConfigureServices method where you can register the services, classes with the use of built-in DI Container, and Configure method which is used to configure the HTTP Request Pipeline. Request pipeline is configured with the help of middleware components. We will learn in detail about the middleware component in the up coming article of this series.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMaAgw6S_x2c552kawsfthPX9TlEO59aV8cXqVbjXfh0EdbYJCodaGKlrjgTBgcOQRoBHzGhapDKwa6Z7-hoZJxqY4Di0MjjbB-QgEAw8QSdR2zpoGDNxPe0p7Y7EWV1Y0BQ6ObpuLgqA/s550/image7.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="270" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMaAgw6S_x2c552kawsfthPX9TlEO59aV8cXqVbjXfh0EdbYJCodaGKlrjgTBgcOQRoBHzGhapDKwa6Z7-hoZJxqY4Di0MjjbB-QgEAw8QSdR2zpoGDNxPe0p7Y7EWV1Y0BQ6ObpuLgqA/s16000/image7.jpg" /></a></div></div><div><br /></div><div><b>wwwroot Folder</b>: A wwwroot folder needs to be created in order to serve and store static files like CSS, Javascript, images, icons, etc. We will see its usage when we learn about the Static Files in the upcoming articles of this series.</div><div><br /></div><div>Another interesting feature of the ASP.NET Core Project that files in the project are sync with the files in the system in real-time. Let say on adding a file through the file explorer in the project (not through Visual Studio), files created/altered immediately reflected in the Solution Explorer window. If we delete any file through file explorer, the file will be deleted immediately from the solution explorer as well. In the older version of .Net Framework, we need to include and exclude files manually if files added/deleted through the windows explorer window.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEincuSZ9THekwMRGafupjWtIkurBOo_OxUzw3MvYbMME5LAk85ya7WbEms_FAW-_5WoeQPYaCmM4as5F8dyZLVZkBY2Y5Hbc43ckUlVRQM3Djw7cl9-fp-HdK1revLuckIPgI26auX3Kns/s550/image8.gif" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="550" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEincuSZ9THekwMRGafupjWtIkurBOo_OxUzw3MvYbMME5LAk85ya7WbEms_FAW-_5WoeQPYaCmM4as5F8dyZLVZkBY2Y5Hbc43ckUlVRQM3Djw7cl9-fp-HdK1revLuckIPgI26auX3Kns/s16000/image8.gif" /></a></div></div><div>I hope this article helps you in understanding the basic Folder/Project architecture of the ASP.Net Core project.</div><div>Thanks</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" rel="nofollow" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-65800680000939673712021-02-26T20:46:00.000-08:002021-02-26T20:46:18.749-08:00Create your first application with ASP.NET Core 3.1<p>In this article, we will create our first ASP.NET Core application with the Visual Studio 2019 and .NET Core 3.1 version. This article is part of the ASP.NET Core series that I am going to start. In this series of articles, I will try to cover the basics as well as will create a demo application for the learning purpose.</p><p></p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmjiumwhmEemneFn9Csew6k0Knbdxxmn2-REpFM19yjtOBMBc_rirs0t-BWv6MUbt3dfdkyPq6B0T9xAcOgLdFlAZUSIibxya4z_r6xUANjgBapkEHMYWzhxPDOtfu8Duum7CWQzRe8M/s550/Cover.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmjiumwhmEemneFn9Csew6k0Knbdxxmn2-REpFM19yjtOBMBc_rirs0t-BWv6MUbt3dfdkyPq6B0T9xAcOgLdFlAZUSIibxya4z_r6xUANjgBapkEHMYWzhxPDOtfu8Duum7CWQzRe8M/s16000/Cover.png" /></a></div></div><span><a name='more'></a></span><div><div><b>What is ASP.NET Core?</b></div><div>ASP.NET Core is a framework for building modern web applications and services. It is part of .NET Core which is a cross-platform as well as an open-source framework. We said cross platforms means, we can develop and deploy the web application targeting several operating systems including Windows, Linux as well as macOS. Another feature that makes it popular are mentioned below:</div><div>1. Cross-Platform as well as Open Source.</div><div>2. Built-in support for the dependency injection (DI).</div><div>3. It also includes a built-in Web server i.e. Kestral. You can run your application directly with the Kestral or can host your application under IIS, Ngnix, Apache, etc.</div><div>4. Unified programming model for building the web as well as Web API (with the use of Controller as the base class).</div><div>5. Lightweight and high-performance modular request pipeline which is suitable for the modern cloud-based application.</div></div><div><br /></div><div><div>For creating our first ASP.NET Core application, I am using Visual Studio 2019 with .NET core 3.1 Version. </div><div><b>Let’s Begin</b>:</div><div>Open Visual Studio 2019 and click on Create a new project</div></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9IKQ5EQv-gL5ThPvTLoqyZRe2O66wpcD-KodCQA_hyphenhyphenbSsN3285Ce-DtjmxoCbLmaRqsBrz5QuoxdeBzAXMjb2pP0n-d5vEQkLq5JY6QkJpekxSK_YqpxLPOxoOKcAbs3mpI3gBbW9U3k/s550/image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9IKQ5EQv-gL5ThPvTLoqyZRe2O66wpcD-KodCQA_hyphenhyphenbSsN3285Ce-DtjmxoCbLmaRqsBrz5QuoxdeBzAXMjb2pP0n-d5vEQkLq5JY6QkJpekxSK_YqpxLPOxoOKcAbs3mpI3gBbW9U3k/s16000/image1.jpg" /></a></div></div><div>On the next screen, select ASP.NET Core Web Application and click on the Next button</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9-l5g59hCLaAhikO2oq9WUiAc8rCkDBrX-h1MTtlM9VwJOJ2_ZduUpkYSzZPYe0X887JLtBs4tYKZVBw0Q_rdCArjiFpn7pT_U168S3EE5o4V5uJgDG0LnBqu5DAhaQta_DxHPamA2eM/s550/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9-l5g59hCLaAhikO2oq9WUiAc8rCkDBrX-h1MTtlM9VwJOJ2_ZduUpkYSzZPYe0X887JLtBs4tYKZVBw0Q_rdCArjiFpn7pT_U168S3EE5o4V5uJgDG0LnBqu5DAhaQta_DxHPamA2eM/s16000/Image2.jpg" /></a></div></div>Configure your project name and the location where you want to create the application. Click on create button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQE_tFFgIK69uV_5sdM17avqSY27A-hJZ4FcGahB6jgwKmq1IMv7eYHJA6H23E7eXWTbZ94HiP7wALMpUFtqFfskrgrwBD7BBNblxAuyxEl73plx5gyLRNCx66kE8H9wHkO0Sdv2YjUZQ/s550/Image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQE_tFFgIK69uV_5sdM17avqSY27A-hJZ4FcGahB6jgwKmq1IMv7eYHJA6H23E7eXWTbZ94HiP7wALMpUFtqFfskrgrwBD7BBNblxAuyxEl73plx5gyLRNCx66kE8H9wHkO0Sdv2YjUZQ/s16000/Image3.jpg" /></a></div></div>As It’s our first application, we are trying to make it as simple as possible. Select .Net Core and ASP.NET Core 3.1 Version (as I am going to use the same version in upcoming tutorials of this series). Select the Empty template (We can create ASP.NET Core API, ASP.NET Core Application with Razor Pages, ASP.NET Core MVC, etc. application with the ASP.NET .NET Core). Unselect the configure for HTTPS checkbox as we are trying to make it as simple as possible and SSL is not required for that. Click on create button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh25JYksLcSPW0YA_xQYVQkWZZ0tSu7mtPX9AW7X3bEz_rSYl97hikPUSDsaVoAQMuqZ9QnmvoSW0QI-Ro0RAdg3BWS8DsqR6sLFEiNtkpQiezUKAvlvfmWVX2U3RBL7ev28LSNHvQLMHk/s550/image4.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="381" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh25JYksLcSPW0YA_xQYVQkWZZ0tSu7mtPX9AW7X3bEz_rSYl97hikPUSDsaVoAQMuqZ9QnmvoSW0QI-Ro0RAdg3BWS8DsqR6sLFEiNtkpQiezUKAvlvfmWVX2U3RBL7ev28LSNHvQLMHk/s16000/image4.jpg" /></a></div></div>Once the application is created you will see a screen like below.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUjtf83NyToiy95PmzqMp_XmleoTACWrgLrhqwdWBAa_BJvlM01ZJ21Og2Bow9HiEHVqdBlw2AfzvnTCmQYQ4ueBL5ZIusc6rjVQplXwUU-upULZ2Lson2EOwYukd5n78wArw1BTBHhMk/s550/Image5.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="293" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUjtf83NyToiy95PmzqMp_XmleoTACWrgLrhqwdWBAa_BJvlM01ZJ21Og2Bow9HiEHVqdBlw2AfzvnTCmQYQ4ueBL5ZIusc6rjVQplXwUU-upULZ2Lson2EOwYukd5n78wArw1BTBHhMk/s16000/Image5.jpg" /></a></div></div>Go to top navigation controls and run the Application on IIS Express as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1NujOMV4UjWbbcouP0MVBCteXuz-mMqqmNdolgSRSB2rxUeBd9tDubxJmWSCAEJZ9E6e0UHHcVFOOPd3qjWmRVgUDQVkHYWiQl-AqrlGvxdf3j5Q5brULX7ImhpJQOEoDSW7DkQaqb7Q/s550/Image6.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="231" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1NujOMV4UjWbbcouP0MVBCteXuz-mMqqmNdolgSRSB2rxUeBd9tDubxJmWSCAEJZ9E6e0UHHcVFOOPd3qjWmRVgUDQVkHYWiQl-AqrlGvxdf3j5Q5brULX7ImhpJQOEoDSW7DkQaqb7Q/s16000/Image6.jpg" /></a></div></div>On clicking on IIS Express, You will see that the application is launched in the browser with a text as Hello World on the screen.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYALXu8ZZKNYkV6bv92bIO341ZAuDE2YRSGjWnz7-CCf9A2OivPn4JUQLsjA8uQDCDW_xSLuwF7k6ZAcsGN88pXBoDuJ-vBFAtPEtsnQJBcb3uqkoLHxw9X0r1SqlIkgaYwCQuowM2vAI/s485/Image7.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="240" data-original-width="485" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYALXu8ZZKNYkV6bv92bIO341ZAuDE2YRSGjWnz7-CCf9A2OivPn4JUQLsjA8uQDCDW_xSLuwF7k6ZAcsGN88pXBoDuJ-vBFAtPEtsnQJBcb3uqkoLHxw9X0r1SqlIkgaYwCQuowM2vAI/s16000/Image7.jpg" /></a></div></div>Now you might be confused about where this “Hello World” text is coming from. In order to understand that let’s open the startup.cs file from solution explorer. I have highlighted the line in the Configure method (Configure method is called during the runtime and used to configure the HTTP request pipeline. We will see more in detail about it when we cover Middleware use in ASP.NET Core web application)<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfP3LJtX1IPXQimKyRrXpfUkLblDelX0ZdMN0gbQQKhMgy0__y-ZsGFMow4JAqlZTPiJd2lhPW_UokTQN3jJcEYKC5jrDLvR9TMCl6GglP-PHP0s4faL9NbwTSKDyIWZfvIjdfjnpSK4s/s550/Image8.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="263" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfP3LJtX1IPXQimKyRrXpfUkLblDelX0ZdMN0gbQQKhMgy0__y-ZsGFMow4JAqlZTPiJd2lhPW_UokTQN3jJcEYKC5jrDLvR9TMCl6GglP-PHP0s4faL9NbwTSKDyIWZfvIjdfjnpSK4s/s16000/Image8.jpg" /></a></div></div>Let’s change that text to something that you want to see on screen. For demonstration, I am changing it to “Hello World from IT Tutorials with Example”.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZcUuAs8Tcq6SaxAwMkLpe4ybwvUWKYFFkplkIgVdnYsiw47QNz4zgo-S7C5P4yHOxXvAPKfh0W6tZdva71wbmWkIE4gQ4mJsaGUIJJ_6UQNWyMl2I0OfMYGy5XjwyLmMet8o0xZPULTI/s550/Image9.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="244" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZcUuAs8Tcq6SaxAwMkLpe4ybwvUWKYFFkplkIgVdnYsiw47QNz4zgo-S7C5P4yHOxXvAPKfh0W6tZdva71wbmWkIE4gQ4mJsaGUIJJ_6UQNWyMl2I0OfMYGy5XjwyLmMet8o0xZPULTI/s16000/Image9.jpg" /></a></div></div>Build and run the application as we did in the above steps. The text which we changed is shown on the web browser.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR2lloesxQDVcNiKHokN9hEzidn4hjI86FxRc4ppbG3OD5DGVThh61EO8_DsAwU-e0sNUBIJ2uLGpsFnNSzT1036HFlN8L8sE3flNsEdZMxQDFzOuvc_3he6n4uGDEr1lqsktFiDZkIck/s550/Image10.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="260" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR2lloesxQDVcNiKHokN9hEzidn4hjI86FxRc4ppbG3OD5DGVThh61EO8_DsAwU-e0sNUBIJ2uLGpsFnNSzT1036HFlN8L8sE3flNsEdZMxQDFzOuvc_3he6n4uGDEr1lqsktFiDZkIck/s16000/Image10.jpg" /></a></div></div><div>Great! We have created our First Hello World Application with ASP.NET Core. In the next article, we will understand the basic file structure of the project that we have created.</div><div>I hope you like it. Thanks.</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div><div><div><div><div><div><p></p></div></div></div></div></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-74168500733817400842021-01-29T12:04:00.002-08:002021-02-13T06:31:04.822-08:00Program to check whether the entered year is Leap Year or Not<p>In this example, we will learn How to find the year entered by the user is Leap Year or not. This is one of the most common interview questions which can be asked on the fresher level interview round.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpmZgvIXJV6tSLsEOPyYqUGasQGXeX4XQYx7-CKowo_-x0gVpwoxIzwEKjgfDfNc1z7-knzggk3igqwqOKMWkh5heY3Z13TkGO5F_5YdFs37rRTTXlWYw2gkoIapAbtKEIId7AY_yL0W8/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpmZgvIXJV6tSLsEOPyYqUGasQGXeX4XQYx7-CKowo_-x0gVpwoxIzwEKjgfDfNc1z7-knzggk3igqwqOKMWkh5heY3Z13TkGO5F_5YdFs37rRTTXlWYw2gkoIapAbtKEIId7AY_yL0W8/s16000/Cover.jpg" /></a></div></div><div><br /></div>
<div class="clsImportant">
<div>I will recommend you to check the below link for Top C# Interview Programs asked during the Interview and Examination.</div><div><a href="https://www.ittutorialswithexample.com/2020/09/top-csharp-programs-for-interview.html.html" target="_blank">Top C# Program for Interview</a></div></div>
<p><b><br /></b></p><p><b>Let’s Begin:</b></p><p>In order to find the year entered by the user is Leap year or not, we have to check first that the year entered by the user is evenly divisible by 4. If the year is evenly divisible by 4 as well as evenly divisible by 100 then the year entered by the user is not a Leap year. In case if it's not evenly divisible by 100 then it is an example of Leap year. In case, If the year is evenly divisible by 400 then this is an example of the Leap year.</p><div><b>Program</b>:</div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter
the year to check whether year entered is Leap year or not?"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Recieve input year from the user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> yearValue =
Convert.ToInt32(Console.ReadLine());<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//If year is evenly divisible by 4 as well and not divisible by
100 then year is leap year</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//If year is evenly divisible by 400 then year is leap year</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Else not a Leap Year</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> ((yearValue % 4 == 0 &&
yearValue % 100 != 0) || (yearValue % 400 == 0))<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"{0} is a Leap Year"</span><span style="font-family: Consolas; font-size: 9.5pt;">,
yearValue);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"{0} is not a Leap Year"</span><span style="font-family: Consolas; font-size: 9.5pt;">, yearValue);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Using Console.ReadLine() in order to hold the terminal/command
prompt</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.ReadLine();</span><o:p></o:p></p>
</td>
</tr>
</tbody></table><p><b>Preview</b>:</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWW5Wvv2BhGcxC2RR2mHrFD9gdrzi0akzV6wZNefWLLdFMhQIYLd75791mP0tgx1xr8wVliB379AIlJK3KAVyFr6dajEIrzzFQyRwFVQVVQJXaA0fUAWEa2300QqnEuz-spvUubEu0Y64/s548/image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="116" data-original-width="548" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWW5Wvv2BhGcxC2RR2mHrFD9gdrzi0akzV6wZNefWLLdFMhQIYLd75791mP0tgx1xr8wVliB379AIlJK3KAVyFr6dajEIrzzFQyRwFVQVVQJXaA0fUAWEa2300QqnEuz-spvUubEu0Y64/s16000/image1.jpg" /></a></div></div><div class="separator" style="clear: both; text-align: center;"><br /></div><br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaDCDxamIBEPHJ2FAtWjGYx8CsClP7GHNc9DtCgmW5veHtdQckn3a3Xb_MKs8CKEyJre1lQ4TS8tO-vb9pl5ICpmdnig8fGpC6vZ7H9ZzRIGrJNS6bVA7bw5_G59pTB5M8FRpnBI9QjZI/s550/image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="105" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaDCDxamIBEPHJ2FAtWjGYx8CsClP7GHNc9DtCgmW5veHtdQckn3a3Xb_MKs8CKEyJre1lQ4TS8tO-vb9pl5ICpmdnig8fGpC6vZ7H9ZzRIGrJNS6bVA7bw5_G59pTB5M8FRpnBI9QjZI/s16000/image2.jpg" /></a></div></div>
<div class="separator" style="clear: both; text-align: center;"><br /></div><br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiNfvbT3gN5OcUOocL3e92snYiYSVlt732yIFv8yGkt8Z_lTM5lPFrg8PRNMCI2RxSey5ikJbUY4FychPfWbLryfmeR4zsNUKnFYB1jTX8fR8EaKMo65HPeSnVZIkr4eNgzKwfKVe7_GQ/s550/image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="91" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgiNfvbT3gN5OcUOocL3e92snYiYSVlt732yIFv8yGkt8Z_lTM5lPFrg8PRNMCI2RxSey5ikJbUY4FychPfWbLryfmeR4zsNUKnFYB1jTX8fR8EaKMo65HPeSnVZIkr4eNgzKwfKVe7_GQ/s16000/image3.jpg" /></a></div></div><div>I hope this example will help you in your interview/exam preparation.</div><div>Thanks</div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-47133610398088482422021-01-23T22:04:00.000-08:002021-01-23T22:04:13.757-08:00Program to Count Vowels and Consonants in a string<p>One of the popular programs which can be asked by the interviewer during the interview is to count no. of Vowels and Consonants in a string. The letters A, E, I, O, and U are called Vowels and the other letters (except vowels) in the alphabet are known as Consonants.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQv1lmwYHqy1TQbIzNRdJoaO3NiRynSEmeIkUuUHl0-cotT7twG63P-rrpJbc4kaZ8WGr6OYYj8AJPBdR0mPNSobvU9qCRkIHSVh1wVPVMcnFe9q9y8T3efkVDdWikm89mK208NjraROY/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQv1lmwYHqy1TQbIzNRdJoaO3NiRynSEmeIkUuUHl0-cotT7twG63P-rrpJbc4kaZ8WGr6OYYj8AJPBdR0mPNSobvU9qCRkIHSVh1wVPVMcnFe9q9y8T3efkVDdWikm89mK208NjraROY/s16000/Cover.jpg" /></a></div></div><span><a name='more'></a></span><div>
<div class="clsImportant">I will recommend you to check the below link for Top C# Interview Programs asked during the Interview and Examination.
<div><a href="https://www.ittutorialswithexample.com/2020/09/top-csharp-programs-for-interview.html.html" target="_blank">Top C# Program for Interview</a></div>
</div>
</div><div><br /></div><div>In the below example, User will input the string which will be converted to lowercase so that comparison can be done without worrying about Upper-case or Lower-case characters. Then looping through each character of the string and check whether the character is in ‘a’, ’e’, ’I’, ’o’, and ‘u’. If yes, then increase the vowel counter value by 1. If the entered alphabet is between a to z but not in Vowels then need to increase Consonants variable value by 1. </div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf9Yy_5udKq4CdUjRWM-B2BBp7ARZXgkaAk1dD4JVhWr2CQ8WCHWLDtCE-birJilU-T0ZgYb0sVQGjmavRc3XxKRzpZ0Xy1V2YuPCdMa78HYCTmAsGvBe4Uk9xyAW8enAARKD07zNRFls/s549/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="509" data-original-width="549" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf9Yy_5udKq4CdUjRWM-B2BBp7ARZXgkaAk1dD4JVhWr2CQ8WCHWLDtCE-birJilU-T0ZgYb0sVQGjmavRc3XxKRzpZ0Xy1V2YuPCdMa78HYCTmAsGvBe4Uk9xyAW8enAARKD07zNRFls/s16000/Image1.jpg" /></a></div></div><div><b>Program in C#</b>:</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Count
no. of Vowels and Consonants in a string"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Variables to hold the Vowels and Consonants count</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> vCount = 0;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> cCount = 0;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> inputString = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;">.Empty;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Recieve the input from the user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">inputString = Console.ReadLine();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Lower the characters of the string for the comparision</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">inputString = inputString.ToLower();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Loop through the each character of the string</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">for</span><span style="font-family: Consolas; font-size: 9.5pt;"> (</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> i = 0; i < inputString.Length; i++)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> //check and increase
the counter if character is vowel</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (inputString[i]==</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">'a'</span><span style="font-family: Consolas; font-size: 9.5pt;"> || inputString[i]==</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">'e'</span><span style="font-family: Consolas; font-size: 9.5pt;"> || inputString[i] == </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">'i'</span><span style="font-family: Consolas; font-size: 9.5pt;"> || inputString[i] == </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">'o'</span><span style="font-family: Consolas; font-size: 9.5pt;"> || inputString[i] == </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">'u'</span><span style="font-family: Consolas; font-size: 9.5pt;">)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> vCount++;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//check and increase the counter if character is consonant</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (inputString[i]>=</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">'a'</span><span style="font-family: Consolas; font-size: 9.5pt;"> && inputString[i] <= </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">'z'</span><span style="font-family: Consolas; font-size: 9.5pt;">)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> cCount++;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Showing the Vowels and Constants count in a string to the user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Total
no. of Vowels in a string="</span><span style="font-family: Consolas; font-size: 9.5pt;"> + vCount);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Total
no. of Constants in a string="</span><span style="font-family: Consolas; font-size: 9.5pt;"> + cCount);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.ReadLine();</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div><b>Preview</b>:
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjejP2D9NS7t-V_NI4RvdPIJYl10TpiJYzTgvjfrQ_IAI_i89Fpzh-cggJbhYTSIEk2WXgt8c3anviEQ_gIyNTmMRA29ukQuOyRSU0bcrTWxMVhHgcaYbaKu4v_NaLvMo_Zj6VlDeM_xNU/s410/image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="146" data-original-width="410" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjejP2D9NS7t-V_NI4RvdPIJYl10TpiJYzTgvjfrQ_IAI_i89Fpzh-cggJbhYTSIEk2WXgt8c3anviEQ_gIyNTmMRA29ukQuOyRSU0bcrTWxMVhHgcaYbaKu4v_NaLvMo_Zj6VlDeM_xNU/s16000/image2.jpg" /></a></div></div><div>I hope this will help you in your interview preparation.</div><div>Thanks</div><div><br /></div><div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-43078466881270277052020-12-11T08:40:00.001-08:002020-12-11T08:40:50.305-08:00Getting Started with MongoDB Atlas - Part 2<p>This is the continuation of <a href="https://www.ittutorialswithexample.com/2020/12/getting-started-with-mongodb-atlas-part-1.html" target="_blank">Getting Started with MongoDB Atlas - Part 1</a>. Our Dataset is ready. Now let’s create a .Net Core Console App through which we will try to access one of the collections in the MongoDB Atlas cluster. </p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoPKuRe86trbm7VPmUey6Hu8iWgvs7_8MPZphjZVIN_0bwKUFM7kpprOHNGvhojzYVHQS_IN-BufW9iwDX9jmvICzplZyw14kii1BliJfoLcZCdNikdqcGSea_jUHNInGDeWuifJPR9qc/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoPKuRe86trbm7VPmUey6Hu8iWgvs7_8MPZphjZVIN_0bwKUFM7kpprOHNGvhojzYVHQS_IN-BufW9iwDX9jmvICzplZyw14kii1BliJfoLcZCdNikdqcGSea_jUHNInGDeWuifJPR9qc/s16000/Cover.jpg" /></a></div></div><span><a name='more'></a></span><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8UEyTK1x78F9L-yTGNSrk3aIiByIOHAm-1UoXCcwuyz1qVlWNAnf0CmGV68FXJUU8n3W-67EjgxSidHSXCbyc8TT49_EAMpz0Mkrql4UWjsmDHilGRg1OpZjXJiRoeKecqqG2bzPUcx0/s550/Image25.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8UEyTK1x78F9L-yTGNSrk3aIiByIOHAm-1UoXCcwuyz1qVlWNAnf0CmGV68FXJUU8n3W-67EjgxSidHSXCbyc8TT49_EAMpz0Mkrql4UWjsmDHilGRg1OpZjXJiRoeKecqqG2bzPUcx0/s16000/Image25.jpg" /></a></div></div>Give a name to your .Net Core project. Click on the Create button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyYgLQl2ZXaFquPOcnUAbHSg0YEXiar2JnP_-G7R05fKwh4hXNog4MlEL7Tv4-Mk4HWzO0xNA6Ug1gGkcu92cdZyyY7CQVDrkbRcwoL5g6EpisuVvCXqJ41WvBI4qrlLMZEIsWB5dhTUQ/s550/Image26.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="365" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyYgLQl2ZXaFquPOcnUAbHSg0YEXiar2JnP_-G7R05fKwh4hXNog4MlEL7Tv4-Mk4HWzO0xNA6Ug1gGkcu92cdZyyY7CQVDrkbRcwoL5g6EpisuVvCXqJ41WvBI4qrlLMZEIsWB5dhTUQ/s16000/Image26.jpg" /></a></div></div>Once the solution is ready, right-click on the project’s dependencies and select Manage NuGet Packages.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOmerDmjKNQwGwWGmDYdnMwQWu8SbsXyhf2F1PQxo9qArC59ysOF2Rv0x0owHEI2BAJ8jNqJyu4Yfy5vAYCBou_5IOmQg1E9XG0DKnb1_255KaKGONOmk-Av2_bU1sEC9FTUuJMtD3V8U/s374/Image27.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="374" data-original-width="372" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOmerDmjKNQwGwWGmDYdnMwQWu8SbsXyhf2F1PQxo9qArC59ysOF2Rv0x0owHEI2BAJ8jNqJyu4Yfy5vAYCBou_5IOmQg1E9XG0DKnb1_255KaKGONOmk-Av2_bU1sEC9FTUuJMtD3V8U/s16000/Image27.jpg" /></a></div></div>Now install MongoDB Driver from NuGet package manager as shown in the below image. Click on the Install button, in order to install the package.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQZ1AmkqpIrpEfvnmEOiHp2H6lao-R1GI3nNttT3bZcECqxlzpTnoFuzDpj3mQXMpGzZn8ouvoJ6oHDzX5NVStiHFnsdsyIyKQoEKdHCewJ5DXeEEjN_AiYnli-snow6qz7887_GSNf0g/s550/Image28.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="251" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQZ1AmkqpIrpEfvnmEOiHp2H6lao-R1GI3nNttT3bZcECqxlzpTnoFuzDpj3mQXMpGzZn8ouvoJ6oHDzX5NVStiHFnsdsyIyKQoEKdHCewJ5DXeEEjN_AiYnli-snow6qz7887_GSNf0g/s16000/Image28.jpg" /></a></div></div>In order to connect C# .Net Core Application with the MongoDB Atlas’s Cluster, we need a connection string. Click on the connect button of the Cluster created.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGKY40o3XGNIPVloRwJhujYDe9x5-tUcNI1kOxPzpXfVFL_VX_EgFUc2AyWIctcu5vB8NPEfagZo3vkaKrLZTI02ei2T7xu_PuBEoEVA_NVP4aWNtep_tvHKSmbh4i76nKVuS1RZHlOHc/s550/Image29.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="287" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGKY40o3XGNIPVloRwJhujYDe9x5-tUcNI1kOxPzpXfVFL_VX_EgFUc2AyWIctcu5vB8NPEfagZo3vkaKrLZTI02ei2T7xu_PuBEoEVA_NVP4aWNtep_tvHKSmbh4i76nKVuS1RZHlOHc/s16000/Image29.jpg" /></a></div></div>A popup will appear from where we have to choose a connection method. Click on the Connect your application link as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNH_BK9FEluxrFWuimssACgKeUOW2iA9j0DEAOohCKP8U7_WjxSLBC4O5thfqCiIpnlhZ2lCzQltjmYWyw1Ch0X1UNwqMaJm-s6_A7p8YKmUqtXq4UWqCRDn16IsaSsNS5lXhfngI1gtU/s550/Image30.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="478" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNH_BK9FEluxrFWuimssACgKeUOW2iA9j0DEAOohCKP8U7_WjxSLBC4O5thfqCiIpnlhZ2lCzQltjmYWyw1Ch0X1UNwqMaJm-s6_A7p8YKmUqtXq4UWqCRDn16IsaSsNS5lXhfngI1gtU/s16000/Image30.jpg" /></a></div></div>Select Driver and the Version of the Driver (installed through NuGet package manager) which we are using to connect with MongoDB through the C# .Net Core console application. Click on the copy button in order to copy the connection string. Change <password> to the password added for the database user and <dbname> to the database name with which you want to connect.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5jRW7tgP75vAZZvC4rm6JilwJCj8EHpdOUs7z-COIvCadQnHoUVazSW3PnU6734MFj2VghwSEvtqbBwlpNAK8G-BPE5lNcow-Pds0kWihQrShep1S8_Ztng3PbaWDq9ndcdzehf49vls/s550/Image31.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="480" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5jRW7tgP75vAZZvC4rm6JilwJCj8EHpdOUs7z-COIvCadQnHoUVazSW3PnU6734MFj2VghwSEvtqbBwlpNAK8G-BPE5lNcow-Pds0kWihQrShep1S8_Ztng3PbaWDq9ndcdzehf49vls/s16000/Image31.jpg" /></a></div></div>There are multiple databases in the Sample Dataset loaded. We will use the sample_mflix database in the connection string.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsipVLsGMiuD2NtDYT-JgSoJ8ftd1opgz3UQ8S3tjauTDA3wYitHYLvW6gyfqFlZVEndWkXfazq-ypG7kcc8RJCkcdLHudJ3B-VNGVqqAt5TimbrTSCWjy0zd4ddYWIGdk_i9AZNJnMUA/s444/Image32.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="444" data-original-width="286" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsipVLsGMiuD2NtDYT-JgSoJ8ftd1opgz3UQ8S3tjauTDA3wYitHYLvW6gyfqFlZVEndWkXfazq-ypG7kcc8RJCkcdLHudJ3B-VNGVqqAt5TimbrTSCWjy0zd4ddYWIGdk_i9AZNJnMUA/s16000/Image32.jpg" /></a></div></div>Now add the below C# Code in the main method of the .Net Core Console Application.<div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Passing the connection string in MongoClient</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> client = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> MongoClient(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"mongodb+srv://TestUser:PASSWORD@cluster0.maoqh.mongodb.net/sample?retryWrites=true&w=majority"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Get sample_mflix Database</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> db = client.GetDatabase(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"sample_mflix"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Get movies collection</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> collection =
db.GetCollection<BsonDocument>(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"movies"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Find document with title Peter Pan</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> result=collection.Find(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"{title:'Peter Pan'}"</span><span style="font-family: Consolas; font-size: 9.5pt;">).FirstOrDefault();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(result);</span><o:p></o:p></p>
</td>
</tr>
</tbody></table><div><b>Preview</b>:<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilZYMSkXxCGduj5APG2W3_YWMUadHrFkvZC9sVVIUWSxN63TlMHegBo4Si-JrrRsNEEiUF4hJjiRsuCbn6Tg1ZxqDHIln_1CE9acdiheM88dXJje9y3FFsJndOMK5_7sAzkJ08kIXQRNQ/s550/Image33.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="288" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilZYMSkXxCGduj5APG2W3_YWMUadHrFkvZC9sVVIUWSxN63TlMHegBo4Si-JrrRsNEEiUF4hJjiRsuCbn6Tg1ZxqDHIln_1CE9acdiheM88dXJje9y3FFsJndOMK5_7sAzkJ08kIXQRNQ/s16000/Image33.jpg" /></a></div></div><div>On running the application, a document with Title “Peter Pan” will be printed on the console.</div><div>I hope this will help you in getting started with MongoDB Atlas.</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div><div><div><div><div><div><span><!--more--></span><span><!--more--></span><span><!--more--></span></div></div></div></div></div></div></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-87487829045853807622020-12-11T08:04:00.000-08:002020-12-11T08:04:27.936-08:00Getting Started with MongoDB Atlas - Part 1<p>In this article, we will learn How to get started with MongoDB Atlas. MongoDB Atlas is the global cloud database service for the modern application. MongoDB Atlas is the best way to deploy, run, and scale MongoDB In the Cloud.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpxzEYvCJQBLZP6-V7gCcz6nw8389sP28L2RrABvq8xsaD-p9Z77UMl3aNn6-yE-aZVBaTj9HbkIdp4qIrF2Oo9jyxcvjZaCdVRvCbEUWzxw0XBtzPkh0cZQMaSWBPMRfrB3pSAlN7M10/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpxzEYvCJQBLZP6-V7gCcz6nw8389sP28L2RrABvq8xsaD-p9Z77UMl3aNn6-yE-aZVBaTj9HbkIdp4qIrF2Oo9jyxcvjZaCdVRvCbEUWzxw0XBtzPkh0cZQMaSWBPMRfrB3pSAlN7M10/s16000/Cover.jpg" /></a></div></div><span><a name='more'></a></span><div><div><b>Let’s Begin</b>:</div><div>First of all, visit <a href="https://www.mongodb.com/cloud/atlas" target="_blank">https://www.mongodb.com/cloud/atlas</a> URL in order to Signup for the MongoDB Atlas Account.</div></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitLBQ6sIBYqb_HRwhUQhGtnJgauDk6tYgEU0s2CtvyB-aIb4FhXL_1ELDePcFiELQdd-zokWqNsarake_raApC7ZgnhsExc27yC3e4xfkAS7vpZaHiNiv0JWVwgLYWqzaqXxuuJaREgKc/s550/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="279" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitLBQ6sIBYqb_HRwhUQhGtnJgauDk6tYgEU0s2CtvyB-aIb4FhXL_1ELDePcFiELQdd-zokWqNsarake_raApC7ZgnhsExc27yC3e4xfkAS7vpZaHiNiv0JWVwgLYWqzaqXxuuJaREgKc/s16000/Image1.jpg" /></a></div></div><div><br /></div><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0IhZzYp_AqGEZ0LIRnHD1ws2YFR0SzU7QnJ2ywML-aouaqbhdG4GlrUYjyZWiOHep29U7UUcACyn23cMb6irmZKjqSGkcQ_nWdqUqBGbrba61eq4F1oWqFK8OG4knRGmJ2Wfn2wNcCiM/s550/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="312" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0IhZzYp_AqGEZ0LIRnHD1ws2YFR0SzU7QnJ2ywML-aouaqbhdG4GlrUYjyZWiOHep29U7UUcACyn23cMb6irmZKjqSGkcQ_nWdqUqBGbrba61eq4F1oWqFK8OG4knRGmJ2Wfn2wNcCiM/s16000/Image2.jpg" /></a></div></div>The next step is to Add Organization. Within the organization, we can create projects, invite users, and can set up a billing account as well.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtPT55KuwYsXL4Pj3PbyNzzhhMETDZhRIFNw6FnTuHR8lMFRhM3qqRCtrJ5xFXptsTenUTkL-Zp2Ami6O4QMb5JOOTu6CzmyiB5xaMDp_9BbMxPPhDk5eeVxnfIkioE0pVEfju5uQIZYQ/s550/Image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="290" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtPT55KuwYsXL4Pj3PbyNzzhhMETDZhRIFNw6FnTuHR8lMFRhM3qqRCtrJ5xFXptsTenUTkL-Zp2Ami6O4QMb5JOOTu6CzmyiB5xaMDp_9BbMxPPhDk5eeVxnfIkioE0pVEfju5uQIZYQ/s16000/Image3.jpg" /></a></div></div>Give a name to your organization and select the MongoDB Atlas as a Cloud Service. Click on Next.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipgvS6AMglwgoHbgKXsNWHREMuZQJofawP_KuefwQrOjKDFbsE0HlGkgupMUkCDKKpyzMZJn8e8rH5yFZ-lGs4-8Ke6vEXlLBrypbSYCgysWX43PnS_W1gJctg8u-hztM-kyc3IcD4bWg/s550/Image4.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="315" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipgvS6AMglwgoHbgKXsNWHREMuZQJofawP_KuefwQrOjKDFbsE0HlGkgupMUkCDKKpyzMZJn8e8rH5yFZ-lGs4-8Ke6vEXlLBrypbSYCgysWX43PnS_W1gJctg8u-hztM-kyc3IcD4bWg/s16000/Image4.jpg" /></a></div></div>Click on the create organization button in order to create an organization.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf5MqqNmG-0W1ht-kqmzxZv033cso5Q_Q5UB-1hEd8gEoYE0tOQhoZRfuAA1LrEpKf6dyfErgfUuP_e2KnRNSdyHIJNdARXPaXznrgcZXoDRCJr8TOOfF9gUwm5JVG0rMLNvXwoltdWno/s550/Image5.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="249" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf5MqqNmG-0W1ht-kqmzxZv033cso5Q_Q5UB-1hEd8gEoYE0tOQhoZRfuAA1LrEpKf6dyfErgfUuP_e2KnRNSdyHIJNdARXPaXznrgcZXoDRCJr8TOOfF9gUwm5JVG0rMLNvXwoltdWno/s16000/Image5.jpg" /></a></div></div>Click on the New Project button in order to add the project to the Organization.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj4Xd9COhMC2vbTydAAJnfrptBl17OaSnlyg6nezg_m_P5Ng_g7A6PeDrqiiPwnK1Z0GdlAoF9dzJHh-azyHdJwR6ZRdB8DO91ZIH0hBHqPHgdtiJbHdVNrnVtL1U6gvuELsvp-kMF__A/s550/Image6.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="231" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj4Xd9COhMC2vbTydAAJnfrptBl17OaSnlyg6nezg_m_P5Ng_g7A6PeDrqiiPwnK1Z0GdlAoF9dzJHh-azyHdJwR6ZRdB8DO91ZIH0hBHqPHgdtiJbHdVNrnVtL1U6gvuELsvp-kMF__A/s16000/Image6.jpg" /></a></div></div>Provide a Name to your Project. The project name must be unique within an organization. Click on the Next button.<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkDK7uxtwfMAWl78VdijdgSlKsTJefgOsAy84slcrEOly1rD8ufIvXZ7CBgeJYHDIM015KuYijnWVBkuxiwYlISPngP86alJQlb3Uy2W-3GagzruHvwgCXQV85MfeMefIZVOski8YjdDM/s550/Image7.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="284" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkDK7uxtwfMAWl78VdijdgSlKsTJefgOsAy84slcrEOly1rD8ufIvXZ7CBgeJYHDIM015KuYijnWVBkuxiwYlISPngP86alJQlb3Uy2W-3GagzruHvwgCXQV85MfeMefIZVOski8YjdDM/s16000/Image7.jpg" /></a></div></div>Click on Create Project in order to add the Project to the organization.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3uWkun7Rm8PiHfiViHNaEFMA6uOLhVzGEOZ4WGDQBk01E9NqpzWKQ_mG_yVMbRPWWS5z10Ibq3gn7qFVqKjheyHePTXfbGR3-GWHIPYXHDNIGbLQNlqO9M-oWObKBlq_DZ3G4S0k3gfM/s550/Image8.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="271" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3uWkun7Rm8PiHfiViHNaEFMA6uOLhVzGEOZ4WGDQBk01E9NqpzWKQ_mG_yVMbRPWWS5z10Ibq3gn7qFVqKjheyHePTXfbGR3-GWHIPYXHDNIGbLQNlqO9M-oWObKBlq_DZ3G4S0k3gfM/s16000/Image8.jpg" /></a></div></div>The next step is to Add a Cluster to the Project. Click on Build a Cluster in order to create a Cluster.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ_KkyWEEBwWhd1iRRZyBoIESC72Uo-Rt_C89C4DdjCfy04g6CNcx_lnqryihwtsaHQbaqxTP9dsfoL6CD_IWNil8w_-CGHrqIaGM1dGyB_6HRI50BIRwoJoZw9HTx31YkjP8Ohy7nGFo/s550/Image9.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJ_KkyWEEBwWhd1iRRZyBoIESC72Uo-Rt_C89C4DdjCfy04g6CNcx_lnqryihwtsaHQbaqxTP9dsfoL6CD_IWNil8w_-CGHrqIaGM1dGyB_6HRI50BIRwoJoZw9HTx31YkjP8Ohy7nGFo/s16000/Image9.jpg" /></a></div></div>Select the Cluster as per your requirement. I am choosing a shared cluster as I am using it for demonstration purposes.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJirdze17BOoND2WlFr2NeGol_ougXgCQeV8omeXi6CBxwCDMmy9ZR7vrGnEHariTZRmd5R5UqxCic-Vz0dC43IOM5jCpjp7yV10LFzSC0vI1MnD0Lie6t1dPHkojIe1Av9bPbdbbZtfg/s550/Image10.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="265" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJirdze17BOoND2WlFr2NeGol_ougXgCQeV8omeXi6CBxwCDMmy9ZR7vrGnEHariTZRmd5R5UqxCic-Vz0dC43IOM5jCpjp7yV10LFzSC0vI1MnD0Lie6t1dPHkojIe1Av9bPbdbbZtfg/s16000/Image10.jpg" /></a></div></div>Shared Cluster is for Team learning MongoDB or developing small applications. Click on the Create a Cluster button as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh41XF-rH8b1XYn-scYpqUOrn5adlxtAKUdvsMr_3iv4L3uI_C3NGVyDfARpDYh4Z5Z_qiEzFf7Om4m3HFJWBbAf6VxhDCGrqt6_yuuKJth9MVNlgETtHvP8crvhcT6D_P5CFpZsLfHqtE/s610/Image11.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="610" data-original-width="279" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh41XF-rH8b1XYn-scYpqUOrn5adlxtAKUdvsMr_3iv4L3uI_C3NGVyDfARpDYh4Z5Z_qiEzFf7Om4m3HFJWBbAf6VxhDCGrqt6_yuuKJth9MVNlgETtHvP8crvhcT6D_P5CFpZsLfHqtE/s16000/Image11.jpg" /></a></div></div>Select a starter Cluster in Shared Cluster. Pick the Cloud Provider and Region where you want to create a Cluster. Click on the create Cluster button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVHA1EA2CVzMqf_SlXFit5uWnnjQDVS_nB6YL6HX6v3LFufeJ343D_Zgz628JS2XKaMWuAAFWEL8WmWAeyu8xznRQHaix3VU3zGLszTxqLGfo_9lJa1ly7-cGsr2VVmr7SV2JRfmr8XQk/s550/Image12.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="379" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVHA1EA2CVzMqf_SlXFit5uWnnjQDVS_nB6YL6HX6v3LFufeJ343D_Zgz628JS2XKaMWuAAFWEL8WmWAeyu8xznRQHaix3VU3zGLszTxqLGfo_9lJa1ly7-cGsr2VVmr7SV2JRfmr8XQk/s16000/Image12.jpg" /></a></div></div>It will take around 3 minutes to set up a cluster in the cloud. You can also add another cluster by clicking on the Add a new Cluster button (if needed).
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkqROFO6iWGvN8k_7avkVDeejViKm6VS9JBYG9VZDm4BqQddY1fSiHPzYPpTm49LQidWkOI4nyr7U6OhBeJA8_lCQBA8zaEO_lIZk63MbReTui8itHdeD9K4COO9mb8ffeWjWytQ2uD7o/s550/Image13.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="279" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkqROFO6iWGvN8k_7avkVDeejViKm6VS9JBYG9VZDm4BqQddY1fSiHPzYPpTm49LQidWkOI4nyr7U6OhBeJA8_lCQBA8zaEO_lIZk63MbReTui8itHdeD9K4COO9mb8ffeWjWytQ2uD7o/s16000/Image13.jpg" /></a></div></div>Once the cluster is ready, Connect, Metrics, and Collections button will be enabled.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0RL7nixUaPyOffblHaiv_aU4cm_QJOKcFu-c6QHh6l6emFlJcNIRGkWgkGmJTNJKvxRr0LNuOC_A3-LBcirTS2W4pGBec59wh3eV_set-oeO2B1IcfjmbiIWFn2rb5Q5BOk0JFoN6syw/s550/Image14.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="265" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0RL7nixUaPyOffblHaiv_aU4cm_QJOKcFu-c6QHh6l6emFlJcNIRGkWgkGmJTNJKvxRr0LNuOC_A3-LBcirTS2W4pGBec59wh3eV_set-oeO2B1IcfjmbiIWFn2rb5Q5BOk0JFoN6syw/s16000/Image14.jpg" /></a></div></div>Click on the Network Access menu and then Add click on the IP Address button as Atlas only allows client connections to a cluster from entries in a Project’s IP Address list.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAmaCXGYivABrd4mIKQpINeuAEoeuO4rZHPIpIfKJssr-M1xt3E1xf7-dTnCy2hgEeQ_UYNtmPKCO0j9RoGvSwYVElmCigj7EPosSzmHtUq3Rs8_OsPBY-vFuHsvkigA31B15a-PoIIHk/s550/Image15.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="299" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAmaCXGYivABrd4mIKQpINeuAEoeuO4rZHPIpIfKJssr-M1xt3E1xf7-dTnCy2hgEeQ_UYNtmPKCO0j9RoGvSwYVElmCigj7EPosSzmHtUq3Rs8_OsPBY-vFuHsvkigA31B15a-PoIIHk/s16000/Image15.jpg" /></a></div></div>For Demonstration, I am allowing Access from Anywhere in the IP Address Access List (as we will access the same cluster through .Net Core Application. Click on Confirm in order to proceed.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEii7LTOj4jmSJhIpxmY6fyEoMzgSqwAIWGhjs63QITMUgOdUPg0OD-gbt_f3QV-Y07N45wfQqzztXzGYV08VoFQ0ORKeHDLl4xf6_wLv7rW6tOdEw1XqdL01z4XbEtpn_ro73AlCrfS5iw/s550/Image16.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="325" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEii7LTOj4jmSJhIpxmY6fyEoMzgSqwAIWGhjs63QITMUgOdUPg0OD-gbt_f3QV-Y07N45wfQqzztXzGYV08VoFQ0ORKeHDLl4xf6_wLv7rW6tOdEw1XqdL01z4XbEtpn_ro73AlCrfS5iw/s16000/Image16.jpg" /></a></div></div>Once added, you can see the whitelist IP Address in the grid. You can edit or delete any allowed IP Address at any time.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr9F9uyEqhmQ56R__xvw8qyJsFJZlCEwopTJNkZ7YoE02wrHkxAp_kPQPkErmn-3fJ9ttJ73S9JbMYjQjGiTiXGErX3bMyIczjkgEjN-FSzfGgMXITu8vx5bLyflNBr6ModOl1r0eN5uk/s550/Image17.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="167" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr9F9uyEqhmQ56R__xvw8qyJsFJZlCEwopTJNkZ7YoE02wrHkxAp_kPQPkErmn-3fJ9ttJ73S9JbMYjQjGiTiXGErX3bMyIczjkgEjN-FSzfGgMXITu8vx5bLyflNBr6ModOl1r0eN5uk/s16000/Image17.jpg" /></a></div></div>Now click on the Database access menu in order to create a Database user, setup permission, and authentication credentials to connect with a cluster. Click on Add new database user.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-m7sFVjXKGFdyawhawuJ3t5iE6w2hvoSa86_BpwWjg9KmeR5v56V3B7aMFvQ44inZcvfm4z3ayMrSWXNVN_Vkm_65wHZUU_gMkcxj9zIK010gi6fhv2h0GGFDPmrFZAWgfxVWc2rKjIk/s550/Image18.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="287" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-m7sFVjXKGFdyawhawuJ3t5iE6w2hvoSa86_BpwWjg9KmeR5v56V3B7aMFvQ44inZcvfm4z3ayMrSWXNVN_Vkm_65wHZUU_gMkcxj9zIK010gi6fhv2h0GGFDPmrFZAWgfxVWc2rKjIk/s16000/Image18.jpg" /></a></div></div>Select Password as the Authentication method, type or auto-generate secure password, give read and write to any database. Click on Add user.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWOXitILFM-PVV8A8usTZD1DW0CKrx-DCo-yiT_ic4n2u6InOWlxbw7UT_S0q2wK27wF0LzrMuLkr6l_Q0m8D2YEA8O6qqZO6NiIdoC8AtFdWNaxxNY71v3_XtKjofrQadzKYETWQemeA/s550/Image19.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="485" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWOXitILFM-PVV8A8usTZD1DW0CKrx-DCo-yiT_ic4n2u6InOWlxbw7UT_S0q2wK27wF0LzrMuLkr6l_Q0m8D2YEA8O6qqZO6NiIdoC8AtFdWNaxxNY71v3_XtKjofrQadzKYETWQemeA/s16000/Image19.jpg" /></a></div></div><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf9K_Ni7PFRxaBSrTyz0rgPeF_6ShjWsnWR5n5-ZeK36pWGFEOBUclmgeZHcx2em_mhAhFk5FtwuqGcRsnK1JhHAuzGW4YPxO3Dto53JGP9iPHVWFrj2LHl6ut2joM5t9VQgsjCxkrLkI/s550/Image20.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="370" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf9K_Ni7PFRxaBSrTyz0rgPeF_6ShjWsnWR5n5-ZeK36pWGFEOBUclmgeZHcx2em_mhAhFk5FtwuqGcRsnK1JhHAuzGW4YPxO3Dto53JGP9iPHVWFrj2LHl6ut2joM5t9VQgsjCxkrLkI/s16000/Image20.jpg" /></a></div></div>All of the added users visible in the grid in the Database user tab.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmpAEFTS9_YScvL7CFOH-v4MqQaynIwgdau6Rf7tcZS88wR2X4vlsF7Ws1U3gjfPslvIxk_EgZGzXbeqGIqucE6L6LgQmFVG_saHxlHEcFZbkvZhm8gQ43BKmnc2z7q_X8-rwKDMLykkk/s550/Image21.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="183" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmpAEFTS9_YScvL7CFOH-v4MqQaynIwgdau6Rf7tcZS88wR2X4vlsF7Ws1U3gjfPslvIxk_EgZGzXbeqGIqucE6L6LgQmFVG_saHxlHEcFZbkvZhm8gQ43BKmnc2z7q_X8-rwKDMLykkk/s16000/Image21.jpg" /></a></div></div>Click on three dots (options) in Sandbox Cluster, Click on Load Sample Dataset. A sample dataset which is of around 350 MB in size will be loaded in the cluster.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMMh7esDFKqPNaGp0WEIbA5Dctfgp28dXoLkswl1lSM_Qt5bTu0zaLB4X9dkaBdKqqcrYENC-2XBHHO-XcFhCm1nzUR54Yev-wH6zHUiSIVXgTbR_bxOpNMTvoZAZqoBmLFNTOs-SQp6A/s550/Image22.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="454" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMMh7esDFKqPNaGp0WEIbA5Dctfgp28dXoLkswl1lSM_Qt5bTu0zaLB4X9dkaBdKqqcrYENC-2XBHHO-XcFhCm1nzUR54Yev-wH6zHUiSIVXgTbR_bxOpNMTvoZAZqoBmLFNTOs-SQp6A/s16000/Image22.jpg" /></a></div></div><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9Yz5iUxuCIHeEnOl9NNjwCRBzp23TQyYIEbf5SMaRoKb0ghblizm8jX9D-vR8gKD_n1y-X4UQTymPW_UnXcwqcR3c9vWkRa9YPVQAXtsOUTjF83LAHY163BXnnEnBbaBSIoAl_sFZLbI/s550/Image23.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="327" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9Yz5iUxuCIHeEnOl9NNjwCRBzp23TQyYIEbf5SMaRoKb0ghblizm8jX9D-vR8gKD_n1y-X4UQTymPW_UnXcwqcR3c9vWkRa9YPVQAXtsOUTjF83LAHY163BXnnEnBbaBSIoAl_sFZLbI/s16000/Image23.jpg" /></a></div></div>Sample dataset will be loaded in few minutes.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglFjVGOQiCESkOqQcbNNUDcfSoAQAkfGq51fK2CLDradFydbxJOLweXVFK8aN7SMiJf6d0Ri4c-JdwExx3nZUWvg8v55qTqOeOqbvtUMFaye1e2aekqVoMxZSAuE5CH_ZwPmSbxAhBcr4/s550/Image24.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="308" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglFjVGOQiCESkOqQcbNNUDcfSoAQAkfGq51fK2CLDradFydbxJOLweXVFK8aN7SMiJf6d0Ri4c-JdwExx3nZUWvg8v55qTqOeOqbvtUMFaye1e2aekqVoMxZSAuE5CH_ZwPmSbxAhBcr4/s16000/Image24.jpg" /></a></div></div>In next Article, we will connect .Net Core application with MongoDB cluster.<br /><div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div><div><br /></div><div><br /></div></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-70749179376369918622020-11-04T05:31:00.000-08:002020-11-04T05:31:03.298-08:00Exception Handling in SQL Server<p>In this Article, we will learn How to Handle Exception in SQL Server and also see How to capture or Log the Exception in case of any DB Level Exception occurs so that the Developer can refer to that Error log, can check the severity of the Exception, and fix it without wasting too much time in finding the exception causing procedure or function or line which is causing the exception.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioht63EnELps4bxkggY2_25PBDOSFGu0GZIQZNvWmqT8cy99jcQE3l8Dd8fM4oP5XPs1DfPTtGFGg9IhDipNdL6HBmET5w-_cEtSAVfiJBz0GDXPpw_36ErpozvML50EyxdmYVrDiCJgg/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioht63EnELps4bxkggY2_25PBDOSFGu0GZIQZNvWmqT8cy99jcQE3l8Dd8fM4oP5XPs1DfPTtGFGg9IhDipNdL6HBmET5w-_cEtSAVfiJBz0GDXPpw_36ErpozvML50EyxdmYVrDiCJgg/s16000/Cover.jpg" /></a></div></div><span><a name='more'></a></span><div><div><b>Let Begin</b>:</div><div>In order to demonstrate how an exception is thrown in the procedure, I have created a Sample Procedure i.e. usp_SampleProcedure as shown below</div></div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">CREATE</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">PROCEDURE</span> dbo<span style="color: grey;">.</span>[usp_SampleProcedure]<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">AS</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">BEGIN</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">SELECT</span>
1 <span style="color: grey;">/</span> 0 <span style="color: blue;">AS</span>
Result<span style="color: grey;">;</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">END</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></p>
</td>
</tr>
</tbody></table></div><p>In the above procedure, I have written a query which will thow Divide by Zero Exception on the execution of the procedure.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheW6Q8kmnTYSC9WFDUPnrVp7vj7pL2mCsrLhegJsWs1ol6Tm93shGsRiFGN6bim2B4u3_Fj87CL8psoWIQot5yDd4h8bc4LZ5fG2F0hXp10aCOk_TpKZx9DBqeLf2Fd9vIaXYc1LBzTlA/s550/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="91" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheW6Q8kmnTYSC9WFDUPnrVp7vj7pL2mCsrLhegJsWs1ol6Tm93shGsRiFGN6bim2B4u3_Fj87CL8psoWIQot5yDd4h8bc4LZ5fG2F0hXp10aCOk_TpKZx9DBqeLf2Fd9vIaXYc1LBzTlA/s16000/Image1.jpg" /></a></div></div><div>Now in order to handle this exception, we need to use a try-catch block in the procedure. In case of exception, we will handle or log the exception in the catch block. I have created a Table i.e. DBErrorLogs in order to capture the DB Level Error. The schema of the table is shown below.</div><div><b><br /></b></div><div><b>Schema of Table DBErrorLogs</b>:</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">CREATE</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">TABLE</span> dbo<span style="color: grey;">.</span>DBErrorLogs<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">(</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> ErrorLogID <span style="color: blue;">BIGINT</span> <span style="color: blue;">IDENTITY</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> UserName <span style="color: blue;">NVARCHAR </span><span style="color: grey;">(</span>200<span style="color: grey;">)</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> ErrorNumber <span style="color: blue;">INT</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> ErrorState <span style="color: blue;">INT</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> ErrorSeverity <span style="color: blue;">INT</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> ErrorLine <span style="color: blue;">INT</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> ErrorProcedure <span style="color: blue;">VARCHAR
</span><span style="color: grey;">(</span><span style="color: magenta;">max</span><span style="color: grey;">)</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> ErrorMessage <span style="color: blue;">VARCHAR </span><span style="color: grey;">(</span><span style="color: magenta;">max</span><span style="color: grey;">)</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> ErrorOccuredOn <span style="color: blue;">DATETIME</span>
<span style="color: grey;">NOT</span> <span style="color: grey;">NULL,</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">CONSTRAINT</span>
PK_DBErrorLogs <span style="color: blue;">PRIMARY</span> <span style="color: blue;">KEY </span><span style="color: grey;">(</span>ErrorLogID<span style="color: grey;">)</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">)<o:p></o:p></span></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><o:p> </o:p></p>
</td>
</tr>
</tbody></table></div><div>Procedure i.e. usp_SampleProcedure after using Try Catch Block:</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">CREATE</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">PROCEDURE</span> dbo<span style="color: grey;">.</span>[usp_SampleProcedure]<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">AS</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">BEGIN</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">BEGIN</span> <span style="color: blue;">TRY</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">SELECT</span>
1 <span style="color: grey;">/</span> 0 <span style="color: blue;">AS</span>
Result<span style="color: grey;">;</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">END</span> <span style="color: blue;">TRY</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">BEGIN</span> <span style="color: blue;">CATCH</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">INSERT</span>
<span style="color: blue;">INTO</span> dbo<span style="color: grey;">.</span>dbErrorLogs<span style="color: blue;"> </span><span style="color: grey;">(</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> UserName<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorNumber<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorState<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorSeverity<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorLine<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorProcedure<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorMessage<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorOccuredOn<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">)</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">VALUES </span><span style="color: grey;">(</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: magenta;">SUSER_SNAME</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_NUMBER</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_STATE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_SEVERITY</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_LINE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_PROCEDURE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_MESSAGE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">)</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">END</span> <span style="color: blue;">CATCH</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">END<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><o:p> </o:p></p>
</td>
</tr>
</tbody></table></div><p>As you can see, we are capturing the various fields with the help of predefined functions provided by SQL like UserName, ErrorNumber, ErrorState, ErrorSeverity, ErrorLine, ErrorProcedure, ErrorMessage, ErrorOccuredOn, etc. which will help us to find us the real root causing issue of the Exception. Let’s understand each function quickly.</p><p><b>1. SUSER_SNAME()</b>: Returns the Login Name for the current Security Context. </p><p><b>2. ERROR_NUMBER()</b>: Returns the error number of the error which caused the catch block of a try-catch construct to execute. ERROR_NUMBER() returns NULL when called outside of the scope of the Catch Block.</p><p><b>3. ERROR_STATE()</b>: Returns the State Number of the error message that caused the Catch Block to Run and it returns NULL when called outside of the scope of the Catch Block.</p><p><b>4. ERROR_SEVERITY()</b>: returns the Severity of the Error when the error or exception occurs. There are several levels of Error Severity defined by Microsoft which can be used to identify the type of the problem encountered by the SQL Server. For more, you can visit <a href="https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-error-severities?view=sql-server-ver15" target="_blank">https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-error-severities?view=sql-server-ver15</a> link. ERROR_SEVERITY() returns NULL when called outside of the scope of the Catch Block.</p><p><b>5. ERROR_LINE()</b>: returns the line number of the occurrence of the Error. ERROR_LINE returns NULL when called outside of the scope of the Catch Block.</p><p><b>6. ERROR_PROCEDURE()</b>: returns the name of the procedure or trigger on the occurrence of the Error. ERROR_PROCEDURE() returns NULL in case error did not occur in the stored procedure or trigger or when called outside of the scope of the Catch Block.</p><p><b>7. ERROR_MESSAGE()</b>: returns the message text of the error that caused the catch block of a try-catch block to execute.</p><div>The result on handling the exception with a try-catch block:</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtYYvipkE1gIG0yseapwjfG-QPtx3IabfKH8Wiv1r_w6IeC-IgNOFT44KsjXWq_A2z7XYHvANIJa7fFuJNhhx1eS-0Z_5OCQKdn-Tx3zNqMPLebECrZEDO4twADkKB4Al4hKxJUHIo0Dc/s550/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="110" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtYYvipkE1gIG0yseapwjfG-QPtx3IabfKH8Wiv1r_w6IeC-IgNOFT44KsjXWq_A2z7XYHvANIJa7fFuJNhhx1eS-0Z_5OCQKdn-Tx3zNqMPLebECrZEDO4twADkKB4Al4hKxJUHIo0Dc/s16000/Image2.jpg" /></a></div></div>Messages which shows the records is inserted in DBErrorLogs Table:
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFg-Wn0walYYgu4eHl9jF0aMBEYD2iGtPQmwFd2ZdijERZKqQIDjdM-o-gjOlyQ7aXQz9GJp5zACZxsE0l8gmWmTC-EfnLKHOyRHg9e2zy1ZV74mX-u1iRU0eL9H3ClOjQq522nMzHFNk/s550/Image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="103" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFg-Wn0walYYgu4eHl9jF0aMBEYD2iGtPQmwFd2ZdijERZKqQIDjdM-o-gjOlyQ7aXQz9GJp5zACZxsE0l8gmWmTC-EfnLKHOyRHg9e2zy1ZV74mX-u1iRU0eL9H3ClOjQq522nMzHFNk/s16000/Image3.jpg" /></a></div></div>Preview of DBErrorLogs Table:
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFFj3Pw1sy01T0p5luHNL33FUSyVjHWFU1olt_2IM4m4_zGA9llo5Lq6vv4mwxPkC0-Rt3t9bqzYkGYap_mtSGncZ7zIfimBDxiYadNJ5Va35YvbHYLQsollo3hqOndolYnWhTsj5D8nc/s550/Image4.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="138" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFFj3Pw1sy01T0p5luHNL33FUSyVjHWFU1olt_2IM4m4_zGA9llo5Lq6vv4mwxPkC0-Rt3t9bqzYkGYap_mtSGncZ7zIfimBDxiYadNJ5Va35YvbHYLQsollo3hqOndolYnWhTsj5D8nc/s16000/Image4.jpg" /></a></div></div><div><b><br /></b></div><div><b>Rollback Transaction In case of any Error/Exception:</b></div><div>Now let see how to rollback a transaction when an error or exception is encountered. For the demonstration, I am using the AdventureWorks Database to show the below demo. I am trying to delete a record in a transaction that cannot be deleted because of the conflict with the reference constraint and throws an error.</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">CREATE</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">PROCEDURE</span> dbo<span style="color: grey;">.</span>[usp_SampleProcedure]<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">AS</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">BEGIN</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">BEGIN</span> <span style="color: blue;">TRY</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">BEGIN</span>
<span style="color: blue;">TRANSACTION</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: green;">--For
Demo, delete query written below will throw error</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: green;">--The
DELETE statement conflicted with the REFERENCE constraint</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">DELETE</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">FROM</span>
Person<span style="color: grey;">.</span>Person<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">WHERE</span>
BusinessEntityID <span style="color: grey;">=</span> 20777<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">COMMIT</span>
<span style="color: blue;">TRANSACTION</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">END</span> <span style="color: blue;">TRY</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">BEGIN</span> <span style="color: blue;">CATCH</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: green;">--@@TRANCOUNT
for number of BEGIN TRANSACTION statements </span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: green;">--that
have occurred on the current connection.</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">IF</span>
<span style="color: magenta;">@@TRANCOUNT</span> <span style="color: grey;">></span>
0<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">ROLLBACK</span>
<span style="color: blue;">TRANSACTION</span><span style="color: grey;">;</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> </span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">INSERT</span>
<span style="color: blue;">INTO</span> dbo<span style="color: grey;">.</span>dbErrorLogs<span style="color: blue;"> </span><span style="color: grey;">(</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> UserName<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorNumber<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorState<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorSeverity<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorLine<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorProcedure<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorMessage<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span>ErrorOccuredOn<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">)</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">VALUES </span><span style="color: grey;">(</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: magenta;">SUSER_SNAME</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_NUMBER</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_STATE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_SEVERITY</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_LINE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_PROCEDURE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">ERROR_MESSAGE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">()</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: grey;">)</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> <span style="color: blue;">END</span> <span style="color: blue;">CATCH</span><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">END<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><o:p> </o:p></p>
</td>
</tr>
</tbody></table></div><div>In the catch block, we are checking <b>@@TRANCOUNT</b> in order to check whether any transaction is encountered before throwing the error. If <b>@@TRANCOUNT</b> returns a value more than 0, in that case, we will roll back the transaction and log the error details in our DBErrorLogs table.<br /><div><b>Preview</b>:<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgExqTC4kEddhQGUnsB_petFLkOUJy7PfutufMI9AlX0prx1Jf6f0wplYQum5jZ6DM5DrVjPcI9wCIYjtmsw5vJu__tKQav80eAqR6mp4pLlkbctnhEP7sYapfPsOzVeCVE9hqeDyRwzrQ/s550/Image5.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="183" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgExqTC4kEddhQGUnsB_petFLkOUJy7PfutufMI9AlX0prx1Jf6f0wplYQum5jZ6DM5DrVjPcI9wCIYjtmsw5vJu__tKQav80eAqR6mp4pLlkbctnhEP7sYapfPsOzVeCVE9hqeDyRwzrQ/s16000/Image5.jpg" /></a></div></div><div>I hope this article helps you in getting a basic understanding to handle exceptions or errors in the SQL Server.</div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div></div></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-31423865175038915332020-10-25T10:35:00.000-07:002020-10-25T10:35:03.125-07:00Program to generate Floyd’s Triangle in C#<p>Floyd’s triangle is a right-angled triangle of natural numbers used in computer science education. Floyd refers to the name after Robert Floyd. Floyd’s triangle is created by printing the consecutive numbers in the rows of the triangle starting from the number 1 at the top left corner.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmgWkUsefnfeCNFfiXZbVK0I82u4u1wSuXiCw854UhXN0cuezn0BEz9lyuRHtbQu-WFJnjt6KZYbMTcNCRJOyZNxXn0bzJUVvr9CkYNmBrNmk1MuXCs96VQEh5KlCvfOd0FDxRBh1k5FE/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmgWkUsefnfeCNFfiXZbVK0I82u4u1wSuXiCw854UhXN0cuezn0BEz9lyuRHtbQu-WFJnjt6KZYbMTcNCRJOyZNxXn0bzJUVvr9CkYNmBrNmk1MuXCs96VQEh5KlCvfOd0FDxRBh1k5FE/s16000/Cover.jpg" /></a></div></div>
<div class="clsImportant">
<div>I will recommend you to check the below link for Top C# Interview Programs asked during the Interview and Examination.</div><div><ul style="text-align: left;"><li><a href="https://www.ittutorialswithexample.com/2020/09/top-csharp-programs-for-interview.html.html" target="_blank">Top C# Program for Interview</a></li></ul></div>
</div>
<div><b>Program</b>:</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Three variable one for outer loop, one for inner</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//k to print the number</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> i, j, k = 1;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">for</span><span style="font-family: Consolas; font-size: 9.5pt;"> (i=1;i<=10;i++) {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> for</span><span style="font-family: Consolas; font-size: 9.5pt;"> (j=1;j<=i;j++) {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Print no. in console with horizontal space i.e. tab</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.Write(k++ + </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"\t"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//New Line</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.Write(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"\n"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Console.ReadLine() to hold the screen after the execution of
the program</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.ReadLine();</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div><p><b>Preview</b>:</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0CC3vIZ_odymPI7LF4w167Cy2CdrFTFYJGf-yeLyJ8FMhBh1FPb8SA58CMJn9vEmKrOTPC3aItHjQt6D5aeGsbxDyyounActIghyou8REvXGjor85llrmLXPCLREyn59JmuCpr-cA7hc/s550/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="197" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0CC3vIZ_odymPI7LF4w167Cy2CdrFTFYJGf-yeLyJ8FMhBh1FPb8SA58CMJn9vEmKrOTPC3aItHjQt6D5aeGsbxDyyounActIghyou8REvXGjor85llrmLXPCLREyn59JmuCpr-cA7hc/s16000/Image1.jpg" /></a></div></div><div>I hope this program will help you in your exam as well as Interview preparation.</div><div>Thanks</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-87053591831630653002020-09-27T20:23:00.000-07:002020-09-27T20:23:25.062-07:00Deployment Manager and Monitoring in Google Cloud Platform<p>In this article, we will learn How to use the Deployment Manager to deploy VM Instance as well as monitor them in the Google Cloud Platform. If you are new to this series of Google Cloud Platform, I will recommend you to go through the below articles of this series:</p>
<div class="clsImportant">
<p><a href="https://www.ittutorialswithexample.com/2020/08/setting-up-lamp-certified-by-bitnami-in.html" target="_blank">Setting Up LAMP Certified by Bitnami In Google Cloud Platform</a></p><p><a href="https://www.ittutorialswithexample.com/2020/08/create-virtual-machine-google-compute-engine.html" target="_blank">Create Virtual Machine Instance in Compute Engine in The Google Cloud Platform</a></p><p><a href="https://www.ittutorialswithexample.com/2020/08/create-storage-bucket-in-google-cloud-platform.html" target="_blank">Create a storage bucket in Google Cloud Platform</a></p><p><a href="https://www.ittutorialswithexample.com/2020/08/getting-started-with-sql-in-google-cloud.html" target="_blank">Getting Started with Cloud SQL in Google Cloud Platform</a></p><p><a href="https://www.ittutorialswithexample.com/2020/08/working-up-with-google-kubernetes-engine.html.html" target="_blank">Working Up With Google Kubernetes Engine In Google Cloud Platform</a></p></div>
<div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh488_exExU7DvtH9WrKRhCmciasu7-D6wUDZKLgzh4RQ0fXsoRiyrrRA-UtMkLqZEaSVtK8kwQgM93AYsxsiwbZtK5e0I5XKOrv-XCJ4fOwSUZqCiiPMgdU8WhkBoCFDfr6p1yLk07p1E/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh488_exExU7DvtH9WrKRhCmciasu7-D6wUDZKLgzh4RQ0fXsoRiyrrRA-UtMkLqZEaSVtK8kwQgM93AYsxsiwbZtK5e0I5XKOrv-XCJ4fOwSUZqCiiPMgdU8WhkBoCFDfr6p1yLk07p1E/s16000/Cover.jpg" /></a></div></div><span><a name='more'></a></span><div><div><b>Let’s Begin</b>:</div><div><b>Step 1</b>:</div><div>Log in to the Google Cloud Platform by visiting <a href="https://console.cloud.google.com/" target="_blank">https://console.cloud.google.com/</a> (Google provides $300 as a free trial, but for that, you need to link your credit card).</div></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinZ0gINDbixr8HxY04wL0f6olpwmE1KzV_wADsYOPdm6ky8H_L9EqzJRAoalCglsb02CiwjnBZ-YDyixJUEh5rPHgtA4RepLD-2n49KE3qwVzcobmt380O6_41lrkbwgIZr8KbMZhHsJg/s444/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="444" data-original-width="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinZ0gINDbixr8HxY04wL0f6olpwmE1KzV_wADsYOPdm6ky8H_L9EqzJRAoalCglsb02CiwjnBZ-YDyixJUEh5rPHgtA4RepLD-2n49KE3qwVzcobmt380O6_41lrkbwgIZr8KbMZhHsJg/s16000/Image1.jpg" /></a></div></div>Once logged in, you will be redirected to the dashboard of the Google Cloud Platform.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEBviBb2zJzgA5Di9qsGVYNrPiYsxWkMjdDz7spbea3U1cbDKNdkrzTovtdLYCmQxgG08O1GbkyROdeJ_rxoRost39LHlLk-q9c-Zmgd4ScedrQZKQPUlIpMmFrIwIufVUAMG-L9MqdTM/s550/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="270" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEBviBb2zJzgA5Di9qsGVYNrPiYsxWkMjdDz7spbea3U1cbDKNdkrzTovtdLYCmQxgG08O1GbkyROdeJ_rxoRost39LHlLk-q9c-Zmgd4ScedrQZKQPUlIpMmFrIwIufVUAMG-L9MqdTM/s16000/Image2.jpg" /></a></div></div><div><b>Step 2</b>:</div><div>Go to APIs & Services, And Click on Dashboard</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwob6f5ozxFOmOjZLXPGajGDNHKUi27XzOmas5tGQJKJW_svWs9fg4be4WTlc1avtFzJe0vGT3Mn2FHyBiUDyUu_ojGH8MZ-JaHZGS1fGqmio03azg6YbQGhIa7RIXFSvuMMlzfQ9N9VQ/s460/Image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="454" data-original-width="460" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwob6f5ozxFOmOjZLXPGajGDNHKUi27XzOmas5tGQJKJW_svWs9fg4be4WTlc1avtFzJe0vGT3Mn2FHyBiUDyUu_ojGH8MZ-JaHZGS1fGqmio03azg6YbQGhIa7RIXFSvuMMlzfQ9N9VQ/s16000/Image3.jpg" /></a></div></div>Make sure Cloud Deployment Manager V2 API, Cloud Runtime Configuration, Stack Driver Monitoring API (If you want to monitor, troubleshoot & improve application performance on your Google Cloud)
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQVYgn2NMPiXV9APFfKtb-7JGlal-W9JaoQlDDvuJa-VBsQRYdG3DqtQmwSssly6nVw7oe0y8RcDza2gm29TxieHEeWZmj8EZNRuXYC9bwovtLjikqZaTSoFn_TyX4LNWrlUh9p1WewI4/s550/Image4.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="390" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQVYgn2NMPiXV9APFfKtb-7JGlal-W9JaoQlDDvuJa-VBsQRYdG3DqtQmwSssly6nVw7oe0y8RcDza2gm29TxieHEeWZmj8EZNRuXYC9bwovtLjikqZaTSoFn_TyX4LNWrlUh9p1WewI4/s16000/Image4.jpg" /></a></div></div>
<br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><br /></div><div><div><br /></div></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEierOUJux9dMqAepX6iXLBR5cNSw84KHgOveDvyFxM7D3niQ60m53uWrBiqK22lbiUklcQuSSXX_cogvd3MFgb0tjQ_LuKcHuAa4UscoaEvkJgptjE7JvFH7I99l77ueAiurcseHol0Ovk/s550/Image5.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="406" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEierOUJux9dMqAepX6iXLBR5cNSw84KHgOveDvyFxM7D3niQ60m53uWrBiqK22lbiUklcQuSSXX_cogvd3MFgb0tjQ_LuKcHuAa4UscoaEvkJgptjE7JvFH7I99l77ueAiurcseHol0Ovk/s16000/Image5.jpg" /></a></div></div><br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA-_t1JzrXVUcWZxYm8PW2Y5ntxZUjQ2fvK9M8CPibMho0KDgOqCCB2mA4ashOvOgaZEmRSFOB7jW4Q5Xf7n6XuFXxzPiNIAMHifKwWyI851_8977Gnu9PHwZ7RiZ3lU0o2pjHOwC-qaY/s550/Image6.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="449" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA-_t1JzrXVUcWZxYm8PW2Y5ntxZUjQ2fvK9M8CPibMho0KDgOqCCB2mA4ashOvOgaZEmRSFOB7jW4Q5Xf7n6XuFXxzPiNIAMHifKwWyI851_8977Gnu9PHwZ7RiZ3lU0o2pjHOwC-qaY/s16000/Image6.jpg" /></a></div></div><div><b>Step 3</b>:</div><div>Click on the Google Cloud Shell icon and Create a .yaml file (named It as mydeploy.yaml). You can use nano editor in order to do the same. (Please refer to <a href="https://cloud.google.com/deployment-manager/docs/configuration/create-basic-configuration" target="_blank">https://cloud.google.com/deployment-manager/docs/configuration/create-basic-configuration</a> link in order to understand the basic configuration required to create .yaml deployment configuration)</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4-jwHBdrWUovRMIEuPEY6OqWPHS25LSXVWrQLvtCAkLQmsK9ACMytRbAqTEc8L7pQBu4dIKiz9nAdyWKaYDRDLePBhsulyHOXlmJjSZRIHPvRXzBihfYWGoM50SIPcmtHskmqkYg4LNs/s272/Image7.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="90" data-original-width="272" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4-jwHBdrWUovRMIEuPEY6OqWPHS25LSXVWrQLvtCAkLQmsK9ACMytRbAqTEc8L7pQBu4dIKiz9nAdyWKaYDRDLePBhsulyHOXlmJjSZRIHPvRXzBihfYWGoM50SIPcmtHskmqkYg4LNs/s0/Image7.jpg" /></a></div></div><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc86kMdQU9s5NSYiLvp2R7QG6dt9ZiiNDywrH91Ka3a7vR0Eyj9qm8LZrC7G91QPmg_5TsQVZ9dikQReBKylLt5TZNxyzwx8BvKaFpBwnvZx5SU2j62mxTA7qMEp6KGz4FdEhoTkj9k60/s550/Image10.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="130" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc86kMdQU9s5NSYiLvp2R7QG6dt9ZiiNDywrH91Ka3a7vR0Eyj9qm8LZrC7G91QPmg_5TsQVZ9dikQReBKylLt5TZNxyzwx8BvKaFpBwnvZx5SU2j62mxTA7qMEp6KGz4FdEhoTkj9k60/s16000/Image10.jpg" /></a></div></div>.yaml file contains the configuration for the VM Instance like VM Name, Type, Zone, Machine Type, etc. as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTGq7J9XIAeEh48MStqffDU0rM374iYE8VPJ8Af02sQUWWhgg0JjPcx7kQk3AafSsFNd27UlctsVee4OKdoS9mPCfXvCmIGGsiNi4tyu1FLNX_hJWI5Y0te1M6BX3zOpU_4PGzDBHVJ9A/s550/Image12.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="245" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTGq7J9XIAeEh48MStqffDU0rM374iYE8VPJ8Af02sQUWWhgg0JjPcx7kQk3AafSsFNd27UlctsVee4OKdoS9mPCfXvCmIGGsiNi4tyu1FLNX_hJWI5Y0te1M6BX3zOpU_4PGzDBHVJ9A/s16000/Image12.jpg" /></a></div></div>Once everything is configured, mydeploy.yaml will look like as shown below
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5jV6BNSxUXhA88rehmG7BgnkasWixEfMT8VwXsS_kr7as4JqGwZsqdSoTIGNP1ITAXIKsq50TjVk0nH7zWJD8_FjSALbF9Fi8_R54cvT3_OibOLEW1WDEa_VliEi9aAKewG-IVvxlp_g/s550/Image14.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="245" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5jV6BNSxUXhA88rehmG7BgnkasWixEfMT8VwXsS_kr7as4JqGwZsqdSoTIGNP1ITAXIKsq50TjVk0nH7zWJD8_FjSALbF9Fi8_R54cvT3_OibOLEW1WDEa_VliEi9aAKewG-IVvxlp_g/s16000/Image14.jpg" /></a></div></div><div><b>Step 4</b>:</div><div>Run the below command in google cloud shell as mentioned below:</div><div><i>gcloud deployment-manager deployments create my-first-depl –config mydeploy.yaml</i></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPJpWDAcADZgwRzJN_AjDeuSg-GevzXk6mK_HOtInWU6nJsscTt13frkqWhhUpeb2pdxAQYnrX6cbgJUygxU3fX07_-3gjjKWoZWKnYHWbuijzHOia52fsY8B1Ri-M8xkZW4TDkyIkfEY/s550/Image15.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="158" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPJpWDAcADZgwRzJN_AjDeuSg-GevzXk6mK_HOtInWU6nJsscTt13frkqWhhUpeb2pdxAQYnrX6cbgJUygxU3fX07_-3gjjKWoZWKnYHWbuijzHOia52fsY8B1Ri-M8xkZW4TDkyIkfEY/s16000/Image15.jpg" /></a></div></div>--config flag is the relative path to your yaml configuration file. Once the above command executed successfully, a list with the resource name mentioned in the yaml file and its state will be shown to the user. We can also check the VM Instances in the Compute Engine menu as shown in the below image.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8H6XiLouOm0HoLsETVry-9YjLJLT_ASHCV2O-ZR5vS6pUpCgSzI5vtzqCcPzd4eQF86IkFR70JS2PyobeY-8ug0oh9DZEPEBSkEWYZsHXytFD8zchB3u9-EzagF1RBKqaMY8GftZUsuA/s476/Image16.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="444" data-original-width="476" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8H6XiLouOm0HoLsETVry-9YjLJLT_ASHCV2O-ZR5vS6pUpCgSzI5vtzqCcPzd4eQF86IkFR70JS2PyobeY-8ug0oh9DZEPEBSkEWYZsHXytFD8zchB3u9-EzagF1RBKqaMY8GftZUsuA/s16000/Image16.jpg" /></a></div></div><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidG79wJmri4HALGu7IrEl-tLrNYCjqEDgvp1rA2qKIuDPIRUo-ezZdbAXRWP1NH9O54gZvQcpenYEC1KWyzCHvMaEqTOpJ9caEfSv9hbWcb9BOkcUUpR67yzj1RQjAbjRCF9KqnqIxbrM/s550/Image17.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="146" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidG79wJmri4HALGu7IrEl-tLrNYCjqEDgvp1rA2qKIuDPIRUo-ezZdbAXRWP1NH9O54gZvQcpenYEC1KWyzCHvMaEqTOpJ9caEfSv9hbWcb9BOkcUUpR67yzj1RQjAbjRCF9KqnqIxbrM/s16000/Image17.jpg" /></a></div></div><div><b>Step: 5</b></div><div>Click on the VM Instance Name, Check the Startup-Script section. </div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZO9dVLZ2hxSoJOA5Tn2Mxvdbh4rJZp41PH9JEVaq4q7cpoVKEIgx715i9x75GnZMHPbxjeyOZbxIppV4AbQevgQYBDog8cMIHqYrcWhlTq0x3ZoTNKk_TVOtjcY1yWCQ8r7_Kxs7qgG8/s550/Image18.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="249" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZO9dVLZ2hxSoJOA5Tn2Mxvdbh4rJZp41PH9JEVaq4q7cpoVKEIgx715i9x75GnZMHPbxjeyOZbxIppV4AbQevgQYBDog8cMIHqYrcWhlTq0x3ZoTNKk_TVOtjcY1yWCQ8r7_Kxs7qgG8/s16000/Image18.jpg" /></a></div></div>Let’s edit the startup-scripts in the deployment.yaml config file as shown in the below image:
<div style="border: 1px dashed black; padding: 10px;">
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto;"><tbody><tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl0FmTCpnV0_mR5sHtGQl4I_eB4xChlNy5gSpdHQH8RI5r545X6JnZ4ATd55U08OVJ-GOFRy_uPjwzdEt4UQmzzI2IQVX2kbRWludKsK3j2K5aoN7MSyJmEeI0sLKLDJr1CAKzHHljBtc/s523/Image19.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="229" data-original-width="523" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl0FmTCpnV0_mR5sHtGQl4I_eB4xChlNy5gSpdHQH8RI5r545X6JnZ4ATd55U08OVJ-GOFRy_uPjwzdEt4UQmzzI2IQVX2kbRWludKsK3j2K5aoN7MSyJmEeI0sLKLDJr1CAKzHHljBtc/s16000/Image19.jpg" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><br /></td></tr></tbody></table></div><div>Run the below command in order to update the deployment/VM instance</div><div><i>gcloud deployment-manager deployments update my-first-depl –config mydeply.yaml</i></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwfvkQIZDhw0K8jvCTkjswGaYQjwRzdnOtYD_JCcuWwVwrOo0VVnqDt-TtRJdp72z683egMeDrkevs0qDe8nIksssv9X02KIMp7wYF_WDlb1QtUfgIFnaeudRmGELzhcVkE40Bp9OxKco/s550/Image20.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="23" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwfvkQIZDhw0K8jvCTkjswGaYQjwRzdnOtYD_JCcuWwVwrOo0VVnqDt-TtRJdp72z683egMeDrkevs0qDe8nIksssv9X02KIMp7wYF_WDlb1QtUfgIFnaeudRmGELzhcVkE40Bp9OxKco/s16000/Image20.jpg" /></a></div></div>Once updated, Visit the VM Instance again, you will see that startup-script under the custom-metadata section is also updated.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigQojeRnTgKFqty7e0wjCN0kUAOvUcQ8dP01GOD2540EXn-nFuM_zXNmxcCCohnkqpkJ9aoxC7pk_QKgwgP9Si4CXAcKjVA7p9J9k_AcRE72ufC98-aW6cTgeq8ihzSlDJS1_09V5K4vA/s550/Image21.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="244" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigQojeRnTgKFqty7e0wjCN0kUAOvUcQ8dP01GOD2540EXn-nFuM_zXNmxcCCohnkqpkJ9aoxC7pk_QKgwgP9Si4CXAcKjVA7p9J9k_AcRE72ufC98-aW6cTgeq8ihzSlDJS1_09V5K4vA/s16000/Image21.jpg" /></a></div></div><div><br /></div><b>Monitoring of Google Cloud Services:</b><br /><div><div><b>Step 1</b>:</div><div>Click on the Overview submenu of the Monitoring menu.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0QDh3VYMHR2OSRpGFAI07rzbdmDKiwMq4EVDCzkDjj-BOpHAqJXt3Drffi922JTpyf9LYAknaeeHohB2PBwdbpFd_369U5Oi6GQ93EvvAMJIb3eINszwS-i1olcBq5TFtRr07RUPVuUQ/s536/Image22.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="429" data-original-width="536" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0QDh3VYMHR2OSRpGFAI07rzbdmDKiwMq4EVDCzkDjj-BOpHAqJXt3Drffi922JTpyf9LYAknaeeHohB2PBwdbpFd_369U5Oi6GQ93EvvAMJIb3eINszwS-i1olcBq5TFtRr07RUPVuUQ/s16000/Image22.jpg" /></a></div></div>Then click on View GCE Dashboard as shown in the below image:</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRbOKuEhyBLhK6xWo2hDowBlsNfhpqwFZ35jBFPz60ZT1RvfH1lhP486sTs-qOOhGEGgeBuLoiE8LSN2M9J0vYLhqoYIjLVZfVe02YV7DUg0CwXM-rcq5wlfFP8NH-m2WZme-SV2TFgCk/s550/Image23.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="367" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRbOKuEhyBLhK6xWo2hDowBlsNfhpqwFZ35jBFPz60ZT1RvfH1lhP486sTs-qOOhGEGgeBuLoiE8LSN2M9J0vYLhqoYIjLVZfVe02YV7DUg0CwXM-rcq5wlfFP8NH-m2WZme-SV2TFgCk/s16000/Image23.jpg" /></a></div></div>Check Monitoring Agent Status, in case of not detected, Install Agent by clicking on the Install Agent button.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaS1i3et5cvOPv7GvvFf7FztGyAK44tSb8xpLOkMLg5-UaVXH9dPlwFDdBArlT2bK9va3DvzZ6am0tUe8xY999zx1TGJZ63KdwJ86Gn4B85zTzzJKuM0IaYTpT3YuCarpiv9JkFd_-rRk/s550/Image24.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="302" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaS1i3et5cvOPv7GvvFf7FztGyAK44tSb8xpLOkMLg5-UaVXH9dPlwFDdBArlT2bK9va3DvzZ6am0tUe8xY999zx1TGJZ63KdwJ86Gn4B85zTzzJKuM0IaYTpT3YuCarpiv9JkFd_-rRk/s16000/Image24.jpg" /></a></div></div>You can track CPU Utilization, Received & send bytes, etc.
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvTWF5VadGVB1EdptH4NCyc8-B631xvU4vZRSsJB_IN59_9da3gd4JhsLdgoSYovqBoRLuB6RpHfgGgih1wvml6AppluNno_X57EcV8WT3Jaojvky9V99x0dRONVPZc3gpmv55VTwb4xc/s550/Image25.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="305" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvTWF5VadGVB1EdptH4NCyc8-B631xvU4vZRSsJB_IN59_9da3gd4JhsLdgoSYovqBoRLuB6RpHfgGgih1wvml6AppluNno_X57EcV8WT3Jaojvky9V99x0dRONVPZc3gpmv55VTwb4xc/s16000/Image25.jpg" /></a></div></div><div>I hope this will article help you in getting the basic understanding of Deployment Manager and Monitoring tools in Google Cloud Platform.</div><div>Thanks</div><div><br /></div><div><div><div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" rel="nofollow" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div><br /><div><br /></div></div></div></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-35308477705551399492020-09-19T10:36:00.000-07:002020-09-19T10:36:48.083-07:00Program to find the HCF of two numbers in C#<p>In this blog, we will learn How to find the HCF of two numbers in C#. If you are looking for Programs asked in C# Interview, check the below link:</p><p></p><ul style="text-align: left;"><li><a href="https://www.ittutorialswithexample.com/2020/09/top-csharp-programs-for-interview.html.html" target="_blank">Top C# Program for the Interview</a></li></ul><p></p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9LamCqkv1GYjA6elI-CJcO_p4WbGhndFNl8r5sSi5ynVxBo5r1rx0pItCtMky_B5M-DPuuAXgAV8yhlOZEVkN2WRkmCJv5g26b2YRcDpkMbVnjVNXiZfEkOq7Ibbwr7kPEhJZo_pKTM8/s550/image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9LamCqkv1GYjA6elI-CJcO_p4WbGhndFNl8r5sSi5ynVxBo5r1rx0pItCtMky_B5M-DPuuAXgAV8yhlOZEVkN2WRkmCJv5g26b2YRcDpkMbVnjVNXiZfEkOq7Ibbwr7kPEhJZo_pKTM8/s16000/image2.jpg" /></a></div></div><div><br /></div>
<div class="clsImportant"><b>
HCF</b> Stands for <b>Highest Common Factor</b>. It is also called the <b>Greatest Common Measure</b> (<b>GCM</b>) and <b>Greatest Common Divisor</b> (<b>GCD</b>). For finding the HCF, we need to find the greatest number which divides two or more numbers.</div><p><br /></p><p>Check the below C# program, for calculating the HCF of two numbers in C#. I have mentioned comments as well for easy understanding.</p><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> num1, num2, loopCheck, hcf=0;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Prompt user to add two number for which HCF needs to find</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter
First Number"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">num1 = Convert.ToInt32(Console.ReadLine());<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter
Second Number"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">num2 = Convert.ToInt32(Console.ReadLine());<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//set the min value out of the numbers entered by the user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">loopCheck = num2 > num1 ? num1 : num2;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Loop the data from 1 to the loopCheck value</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">for</span><span style="font-family: Consolas; font-size: 9.5pt;"> (</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> i = 1; i <= loopCheck; i++)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> //If Modulus of both
number will be Zero than store it in hcf variable</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (num1 % i == 0 && num2 %
i == 0)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> hcf = i;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Show the output to the User</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.Write(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"HCF of {0} and
{1} is: {2}"</span><span style="font-family: Consolas; font-size: 9.5pt;">, num1, num2, hcf);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Console.ReadLine() t</span><o:p></o:p></p>
</td>
</tr>
</tbody></table><p><b>Output</b>:</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDEv2FMHtR_M5L1UOcFinmzIDEDGwMTYl2vuEneRZLrm90wxWUcDlhd8j1U_SLOZ0m4S-hCRbXAza39CKHnwggqfz5Xzj8NWYUBu-vePk6p1Iq0W1s0urezgR9ay9UQUZ0JfVk7Mlrvao/s550/image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="117" data-original-width="550" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDEv2FMHtR_M5L1UOcFinmzIDEDGwMTYl2vuEneRZLrm90wxWUcDlhd8j1U_SLOZ0m4S-hCRbXAza39CKHnwggqfz5Xzj8NWYUBu-vePk6p1Iq0W1s0urezgR9ay9UQUZ0JfVk7Mlrvao/s16000/image1.jpg" /></a></div></div><div>I hope this will help you with your interview preparation or exam.</div><div>Thanks</div><div class="separator" style="clear: both; text-align: center;"><a href="https://www.copyscape.com/" imageanchor="1" rel="nofollow" style="margin-left: 1em; margin-right: 1em;" target="_blank"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div><div><br /></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-26175807639502767972020-09-14T19:41:00.002-07:002020-09-14T20:00:56.476-07:00Program to check a number is Palindrome in C#<p>In this blog, we will learn How to check a number is Palindrome or not in C#. This Is also one of the most popular interview questions among the interviewers. The basic approach is to reverse the number and then compare it with the number added by the user. </p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh04reHbDhSCvHFFng__sVQ3_su7GjIV_D19SMJYno2Uqup_nF-umtljSHeLJoOy4wj8ieNpqGH5_876ZO6ouIFV_vFm7EdPPi3tXhvMiVyv780sJb56PHbSywNoapi_5qlqtIGxBoiGXk/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh04reHbDhSCvHFFng__sVQ3_su7GjIV_D19SMJYno2Uqup_nF-umtljSHeLJoOy4wj8ieNpqGH5_876ZO6ouIFV_vFm7EdPPi3tXhvMiVyv780sJb56PHbSywNoapi_5qlqtIGxBoiGXk/w500-h226/Cover.jpg" width="500" /></a></div></div><span><a name='more'></a></span>
<div class="clsImportant">
<div>Some Programs which might be useful are:</div>
<div><a href="https://www.ittutorialswithexample.com/2020/09/program-to-check-string-is-palindrome-in-csharp.html" target="_blank">Program to check a string is Palindrome in C#</a></div>
<div><a href="https://www.ittutorialswithexample.com/2014/10/reverse-number-in-c.html" target="_blank">Reverse a Number in C#</a></div>
</div>
<div><br /></div><div>Let's create the program in C#:</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> Number, TmpNumber, Reverse;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter
a No. to check either it's palindrome or not"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Get number from the user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Number = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;">.Parse(Console.ReadLine());<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Hold the number in the TmpNumber</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">TmpNumber = Number;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Reverse = 0;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Reverse the Number</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">while</span><span style="font-family: Consolas; font-size: 9.5pt;"> (Number > 0)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> int</span><span style="font-family: Consolas; font-size: 9.5pt;"> remainder = Number % 10;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Reverse = (Reverse *
10) + remainder;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Number = Number / 10;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Compare the Reversed number with the number entered by the
user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (TmpNumber == Reverse)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"'{0}' no. is an example of Palindrome"</span><span style="font-family: Consolas; font-size: 9.5pt;">, TmpNumber);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"'{0}' no. is not an example of Palindrome"</span><span style="font-family: Consolas; font-size: 9.5pt;">, TmpNumber);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Console.ReadLine() to hold the screen after the execution of
the program</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.ReadLine();</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div><div><b>Output:</b></div><div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir2_I3yRnnegRzFRdGJvio8H5ZLnpBHLuKq13A9N1rrzOZD2po2yEodMuc0YS-B-gc7S1kVJoxryNaR8kJJoe0SfIsPrYPJ_QYu-uLLuZ3taw9rTNEkVboRhXF4Xzt4NjY3bSC4c8SS-U/s550/image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="108" data-original-width="550" height="99" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEir2_I3yRnnegRzFRdGJvio8H5ZLnpBHLuKq13A9N1rrzOZD2po2yEodMuc0YS-B-gc7S1kVJoxryNaR8kJJoe0SfIsPrYPJ_QYu-uLLuZ3taw9rTNEkVboRhXF4Xzt4NjY3bSC4c8SS-U/w500-h99/image1.jpg" width="500" /></a></div></div><div><br /></div></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6H0gU8C5B0Gy39WJYwEzUX8jb1I2Nw-GvC12eKO_ulK6iZAFsOKqneYNkcR9o2q05nEx2k8HoiSK_LLNrbrNmzznsnTiH0oomW00LxVpZYnnuBH7B2eYhrZxxWJhomD2iXaZy1y5jKt4/s550/image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="98" data-original-width="550" height="89" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6H0gU8C5B0Gy39WJYwEzUX8jb1I2Nw-GvC12eKO_ulK6iZAFsOKqneYNkcR9o2q05nEx2k8HoiSK_LLNrbrNmzznsnTiH0oomW00LxVpZYnnuBH7B2eYhrZxxWJhomD2iXaZy1y5jKt4/w500-h89/image2.jpg" width="500" /></a></div></div><div>I hope this will help you in your interview preparation/exam.</div><div>Thanks</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s234/cs-wh-234x16.gif" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-73042416098694617812020-09-13T10:13:00.001-07:002020-09-13T10:13:32.720-07:00Program to check a string is Palindrome in C#<p>In this blog, we will learn How to write a program to check whether a String is a Palindrome or not in C#. A palindrome is a word or phrase or a sequence of characters that reads the same either read from backward or as in forwards e.g. Malayalam, Madam, etc. </p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHo45sHGbxN3iCz8S9ZNv6fSn4WRdONFxkRuvckGrQQnWu74AjqCULv817gokYYF-p7MT4kp93xe8BHUsRttukLSxrwEEpeu769HA6fQHaPAdioKiPQE1IzK3Fh7fDnBjKjDCHXz3n_Bo/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHo45sHGbxN3iCz8S9ZNv6fSn4WRdONFxkRuvckGrQQnWu74AjqCULv817gokYYF-p7MT4kp93xe8BHUsRttukLSxrwEEpeu769HA6fQHaPAdioKiPQE1IzK3Fh7fDnBjKjDCHXz3n_Bo/w500-h226/Cover.jpg" width="500" /></a>
</div></div><div>It is also one of the popular and favorite programs asked during the interview/exam. There are multiple ways by which we can check either string is palindrome or not, Out of which two are mentioned here in this blog.</div><div>1.<span style="white-space: pre;"> </span>Iterate through each character and generate the reverse string</div><div>2.<span style="white-space: pre;"> </span>Break string to array and reverse the string</div><div><br /></div><div><b>1. Iterate through each character and generate reverse string:</b></div><div><div>In this method, we start reading the character from the last character of the string and store it in another variable as shown in the below image. Once the string is reversed, compare it with the original string to find that string entered by the user is Palindrome or not.</div></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhd3GY4rQjPy9lcINi9THXWCWJdlG4YF1fOBlXzUQTCiJtK8ngGxtPCfj2CXihjas9S-5L1NeWYmL_0Hmf8AQVQNLxXufbFfgFsjlL1fEmj1Jn8qRwJi_RwKc8jklTrvNWmlpiD95a8s0w/s550/Image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="521" data-original-width="550" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhd3GY4rQjPy9lcINi9THXWCWJdlG4YF1fOBlXzUQTCiJtK8ngGxtPCfj2CXihjas9S-5L1NeWYmL_0Hmf8AQVQNLxXufbFfgFsjlL1fEmj1Jn8qRwJi_RwKc8jklTrvNWmlpiD95a8s0w/w500-h474/Image3.jpg" width="500" /></a></div></div><div><b>Program in C#</b>:</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter
a string to check either it's Palindrome or not"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> statement = Console.ReadLine();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//variable to hold the reversed statement</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> reverseStatement = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">""</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Reverse the statement</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">for</span><span style="font-family: Consolas; font-size: 9.5pt;"> (</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> i=statement.Length-1;i>=0;i--) {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> reverseStatement +=
statement[i];<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Check statement and reverse statement are equal</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;">
(statement.Equals(reverseStatement, StringComparison.OrdinalIgnoreCase))<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"'{0}' is an example of Palindrome"</span><span style="font-family: Consolas; font-size: 9.5pt;">, statement);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"'{0}' is not an example of Palindrome"</span><span style="font-family: Consolas; font-size: 9.5pt;">, statement);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Console.ReadLine() to hold the screen after the execution of
the program</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.ReadLine();</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div><div><b>Output:</b></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8b6prf4jVuxWn1tV_oW02vGfLj-0HOx6lrsvf4E8RhYTwFggA7KG3wPT07QblpyAv3vnX2nlF0UL555PptamF5BMHbYZQlaEuV5ULdANSNsh_13UhXgnrnJnnBO9ELszxDu0i6WfXe54/s550/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="105" data-original-width="550" height="95" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8b6prf4jVuxWn1tV_oW02vGfLj-0HOx6lrsvf4E8RhYTwFggA7KG3wPT07QblpyAv3vnX2nlF0UL555PptamF5BMHbYZQlaEuV5ULdANSNsh_13UhXgnrnJnnBO9ELszxDu0i6WfXe54/w500-h95/Image1.jpg" width="500" /></a></div></div><div class="separator" style="clear: both; text-align: center;"><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiP9BE8oEtabJUPJxz3OJjK5TVnNggKpclSMYzaThz4hkZ66g4kH5eZW5UEyvUgE7DqIQHEO2K8kNl2yLHBYqH_HmYlQQ09QODLctcM7hvBIxZuLKwtHf89U1WjLe952N8Rg_3zKa6G3t8/s550/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="104" data-original-width="550" height="95" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiP9BE8oEtabJUPJxz3OJjK5TVnNggKpclSMYzaThz4hkZ66g4kH5eZW5UEyvUgE7DqIQHEO2K8kNl2yLHBYqH_HmYlQQ09QODLctcM7hvBIxZuLKwtHf89U1WjLe952N8Rg_3zKa6G3t8/w500-h95/Image2.jpg" width="500" /></a></div></div><div><b><br /></b></div><div><b>2. Break string to array and reverse the string</b></div><div>Another and easiest way to check the palindrome is to convert the string to the char array and then reverse the array with Array.Reverse() method. Once the array is reversed, convert it back to the string as shown in the below example. Once the string is reversed, compare it (ignore case while comparing string) with the original string entered by the user.</div><div><b>Program in C#:</b></div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter
a string to check either it's Palindrome or not"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> statement = Console.ReadLine();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//variable to hold the reversed statement</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> reverseStatement = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">""</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Convert the string to the Char Array</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Char[] charArr = statement.ToCharArray();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Reverse the Array</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Array.Reverse(charArr);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Convert the character array to string</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">reverseStatement = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;">(charArr);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Check statement and reverse statement are equal</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;">
(statement.Equals(reverseStatement, StringComparison.OrdinalIgnoreCase))<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"'{0}' is an example of Palindrome"</span><span style="font-family: Consolas; font-size: 9.5pt;">, statement);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"'{0}' is not an example of Palindrome"</span><span style="font-family: Consolas; font-size: 9.5pt;">, statement);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Console.ReadLine() to hold the screen after the execution of
the program</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.ReadLine();</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div>Preview:
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN0a5QluDeL7_wc2Q55eFN67Lrjetx007x__rd9e8UzMn_0lTVf1fxGvUY3y74DESLMfSOsKgiV9lS3gVf079fr1uPrYqHVPJKy5K47nJMnc8qKMVL55JrOGBuffYdDrXmi1KiNL5jp2g/s550/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="105" data-original-width="550" height="95" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN0a5QluDeL7_wc2Q55eFN67Lrjetx007x__rd9e8UzMn_0lTVf1fxGvUY3y74DESLMfSOsKgiV9lS3gVf079fr1uPrYqHVPJKy5K47nJMnc8qKMVL55JrOGBuffYdDrXmi1KiNL5jp2g/w500-h95/Image1.jpg" width="500" /></a></div></div><div><br /></div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPiUEMjSKb0_OpzN2P22Ydx4huEQxQEQFAtYByWXgXtA5xfwim-bQUDf8PYsWdmOj_AHI1Z9af0jeNprHQkPBDYqG9kCFOjmNLGALUHSyBoonDkEbF7sZMOSbC3jrpp-s97b3PeRvKddU/s550/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="104" data-original-width="550" height="95" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPiUEMjSKb0_OpzN2P22Ydx4huEQxQEQFAtYByWXgXtA5xfwim-bQUDf8PYsWdmOj_AHI1Z9af0jeNprHQkPBDYqG9kCFOjmNLGALUHSyBoonDkEbF7sZMOSbC3jrpp-s97b3PeRvKddU/w500-h95/Image2.jpg" width="500" /></a></div></div><div>I hope this program will help you in your interview/exam.</div><div>Thanks</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s234/cs-wh-234x16.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div><div><br /></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-1517062795838899962020-09-09T12:54:00.000-07:002020-09-09T12:54:18.341-07:00Program to find factorial of a number in C#<p>In this blog, we are going to learn How to find factorial of a positive number or integer in C#. As we know that we can find the factorial of a number in multiple ways, out of which I am going to share two ways i.e. with and without the use of recursion.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5ElK8igR2rO3QV8YFrHELaM66LyrxNpn6ao_wFt0YO42ggES7IHE8Q5luQwUUCqi-bqayhOHnu4QXVieQiqbQ8wPAWLmCqjj284tYWoMICoWaSWp_uttEm3wpioabcAiBMN0w0K2Jy4s/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5ElK8igR2rO3QV8YFrHELaM66LyrxNpn6ao_wFt0YO42ggES7IHE8Q5luQwUUCqi-bqayhOHnu4QXVieQiqbQ8wPAWLmCqjj284tYWoMICoWaSWp_uttEm3wpioabcAiBMN0w0K2Jy4s/w500-h226/Cover.jpg" width="500" /></a></div></div><div><b>Program to find factorial of a number without using recursion:</b></div><div>In mathematics, factorial is the product of all positive numbers or integers less than or equal to the number.</div><div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH2loP9kKtjPmE3TzmMxn2EvfgLpWned6ERSY5-qCihpZcTfAp0WZXoqJNHxIY5sD5r76dlRSu31Rr10v1y_45iJNwQYW0YboImeIy2v5vX8cRPkkUAkLHCf9SpGbgcV4Tt5160tW8lKo/s550/image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="171" data-original-width="550" height="155" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjH2loP9kKtjPmE3TzmMxn2EvfgLpWned6ERSY5-qCihpZcTfAp0WZXoqJNHxIY5sD5r76dlRSu31Rr10v1y_45iJNwQYW0YboImeIy2v5vX8cRPkkUAkLHCf9SpGbgcV4Tt5160tW8lKo/w500-h155/image3.jpg" width="500" /></a></div></div><b>Program:</b></div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> number, factorial;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter
a number to calculate its Factorial"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Recieve input from user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">number = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;">.Parse(Console.ReadLine());<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//set factorial value as we will start loop from number-1</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">factorial = number;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Multiply the factorial value till i becomes 1</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">for</span><span style="font-family: Consolas; font-size: 9.5pt;"> (</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> i=number-1;i>=1;i--) {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> factorial = factorial
* i;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Display the output to the user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Factorial
of "</span><span style="font-family: Consolas; font-size: 9.5pt;"> + number + </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">" is:
"</span><span style="font-family: Consolas; font-size: 9.5pt;"> + factorial);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Console.ReadLine() to hold the screen after the execution of
the program</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.ReadLine();</span><o:p></o:p></p>
</td>
</tr>
</tbody></table><p>Output:</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmBk8uzbQZoxxJaxQgsA-dvsGVvvgtgzAMBM7B6cLada2J8V16AIuMxf15_8Q9y8xjROF0fuBO3lncfGjubgwgM2bY60ZAgCLjQbkG_N3udmKd2dwxmyE_qY2yv4VPvXOX35zQdDv7U4c/s550/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="108" data-original-width="550" height="99" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmBk8uzbQZoxxJaxQgsA-dvsGVvvgtgzAMBM7B6cLada2J8V16AIuMxf15_8Q9y8xjROF0fuBO3lncfGjubgwgM2bY60ZAgCLjQbkG_N3udmKd2dwxmyE_qY2yv4VPvXOX35zQdDv7U4c/w500-h99/Image1.jpg" width="500" /></a></div></div><div><b>Program to find the factorial of a number with the use of recursion:</b></div><div>A recursive function is a function that calls itself inside the function.</div><div><b>Program</b>:</div><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">Program</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> //CalculateFactorial
method</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> CalculateFactorial(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> number) <o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//If number
becomes it will return 1 and recursion will stop</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (number == 1)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> 1;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Calling
CalculateFactorial method (Recursion)</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> number * CalculateFactorial(number - 1);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;"> static</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">void</span><span style="font-family: Consolas; font-size: 9.5pt;"> Main(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;">[] args)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> number;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter a number to calculate its Factorial"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Recieve input from user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> number = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;">.Parse(Console.ReadLine());<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (number > 0)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Program objProgram = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> Program();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Calling CalculateFactorial method</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> factorial =
objProgram.CalculateFactorial(number);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Display the output to the user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Factorial of
"</span><span style="font-family: Consolas; font-size: 9.5pt;"> + number + </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">" is:
"</span><span style="font-family: Consolas; font-size: 9.5pt;"> + factorial);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Number must be greater than zero"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Console.ReadLine() to hold the screen after the execution of
the program</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
Console.ReadLine();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">}</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div><p>Output:</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigsm-VHQtAJN8Jno4ItiqPNsJuZ8trVU8InkEyI6d982SI5120e1Kiv1MEr_-X7LHcBPKUXTVuf9zGvizvJRxq-2BPgG52bAWNJaLPKMAHdnsq834lllBGoDQLVpksjAa01WQUJPfEfMY/s550/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="94" data-original-width="550" height="86" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigsm-VHQtAJN8Jno4ItiqPNsJuZ8trVU8InkEyI6d982SI5120e1Kiv1MEr_-X7LHcBPKUXTVuf9zGvizvJRxq-2BPgG52bAWNJaLPKMAHdnsq834lllBGoDQLVpksjAa01WQUJPfEfMY/w500-h86/Image2.jpg" width="500" /></a></div></div><div>I hope this blog will help you in cracking your interview/exam.</div><div>Thanks. </div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s234/cs-wh-234x16.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div><div><br /></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0tag:blogger.com,1999:blog-9007498371541427085.post-22642401548719617812020-09-07T09:39:00.000-07:002020-09-07T09:39:13.487-07:00Program to find the occurrence of the character in a string in C#<p>In some interviews or exams, a problem is provided to the interviewee or student to find out the occurrence of the character in a string. In this example, I will help you in solving that problem/program with the easiest approach.</p>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKa6m-V51I_h93bf9NEv-cfqIdagcYuCImjEL6XL0hE3hFNGak35hCuaXTbqYbu3IiFxJO706gqGc1hC7gqa-6wCrLMVsmR705yXBw5TN8bKjeDJPMZv8dPkkyMkczVuoFkO6uMCzWR-Q/s550/Cover.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="250" data-original-width="550" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKa6m-V51I_h93bf9NEv-cfqIdagcYuCImjEL6XL0hE3hFNGak35hCuaXTbqYbu3IiFxJO706gqGc1hC7gqa-6wCrLMVsmR705yXBw5TN8bKjeDJPMZv8dPkkyMkczVuoFkO6uMCzWR-Q/w500-h226/Cover.jpg" width="500" /></a></div></div><div><span><a name='more'></a></span></div><div><b>Program to find the occurrence of the character in a string</b></div><div>Let’s follow the process shown in the below image. As C# in the case-sensitive language, I am converting the string to the lowercase string so that I can compare the characters otherwise capital character and small alphabetical character will be treated as different characters.</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsHtLFmlHy8lNqBSfuogBbWCATJq1U4jA1a9c2ySXPuKkbawp9k5fBq_KEsCrbNMlmSTClFAWWyrJjVppiLgPJRlzkZC4nyTR0OJ30f05XZuPOI38V1AZwUUQ2ZHCV6YqO3cQ41H72cp4/s550/Image3.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="460" data-original-width="550" height="419" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsHtLFmlHy8lNqBSfuogBbWCATJq1U4jA1a9c2ySXPuKkbawp9k5fBq_KEsCrbNMlmSTClFAWWyrJjVppiLgPJRlzkZC4nyTR0OJ30f05XZuPOI38V1AZwUUQ2ZHCV6YqO3cQ41H72cp4/w500-h419/Image3.jpg" width="500" /></a></div></div><b>Program to find the occurrence of the character in a string in C# is provided below:</b><br /><div><table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody><tr>
<td style="border: 1.5pt solid rgb(68, 114, 196); mso-border-themecolor: accent1; padding: 0cm 5.4pt; width: 450.8pt;" valign="top" width="601">
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> Statement = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">""</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.WriteLine(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Enter
a string to find number of Occurrence of a character"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Statement = Console.ReadLine();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Converting the Statement to lowercase which help in counting
of the character in the string</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//As C# is Case-Sensitive</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">Statement = Statement.ToLower();<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Check the length of string entered by the user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (Statement.Length>0) {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Iterate till length of statement is greater than zero </span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Here we check each character occurrence </span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Once count is checked, we will remove that character from the
string</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">while</span><span style="font-family: Consolas; font-size: 9.5pt;"> (Statement.Length > 0)<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//CountCharacter to store the character occurrence</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> CountCharacter = 0;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Console.Write(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"Number of Occurance of '"</span><span style="font-family: Consolas; font-size: 9.5pt;">+Statement[0] + </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"': "</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Checking the Character occurrence in the string entered by the
user</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">for</span><span style="font-family: Consolas; font-size: 9.5pt;"> (</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> i=0;i<Statement.Length;i++) <o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (Statement[0]==Statement[i]) <o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> CountCharacter++;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Displaying the Count of each character</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">
Console.Write(CountCharacter+</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">"\n"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Removing that character from the string</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;"> Statement =
Statement.Replace(Statement[0].ToString(), </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">string</span><span style="font-family: Consolas; font-size: 9.5pt;">.Empty);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm; mso-layout-grid-align: none; text-autospace: none;"><span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas;">//Console.ReadLine() to hold the screen after the execution of
the program</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height: normal; margin-bottom: 0cm;"><span style="font-family: Consolas; font-size: 9.5pt;">Console.ReadLine();</span><o:p></o:p></p>
</td>
</tr>
</tbody></table></div><div><b>Output</b>:</div>
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg73xCSlRkKyMbxPqVFGmZQAgaTGvFiCPRbNtmnIO2Yr6Fvh2SYqDtqzqD8gTaMA9ZJL74TSTnw2RoODplRBnIbDCtpDptvuIKucg9tYdY_6U_nneyafYTOudJMBATGK1xgg0zIgPlWG1k/s550/Image1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="257" data-original-width="550" height="235" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg73xCSlRkKyMbxPqVFGmZQAgaTGvFiCPRbNtmnIO2Yr6Fvh2SYqDtqzqD8gTaMA9ZJL74TSTnw2RoODplRBnIbDCtpDptvuIKucg9tYdY_6U_nneyafYTOudJMBATGK1xgg0zIgPlWG1k/w500-h235/Image1.jpg" width="500" /></a></div></div><br />
<div style="border: 1px dashed black; padding: 10px;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2lZdgYWzmSav5q9YX8wNy7JtxGAy5bMGw5UhpAYPRSdhpEOlBZBfH9dO_wHoXe_PtVoHROPkoCvCsjNxK9tkhTXWwPMIgfqP5FSI152GbKzjhDZnW-BUJ4XQWx9dngC2jRj3TyNvvdEY/s550/Image2.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="319" data-original-width="550" height="291" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2lZdgYWzmSav5q9YX8wNy7JtxGAy5bMGw5UhpAYPRSdhpEOlBZBfH9dO_wHoXe_PtVoHROPkoCvCsjNxK9tkhTXWwPMIgfqP5FSI152GbKzjhDZnW-BUJ4XQWx9dngC2jRj3TyNvvdEY/w500-h291/Image2.jpg" width="500" /></a></div></div><div>I hope this example will help in your interview/exam preparation.</div><div>Thanks</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s234/cs-wh-234x16.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="16" data-original-width="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgASmbT7b5Q8qM2SIJgW7rQJH3ekgNfzkeEelAB8aUoyCTXUXBC3112OvnfTY9ONDhl7pe_YSOokOhlK9cv0EMtfwmQ3j3exg1Dn8CLR-bAGLueH1IY6oZ3hIWaIOrGXX3ElBoxXPsPMFA/s16000/cs-wh-234x16.gif" title="Protected by Copyscape - Do not copy content from this page." /></a></div>Anoop Kumar Sharmahttp://www.blogger.com/profile/18341676319746374761noreply@blogger.com0