{"id":70283,"date":"2021-08-31T04:10:08","date_gmt":"2021-08-31T08:10:08","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/random-notes-and-simple-code-on-developing-web-sites-applications-in-asp-net-using-c-net-web-applications\/"},"modified":"2025-05-11T20:17:27","modified_gmt":"2025-05-11T20:17:27","slug":"random-notes-and-simple-code-on-developing-web-sites-applications-in-asp-net-using-c-net-web-applications","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=70283","title":{"rendered":"Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# #.Net Web Applications"},"content":{"rendered":"<p>Brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&amp;articleID=1319&amp;title=Random%20Notes%20and%20simple%20code%20on%20Developing%20Web%20Sites%20(Applications)%20in%20ASP.net%20using%20C#<\/p>\n<p> And sure, pretty old article.. <\/p>\n<p>Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C#<\/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>               \nforeach(var entry in db.Query((queryString))) {\n   @entry.Id, @entry.Name\n}\n<\/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>   \n        var username = \"\";\n        var password = \"\";\n        var ErrorMessage = \"\";\n        \n        \/\/ If this is a POST request, validate and process data\n        if (IsPost){\n            \n            username = Request.Form[\"username\"];\n            password = Request.Form[\"password\"];\n            \n            if (username.IsEmpty() || password.IsEmpty()){\n                ErrorMessage = \"You must specify a username and password.\";\n            }else{\n                \/\/ Login, Navigate back to the homepage and exit\n                if (WebSecurity.Login(username, password, false)){\n                    Response.Redirect(\"~\/\");\n                }\n                else{\n                    ErrorMessage = \"Login failed\";\n                }\n            }\n        }\n                        \n        @if (ErrorMessage!=\"\") {\n            @ErrorMessage, Please correct the errors and try again.\n        }\n\n    <\/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>           \n                      @{\n            if (!WebSecurity.IsAuthenticated) Response.Redirect(\"~\/Login\"); \/\/redirect to login page\n            }\n        <\/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=3718<br \/> Categories:.Net Web Applications<br \/>Tags:<br \/> Post Data:2016-07-16 10:38:29<\/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>Brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&amp;articleID=1319&amp;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 Syntax to use the Layout &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=70283\">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-70283","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":69882,"url":"http:\/\/bangla.sitestree.com\/?p=69882","url_meta":{"origin":70283,"position":0},"title":"Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# #19","author":"Author-Check- Article-or-Video","date":"August 21, 2021","format":false,"excerpt":"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 =\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":70283,"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":70283,"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":70303,"url":"http:\/\/bangla.sitestree.com\/?p=70303","url_meta":{"origin":70283,"position":3},"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":70301,"url":"http:\/\/bangla.sitestree.com\/?p=70301","url_meta":{"origin":70283,"position":4},"title":"Simple Ajax Applications in C# (ASP.Net) #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"September 1, 2021","format":false,"excerpt":"Brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1347&title=Simple%20Ajax%20Applications%20in%20C#%20(ASP.Net) Simple Ajax Applications in C# (ASP.Net) Note:asmx web-service might be more appropriate in some\/many cases If you are coming from PHP or Java Platform where you use JavaScript or jQuery to provide Ajax functionality, you still can use those strategies in ASP.net to provide Ajax functionality Check\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":23002,"url":"http:\/\/bangla.sitestree.com\/?p=23002","url_meta":{"origin":70283,"position":5},"title":"File Downloading in C# Applications #Root #By Sayed Ahmed","author":"Author-Check- Article-or-Video","date":"March 23, 2021","format":false,"excerpt":"For ASP.Net web form applications, you can use [for file download] Synchronously using System.Net; WebClient webClient = new WebClient(); webClient.DownloadFile(\"http:\/\/mysite.com\/myfile.txt\", @\"c:myfile.txt\"); or Asynchronously private void btnDownload_Click(object sender, EventArgs e) { WebClient webClient = new WebClient(); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); webClient.DownloadFileAsync(new Uri(\"http:\/\/mysite.com\/myfile.txt\"), @\"c:myfile.txt\"); } private void ProgressChanged(object\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\/70283","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=70283"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70283\/revisions"}],"predecessor-version":[{"id":78121,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70283\/revisions\/78121"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70283"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}