Skip to main content

Posts

Step by step guide to fix Angular app refresh issue in IIS

If you deploy your Angular app in IIS, routing will be handled from the client. So when you refresh a page it will give you 404 error. To get ride of the above-mentioned situation we have to follow the steps as follows: Before deploying anything on IIS, you have to install the URL Rewriting module on the IIS server. Please refer the link. After the installation, you should be seeing the following icon. If you are above to deploy an Angular app when is developed with ASP.Net Core. That deployment steps are explained in my previous blog post . That blog spot explains one issue I came across when I was deploying Angular 7 App with ASP.Net Core in IIS. So now we are done with IIS side installation next, we have to check the deployment files. You have to make sure that web.config file. web.config should contain the followings: <?xml version=”1.0" encoding=”UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> ...

Generic Repository with Entity Framework Core

Recently I worked on a project with ASP.NET Core which uses Entity Framework Core. With them, I used a generic repository pattern in the data layer. Repository interface was like below: using System; using System.Collections.Generic; using System.Linq.Expressions; using OnlineSurvey.Models; namespace OnlineSurvey.Data { public interface IRepository<T> where T : BaseEntity { T GetById(int id, params Expression<Func<T, object>>[] includExpressions); void Add(T entity); void Delete(T entity); void Delete(int id); IEnumerable<T> GetAll(params Expression<Func<T, object>>[] includExpressions); IEnumerable<T> Find(Expression<Func<T, bool>> where); int Count(); } } And the implementation was like below: using System; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Collections.Generic; using Syste...

An error occurred while starting the application in ASP.NET Core on IIS

I got this following error when I hosted my ASP.NET Core 2.2 web API on IIS. An error occurred while starting the application. .NET Core 4.6.27317.07 X64 v4.0.0.0 | Microsoft.AspNetCore.Hosting version 2.2.0-rtm-35687 (Please ignore the version numbers. Just wanted to show the error as it was.) So my first step was to change the  stdoutLogEnabled=true in web.config,  but couldn't find the logs folder. Few mins later I learnt that the  AspNetCoreModule   doesn’t create the logs folder for you by default (Hope they will fixed soon). It logs the error to the Event Viewer which says: Warning: Could not create stdoutLogFile  Path\logs\stdout_xxxxx.log, ErrorCode = -2147024893 . So, I created the the logs folder manually and here I find the real reason why it is failing. Hope this will help you guys.

503 Service Unavailable when deploy ASP.NET CORE 2.2 Angular 7 app in ISS

Currently, I'm working on an ASP.NET CORE 2.2 based project. So, I wanted to host in IIS, which is on Windows Server 2012 R2 system. So, I followed the following steps: Installed the latest version of . NET Core Runtime & Hosting Bundle for Windows. Which you can find in this. Created the application pool with .NET CLR Version: No Manged Code Then created the web application pointing to that application pool. But it was not working, and it started giving me 503 Service Unavailable error. The most important thing is, it was not only for this the web application that I created, but it was also for all the application hosted in this server. When I investigated more I found the following error in Event Viewer: Error logged in Event viewer After looking around for some time, I came to know that the ASP.NET Core/.NET Core: Runtime & Hosting Bundle (latest versions) depends on Microsoft Visual C++ 2015 Redistributable . Even while install...

Common Design Principles

There are number of common design principles that, like design patterns, best practice over the years to build maintainable software. I'm up to describe some widely used design principles though out the post. Following common principle are extracted by the same book that I mentioned before ( Professional ASP.Net Design Patterns - Scott Millet ). Principles are as follows: Keep It Simple Stupid (KISS) One common issue in software programming is over-complicating a solution. So main concern of this principle is keep the code simple but not simplistic. Eventually this will avoid unnecessary complexities. Don't Repeat yourself (DRY) Main concern of this principle is to avoid the repetition. In other words this is all about abstracting out the common functionalities into a single place. Ex: If there is a price calculation method in a system. It should lay in a single place there. Tell Don't Ask The Tell, Don’t Ask principle is closely aligned with encapsulation and the assignin...

S.O.L.I.D Design Principles

Hold on!!! Before this please read the common design principle post. After a long time thought of writing a post. Actually these days I'm reading a book which is written by Scott Millet and the name of the book is "Professional ASP.Net Design Patterns". I can guarantee that this book give you a great knowledge on design stuffs. Most of us are bit lazy to read things, so I thought of posting the things that I got form it. This is like the cream of what I got. I'll start it with the S.O.L.I.D design principles: The term S.O.L.I.D. comes from the initial letter of each of the five principles that were collected in the book Agile Principles, Patterns, and Practices in C# by Robert C. Martin, or Uncle Bob to his friends. Simply this is a collection of best practices for object-oriented design. Following will explain all the principles: Single Responsibility Principle (SRP) This principle is closely aligned with a common design principle called Separation of Concerns. It ...

LINQ : Query expression vs Lambda Expression

All the time I was using LINQ on projects I was wondering whether there is a performance difference between query expression and lambda expression. So I decided to dig into it. I wanted to examine MSIL for both of these situations. I wrote small class which has two methods. One is using query expression and the other one is using lambda. I complied this code and got the dll and view the MSIL using ildasm.exe. This following picture will show you the MSIL of GetFirst() method. And this following picture will show you the MSIL of the GetSecond() method. Yes!!! you can see that there is no different between these 2 MSIL. Will there be a performance difference???

reCAPTCHA for ASP.NET

I was looking for this reCAPTCHA recently and this is what I found on my way. Hope this will help you in someway. To get an idea about reCAPTCHA watch the following video and the following link will explain you how to implement it in your ASP.net web site. reCAPTCHA for ASP.NET

Exit a T-SQL Cursor When Condition is met

Have you ever wanted to exit from a cursor when a condition is met? I wanted to do it. So this is how I did it. DECLARE @Field1 AS INT DECLARE @Field2 AS INT DECLARE CursorName CURSOR READ_ONLY FOR SELECT Field1, Field2 FROM TableName OPEN CursorName FETCH NEXT FROM CursorName INTO @Field1, @Field2 WHILE @@FETCH_STATUS = 0 BEGIN IF @Field1 = 1 BEGIN GOTO ENDCURSOR END FETCH NEXT FROM CursorName INTO @Field1, @Field2 END ENDCURSOR: CLOSE CursorName DEALLOCATE CursorName I have set my fonts to bold where you want to notice. So that's all I hope you will get something out of it and it is true that this is not a big deal. :)

Populate Modal popup data which is bind to a link button - ASP.net

I wanted to do a POC to my client to show modal popup functionality. So I did a simple page with one Button and a TextBox. That Button is responsible to popup the modal window. On that ModalPopup I implemented a search mechanism. I used Girdview control to show the search result. I wanted to populate the id value of that search result which was binded to a link button. This gridview and the text box and button was in a AJAX update panel control. I did this because I wanted to have the smothness of the UI. Now I met a new problem. Because I wanted to get that value out of that LinkButton control and show it in a TextBox control which was out of the ModalPopup. So what I did was, I just assign that LinkButton's text property to a HiddenField and I used a JavaScript function to populate that HiddenField value the TextBox. As you all know we need a Panel control to show our ModalPopup. This is gonna be a <div> on the HTML. So I used the onblur event to call my JavaScript functi...

Programmatically add the META tags to an ASP.NET page

Do you want to programmatically add the META tags to an ASP.NET page? You can try to the below code: HtmlMeta metaDesc = new HtmlMeta(); metaDesc.Name = "description" ; metaDesc.Content = "Your Description goes here" ; Page.Header.Controls.Add(metaDesc); HtmlMeta metaKey = new HtmlMeta(); metaKey.Name = "keywords" ; metaKey.Content = "Your keywords here" ; Page.Header.Controls.Add(metaKey);

Adding a separator image to ASP.Net Menu Control

This what I did to add a separator to ASP.Net menu. I used Web.sitemap to bind the data to menu control. This how Web.sitemap looks like. <sitemap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"> <sitemapnode> <sitemapnode url="~/Pages/DatingHome.aspx" title="Home" description="" separatorImageUrl="../../Images/but_blueSlice.jpg"> <sitemapnode url="~/Pages/Inbox.aspx" title="Inbox" description="" separatorImageUrl="../../Images/but_blueSlice.jpg"> </sitemapnode> </sitemapnode> This separatorImageUrl will tell you the image path of the separator. This event handler will do the rest of it. protected void Menu2_MenuItemDataBound(object sender, System.Web.UI.WebControls.MenuEventArgs e) { SiteMapNode smNode = (SiteMapNode)e.Item.DataItem; if (smNode["seperatorImageUrl"] != null) e.Item.SeparatorImageUrl = smNode[...

How to configure SQL Server Session State with Custom Database

There are two steps got to follow to enable the SQL Server Session state to work 1. Configuring the database to support the SQL Server Session state. 2. Configuring your application to use SQL Server Session state. 1. Configuring the database to support the SQL Server Session state. .Net framework has a tool aspnet_regsql which you can use to add the table and stored procedure to support SQL Server Session state. You can find this tool in the following folder. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ aspnet_regsql.exe You can run this exe from window command prompt or you can directly run from SDK Command prompt. Executing the following command enables SQL Server Session state for a database server named local and store it in a custom database called CustomSessionDB. aspnet_regsql -C "Data Source=local;User Id=sa; Password=Sql2005" -ssadd -sstype c -d CustomSessionDB Executing this command creates a new database named CustomSessionDB that contains bot...

Simulate Table Lock situation using a Select statement - SQL Server 2005

Today I wanted simulate a table lock situation in my database using a select statement. It was bit hard for me to do it. I was searching it in web, but couldn't find useful thing. May be I didn't do it in right way. ;) Anyway I could do it. This is how I did it. You can write your SQL statement with (TABLOCKX) at the end of SQL statement. ex: Select * From table_name (TABLOCKX) I assume you all know how to do the rest of it.

How to use DataBinder.Eval in HyperLink NavigationUrl - ASP.net

I wanted to append page Url with DataBinder.Eval value in ASP.NET hyperlink control on ASP.NET HTML source. I was trying it using many ways and also search for resources on web but I could not find any useful thing. I thought this will help u guys to get an idea about appending two strings. Solution as follows. <asp:HyperLink ID="customerHyperLink" runat="server" Text= ' ' NavigateUrl=' ' ></asp:HyperLink> You can see how I have appended these two value in NavigateUrl property. Hope some one will get the advantage of this post.

How To Implement Forms-Based Authentication in Your ASP.NET Application by Using C# .NET

These days I was so busy to find how to Implement form based authentication in my ASP.net application. I was looking for a resource that I can use on web. I found some and most of them are not that easy to understand. So I though to write an article so then any one can read and get the basic idea from it. I will first explain what is my scenario. I have my own database table to keep user credentials. So I wanted to use it to authenticate the users who are trying to log in. This has nothing more than configuring your Web.config and writing few codes authenticate the user. If you have your own database table to keep user credential, obviously you have a method written to authenticate. We can use this method to validate user and based on the results of this method you can do the authentication part. These are the configuration lines that you have to put in to our Web.config. <authentication mode="Forms"> <authentication mode="Forms"> <forms login...

How To: Use Forms Authentication with Active Directory in ASP.NET 2.0

This post will show you how to use forms authentication with Microsoft Active Directory directory service by using the ActiveDirectoryMembershipProvider . To create a Web application with a logon page Start Microsoft Visual Studio® .NET development system, and then create a new ASP.NET Web site called FormsAuthAD. Use Solution Explorer to add a new Web form to the site called Login.aspx. Add a Login control to Login.aspx. By default, this control displays a user name field, a password field, and a Remember me next time checkbox. If the user selects this checkbox, a persistent authentication cookie is created and the user's browser stores the cookie on the user's computer. For security reasons, you should avoid creating persistent authentication cookies; therefore, disable this feature by setting the DisplayRememberMe property of the Login control to false . Note that when a user clicks Login on the Login control, it automatically validates the user by calling the con...