Core Q&A
Core Q&A
All rights reserved. No part of this book can be reproduced or stored in any retrieval system or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording, uploading on server and scanning without
the prior written permission of the Dot Net Tricks Innovation Pvt. Ltd.
The author of this book has tried their best to ensure the accuracy of the information described in this book.
However, the author cannot guarantee the accuracy of the information contained in this book. The author or Dot
Net Tricks Innovation Pvt. Ltd. will not be liable for any damages, incidental or consequential caused directly or
indirectly by this book.
Further, readers should be aware that the websites or reference links listed in this book may have changed or
disappeared between when this book was written and when it is read.
All other trademarks referred to in this book are the property of their respective owners.
Release History
• Initial Release 1.0 - 30th Nov 2018
• Second Release 1.1 - 4th Jan 2019
• Third Release 2.0 - 20th Dec 2019
1
Page
About Dot Net Tricks
Dot Net Tricks is founded by Shailendra Chauhan (Microsoft MVP), on Jan 2010. Dot Net Tricks came into existence
in the form of a blog post over various technologies including .NET, C#, SQL Server, ASP.NET, ASP.NET MVC,
JavaScript, Angular, Node.js and Visual Studio, etc.
The company which is currently registered by a name of Dot Net Tricks Innovation Pvt. Ltd. came into the shape
in 2015. Dot Net Tricks website has an average footfall on the tune of 300k+ per month. The site has become a
cornerstone when it comes to getting skilled-up on .NET technologies and we want to gain the same level of trust
in other technologies. This is what we are striving for.
We have a very large number of trainees who have received training from our platforms and immediately got
placement in some of the reputed firms testifying our claims of providing quality training. The website offers you
a variety of free study material in the form of articles.
• .NET Development
• Front-end Development
• Cloud
• DevOps
• Programming Languages
• Database - SQL and NoSQL
• Mobile Development
• ML/AI and many more...
Start your journey today to learn coding. Because learning to code is the first step and forward to advance your
career.
For a beginner who needs regular guidance, we have a fully packed Master Courses. They are almost equal to
semester courses taught in engineering colleges when it comes to length, breadth of content delivery, the only
difference instead of 5-6 months, they take approx. 6 weeks of live classes.
Corporate Training
Dot Net Tricks having a pool of mentors who help the corporate to enhance their employment skills as per
changing the technology landscape. Dot Net Tricks offers customized training programs for new hires and
experienced employees through online and classroom mode. As a trusted and resourceful training partner, Dot
Net Tricks helps the corporate to achieve success with its industry-leading instructional design and customer
training initiatives.
Apart from these, we also provide on-demand boot camps and personalized project consultation.
• .NET Development
• Front-end Development
• Cloud
• DevOps
• Programming Languages
• Database - SQL and NoSQL
• Mobile Development
• ML/AI and many more...
Technical Recruiting
We provide full technical staffing service which suits our client needs. Our technical recruiters search across the
world to find highly skilled professionals that will fit our clients need. If you are looking for a job change, do share
your resume at [email protected]. Dot Net Tricks will help you to find your dream job in MNCs.
4
Join us today, learn to code, prepare yourself for interviews, and get hired!
Page
Dedication
I would like to say many thanks to my mother Mrs Saryuben Trivedi and my wife Mrs Poorvi for their support.
They deserve to have their name on the cover as much as I do for all their support made this possible. I would also
like to say thanks to all my family members Girish Kumar Trivedi (father), Rakesh and Tejas (brother) for their
continuous guidance and support to achieve my goals.
-Jignesh Trivedi
5
Page
Introduction
What Where Author Qualification to Write This Book
Jignesh Trivedi is awarded as MVP by Microsoft for his exceptional contribution in Microsoft technologies under
the category "Developer Technologies" for the year 2016, 2017, 2018 and 2019. He has more than 12 years of
experience on Microsoft technologies such as ASP.NET, MVC, ASP.NET Core, TypeScript, Blazor, SQL server etc.
and other technologies such as Angular and AngularJS, HTML, CSS, jQuery etc.
He is also a blogger and author of articles on various technologies. He is also a speaker and delivered talk on
various technologies like ASP.NET Core, Angular, MVC etc. in the public events.
Our best wishes always with you for your learning and growth!
6
Page
About the Author
Jignesh Trivedi - An Author, Architect, and Microsoft MVP
Jignesh Trivedi is working as a software developer with a leading
organization and having more than 12 years of experience. He is very
passionate about the Microsoft Technologies. He is author, speaker and
MVP.
He loves building great products and POC (proof of concepts) using the
best available technologies. He loves to share his knowledge by
contributing to Developer community.
He always tries to keep updated himself about new technologies and learning new skills and shared with other
in simple manner. He hopes that this e-book helps you to crack interview of ASP.NET Core.
7
Page
How to Contact Us
Although the author of this book has tried to make this book as accurate as it possible but if there is something
strikes you as odd, or you find an error in the book please drop a line via e-mail.
• [email protected]
• [email protected]
We are always happy to hear from our readers. Please provide your valuable feedback and comments!
You can follow us on YouTube, Facebook, Twitter, LinkedIn and Google Plus or subscribe to RSS feed.
8
Page
Table of Contents
ASP.NET Core Interview Questions & Answers ............................................................... 1
Release History ...................................................................................................................................................1
About Dot Net Tricks ...........................................................................................................................................2
Dot Net Tricks Courses ........................................................................................................................................2
Dot Net Tricks Pro ...............................................................................................................................................2
Dot Net Tricks Live Training ................................................................................................................................4
Dot Net Tricks eBooks .........................................................................................................................................4
Technical Recruiting ............................................................................................................................................4
Dedication ...........................................................................................................................................................5
Introduction ........................................................................................................................................................6
About the Author ................................................................................................................................................7
How to Contact Us ..............................................................................................................................................8
Q4. Why Session is stored in the form of byte array in ASP.NET Core? ........................................................ 32
Page
Q5. Is there any sequence to call UseSession() method in the Configure method? ..................................... 32
Q6. Can we store the Complex data into the session? .................................................................................. 32
Q7. How does ASP.net core track user session? ............................................................................................ 33
Q8. Can we change the name of the cookie used for the session? ............................................................... 33
Q9. How can we maintain the app state in ASP.net core? ............................................................................ 33
Q10. How can we set an environment variable? ............................................................................................. 33
Q11. Key for environment variable is case-sensitive? ..................................................................................... 33
Q12. How determine the value of an environment variable programmatically? ............................................ 34
Q13. What are the various JSON files available in ASP.NET Core? .................................................................. 34
Q14. What is the use of “launchsettings.json” file? ........................................................................................ 34
Q15. What is the use of "appsettings.json" file? ............................................................................................. 34
Q16. What is the use of "bower.json" file? ...................................................................................................... 34
Q2. How many types of service containers available in ASP.NET Core? ....................................................... 58
Page
Q3. How can we inject the service dependency into the controller? ............................................................ 58
Q4. Can we inject the dependency to individual action method of the controller? ..................................... 59
Q5. Can we get a service instance without dependency injection in the controller action method?........... 59
Q6. How to specify a service life for register service that added as a dependency? .................................... 59
Q7. How can we inject the service dependency into the View?.................................................................... 60
Q8. What point you will be taken care while creating service for DI? ........................................................... 61
Q25. How can we enforce Https for all requests in ASP.net Core? ................................................................. 69
Page
Q26. Is there any alternative approach for enforcing Https other than injecting middleware? ..................... 69
Q27. How can we enable CORS in ASP.net core app? ..................................................................................... 70
Q28. How to prevent ASP.net Core app from Cross-Site Request Forgery (CSRF)? ........................................ 70
Deployment ................................................................................................................... 78
Q1. What are the different techniques for hosting an ASP.NET Core application?....................................... 78
Q2. What is Kestrel? ....................................................................................................................................... 78
Q3. How to add Kestrel server in ASP.NET Core application? ....................................................................... 78
Q4. Can we bind TCP socket with Kestrel server?.......................................................................................... 79
Q5. What is HTTP.sys server? ......................................................................................................................... 79
15
References ..................................................................................................................... 81
16
Page