{"id":69882,"date":"2021-08-21T15:30:42","date_gmt":"2021-08-21T19:30:42","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/random-notes-and-simple-code-on-developing-web-sites-applications-in-asp-net-using-c-19\/"},"modified":"2025-05-11T20:18:22","modified_gmt":"2025-05-11T20:18:22","slug":"random-notes-and-simple-code-on-developing-web-sites-applications-in-asp-net-using-c-19","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=69882","title":{"rendered":"Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# #19"},"content":{"rendered":"<p><strong>Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C#<\/strong><\/p>\n<ul>\n<li> The information below primarily apply to the web page model of web-development in C#        <\/li>\n<li> _PageStart.cshtml runs at each page start\/open    <\/li>\n<li> _AppStart.cshtml runs at the beginning of the application <\/li>\n<li> Syntax to use the Layout file: @{Layout = &#8220;\/Shared\/Layout.cshtml&#8221;;}   <\/li>\n<li> if you use this &#8211; @{Layout = \/Shared\/Layout.cshtml&#8221;;} in the _PageStart.cshtml file, you will not need to use it at the top of each file        <\/li>\n<li> You can use Microsoft Webmatrix, Visual Web Developer, or Visual Studio for web development        <\/li>\n<li> Webmatrix, includes IIS Express, and also a database workspace where you can create and use compact SQL Server Databases        <\/li>\n<li> DateTime.Now : will display current date and time        <\/li>\n<li> You can connect to a database using var db = Database.Open(&#8220;db_name&#8221;);    <\/li>\n<li> db = Database.Open(&#8220;db_name&#8221;); will look for the database in the same workspace; if not found will use the connection parameter as defined in the web.config file to find and connect to database        <\/li>\n<li> Executing a query: var queryString = &#8220;SELECT * FROM Product ORDER BY Name&#8221;; db.Query(queryString)        <\/li>\n<li> Accessing each row from a rowset of data as returned from database:\n<pre>               foreach(var entry in db.Query((queryString))){                @entry.Id, @entry.Name            }               <\/pre>\n<\/li>\n<li> if (IsPost) : will check if a form is submitted by POST or not       <\/li>\n<li> username = Request.Form[&#8220;username&#8221;]; Will retrieve username from the Request object [submitted form with control named username] <\/li>\n<li> A basic login authentication code can be as follows\n<pre>           var username = \"\";      var password = \"\";      var ErrorMessage = \"\";              \/\/ If this is a POST request, validate and process data     if (IsPost){                        username = Request.Form[\"username\"];            password = Request.Form[\"password\"];                        if (username.IsEmpty() || password.IsEmpty()){              ErrorMessage = \"You must specify a username and password.\";         }else{              \/\/ Login, Navigate back to the homepage and exit                if (WebSecurity.Login(username, password, false)){                  Response.Redirect(\"~\/\");                }               else{                   ErrorMessage = \"Login failed\";              }           }       }                                       @if (ErrorMessage!=\"\") {            @ErrorMessage, Please correct the errors and try again.     }   <\/pre>\n<\/li>\n<li> Execute an Insert Statement: db.Execute(&#8220;INSERT INTO UserProfile (Email) VALUES (@0)&#8221;, email);    <\/li>\n<li> WebSecurity object can be used for the security of your web-site (application) such as user authentication, block a page until a user is authenticated    <\/li>\n<li> Block user if he is not logged in [can be added at the top of the page to be blocked]\n<pre>           @{              if (!WebSecurity.IsAuthenticated) Response.Redirect(\"~\/Login\"); \/\/redirect to login page            }       <\/pre>\n<\/li>\n<li> WebSecurity.InitializeDatabaseConnection(&#8220;db_name&#8221;, &#8220;profile_of_the_users_table&#8221;, &#8220;UserId&#8221;, &#8220;Email&#8221;, true);   <\/li>\n<li> WebSecurity.CreateAccount(email, password, false);<\/li>\n<\/ul>\n<p>From: http:\/\/sitestree.com\/?p=5298<br \/> Categories:19<br \/>Tags:<br \/> Post Data:2012-01-30 09:33:18<\/p>\n<pre><code>    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\"&gt;https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    (Big Data, Cloud, Security, Machine Learning): Courses: &lt;a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"&gt; http:\/\/Training.SitesTree.com&lt;\/a&gt; \n    In Bengali: &lt;a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\"&gt;http:\/\/Bangla.SaLearningSchool.com&lt;\/a&gt;\n    &lt;a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\"&gt;http:\/\/SitesTree.com&lt;\/a&gt;\n    8112223 Canada Inc.\/JustEtc: &lt;a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\"&gt;http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) &lt;\/a&gt;\n    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com'&gt; https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    Medium: &lt;a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"&gt; https:\/\/medium.com\/@SayedAhmedCanada &lt;\/a&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# The information below primarily apply to the web page model of web-development in C# _PageStart.cshtml runs at each page start\/open _AppStart.cshtml runs at the beginning of the application Syntax to use the Layout file: @{Layout = &#8220;\/Shared\/Layout.cshtml&#8221;;} if you use this &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=69882\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1973,1917],"tags":[],"class_list":["post-69882","post","type-post","status-publish","format-standard","hentry","category-c-misc","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":70283,"url":"http:\/\/bangla.sitestree.com\/?p=70283","url_meta":{"origin":69882,"position":0},"title":"Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"August 31, 2021","format":false,"excerpt":"Brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1319&title=Random%20Notes%20and%20simple%20code%20on%20Developing%20Web%20Sites%20(Applications)%20in%20ASP.net%20using%20C# And sure, pretty old article.. Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# The information below primarily apply to the web page model of web-development in C# _PageStart.cshtml runs at each page start\/open _AppStart.cshtml runs at the beginning of the application\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70285,"url":"http:\/\/bangla.sitestree.com\/?p=70285","url_meta":{"origin":69882,"position":1},"title":"Razor, Web-page Model, Web-Application Development in C# #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"August 31, 2021","format":false,"excerpt":"Brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1320&title=Razor,%20Web-page%20Model,%20Web-Application%20Development%20in%20C# (written long back) Razor, Web-page Model, Web-Application Development in C# Razor:a markup syntax to add server side code into ASP.net pages Razor example: Current time is @DateTime.Now Razor Code Syntax Single statement block @{ var message = \"Hello World\"; } Inline expression or variable The message: @message\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":69884,"url":"http:\/\/bangla.sitestree.com\/?p=69884","url_meta":{"origin":69882,"position":2},"title":"Razor, Web-page Model, Web-Application Development in C# #19","author":"Author-Check- Article-or-Video","date":"August 21, 2021","format":false,"excerpt":"Razor, Web-page Model, Web-Application Development in C# Razor: a markup syntax to add server side code into ASP.net pages Razor example: Current time is @DateTime.Now Razor Code Syntax Single statement block @{ var message = \"Hello World\"; } Inline expression or variable The message: @message Multi-statement block @{ var greeting\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78356,"url":"http:\/\/bangla.sitestree.com\/?p=78356","url_meta":{"origin":69882,"position":3},"title":"Modes of Session State Management","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"By AI: Here are the 5 modes to store Session State in ASP.NET, each with its own storage location and behavior. This is especially useful for configuring ASP.NET (Framework) Web Forms or MVC applications \u2014 though some modes also apply to ASP.NET Core with slight differences. You can copy and\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70303,"url":"http:\/\/bangla.sitestree.com\/?p=70303","url_meta":{"origin":69882,"position":4},"title":"Creating your own Classes in C# in ASP.net #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"September 1, 2021","format":false,"excerpt":"Brought from our old site: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1348&title=Creating%20your%20own%20Class%20in%20C#%20in%20ASP.net Creating your own Class in C# in ASP.net It is kind of simple. You need to create a class library. The class library will create a dll file. From your project, you need to add reference to the dll file. Then you will be\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78358,"url":"http:\/\/bangla.sitestree.com\/?p=78358","url_meta":{"origin":69882,"position":5},"title":"Application State Variables in C#.net","author":"Sayed","date":"August 5, 2025","format":false,"excerpt":"Here\u2019s a clear, copyright-free explanation of Application State Variables in C#.NET, ideal for blogs, Facebook pages, or classroom notes. \ud83c\udf10 Application State Variables in C#\/.NET Application State in ASP.NET is a way to store global data that is shared by all users across the entire web application. It is commonly\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69882"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69882\/revisions"}],"predecessor-version":[{"id":78130,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69882\/revisions\/78130"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69882"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}