European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

ASP.NET 4.6 Hosting - HostForLIFE.eu :: How to Edit value of RequiresQuestionAndAnswer in ASP.NET 4.6 Membership Provider

clock October 29, 2015 01:16 by author Peter

Let me show you how to edit value of RequiresQuestionAndAnswer in ASP.NET 4.6 Membership provider. RequiresQuestionAndAnswer is checked when ResetPassword or GetPassword is called. The provider provided with the .NET Framework throws a NotSupportedException if RequiresQuestionAndAnswer is true and the supplied password answer is null. Requiring a password question and answer provides an additional layer of security when retrieving or resetting a user's password. Users can supply a question and answer when their user name is created that they can later use to retrieve or reset a forgotten password.

A Membership Provider allows a web application to store and retrieve membership data for a user, and the standard ASP.NET Membership Provider uses pre-defined SQL Server tables.

Now you write the following example code:
MembershipUser user = Membership.GetUser();
string newPassword = "newPass";
string tempPassword = string.Empty;
if (Membership.Provider.RequiresQuestionAndAnswer)
{
var _requiresQA = Membership.Provider.GetType().GetField("_RequiresQuestionAndAnswer",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
//change the value in the private field
_requiresQA.SetValue(Membership.Provider, false);
//do the reset
tempPassword = user.ResetPassword();
//set it's original value
_requiresQA.SetValue(Membership.Provider, true);
}
else
{
tempPassword = user.ResetPassword();
}

HostForLIFE.eu ASP.NET 4.6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments. 



ASP.NET Hosting with Toronto Data Center - HostForLIFE.eu :: How To Convert A Password Into Complicated

clock October 27, 2015 00:22 by author Rebecca

In this tutorial, we will show you how to convert a password into complicated in ASP.NET. We will ise SHA1 or MD5 algorithm to work around for converting your password into complicated.

Follow these steps to make your password seems complicated in ASP.NET:

Step 1

Open Visual Studio and create an empty website. Give it a suitable name for example: [hashpass_demo].

Step 2

 In Solution Explorer you will get your empty website, then add a Web Form by going like this:

  • Right Click
  • Add New Item, then Web Form. Name it hashpass_demo.aspx.

Step 3

Now mcreate some design for your application by going to hashpass_demo.aspx and try the code like this:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server"> 
        <title></title> 
        <style type="text/css"> 
            .style1 
            { 
                width: 258px; 
            } 
            .style2 
            { 
                width: 239px; 
            } 
        </style> 
    </head> 
    <body> 
        <form id="form1" runat="server"> 
        <div> 
         
            <table style="width:100%;"> 
                <tr> 
                    <td class="style1"> 
                        Enter Your Username:</td> 
                    <td class="style2"> 
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
                    </td> 
                    <td> 
                        <asp:Label ID="Label2" runat="server"></asp:Label> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="style1"> 
                        Enter Your Password:  
                    </td> 
                    <td class="style2"> 
                        <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox> 
                    </td> 
                    <td> 
                        <asp:Label ID="Label1" runat="server"></asp:Label> 
                    </td> 
                </tr> 
                <tr> 
                    <td class="style1"> 
                         </td> 
                    <td class="style2"> 
                         </td> 
                    <td> 
                         </td> 
                </tr> 
                <tr> 
                    <td class="style1"> 
                         </td> 
                    <td class="style2"> 
                        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" /> 
                    </td> 
                    <td> 
                         </td> 
                </tr> 
            </table> 
         
        </div> 
        </form> 
    </body> 
    </html> 

Your design will look like following picture snippet:

Step 4

Now it’s time for server side coding so that our application starts working. Open your hashpass_demo.aspx.cs file and code it like below:

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.Security; 
     
    public partial class _Default : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
     
        } 
        protected void Button1_Click(object sender, EventArgs e) 
        { 
            string securepass = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "MD5"); 
            Label2.Text = "Your Username is-" + TextBox1.Text; 
            Label1.Text = "Your HashPassword is-" + securepass; 
            Label2.ForeColor = System.Drawing.Color.ForestGreen; 
            Label1.ForeColor = System.Drawing.Color.ForestGreen; 
       
        } 
    } 

Here is the output:

Good luck!

HostForLIFE.eu ASP.NET 4.6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments. 



ASP.NET 4.6 Hosting with Milan Data Center - HostForLIFE.eu :: How To Delete Duplicates Elements from List Using IEqualityComparer?

clock October 22, 2015 00:03 by author Peter

In this tutorial, let me show you how to delete duplicates elements from list using IEqualityComparer in ASP.NET 4.6. IEqualityComparer is implemented by classes that need to support an equality comparison for two values of the same type. Generic collections require instances of classes that implement the IEqualityComparer interface in order to provide support for custom data types. IEqualityComparer has two methods to support the comparison of objects for equality. Let us suppose that you have a Employee class that has four properties EmployeeID,FirstName,LastName and Age. Now, you need to write the following code:

public class Employee
{
public Employee()
{
}
public string EmployeeID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public List&lt;Employee&gt; Employees
{
    get
    {
return new List&lt;Employee&gt;()
        {
new Employee(){EmployeeID="01",FirstName="Peter",LastName="Last01",Age=31},
new Employee(){EmployeeID="02",FirstName="Scott",LastName="Last02",Age=35},
new Employee(){EmployeeID="03",FirstName="Rebecca",LastName="Last03",Age=36},
new Employee(){EmployeeID="01",FirstName="Paul",LastName="Last01",Age=31},
new Employee(){EmployeeID="01",FirstName="Richard",LastName="Last01",Age=31},
        };
    }
}
}

In the above class I have added some dummy records which have duplicates elements. Now,let's remove the duplicate elements from the above class using IEqualityComparer interface.  For this right click on the project and add a new class named EmployeeEquality and inherit this class with IEqualityComparer and write the below code:
public class EmployeeEquality : IEqualityComparer<Employee>
{
public bool Equals(Employee x, Employee y)
{
if (x.EmployeeID == y.EmployeeID && x.FirstName == y.FirstName && x.LastName == y.LastName && x.Age == y.Age)
return true;
return false;
}
public int GetHashCode(Employee obj)
{
//For shake of simplicity
return obj.FirstName.GetHashCode();
}
}


Now,let's display the record on UI. First, right click on the project and add new page,and add the below code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:Button ID="btnUnSorted" runat="server" OnClick="btnUnSorted_Click" Text="Duplicates" />
<asp:Button ID="btnWDuplicate" runat="server" OnClick="btnWDuplicate_Click" Text="Without Duplicate" />
</form>
</body>
</html>

In the code behind add following code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUnSorted_Click(object sender, EventArgs e)
{
    Employee employee = new Employee();
    GridView1.DataSource = employee.Employees;
    GridView1.DataBind();
}
protected void btnWDuplicate_Click(object sender, EventArgs e)
{
    Employee employee = new Employee();
    List<Employee> list = employee.Employees;
    var distinctEmployee = list.Distinct(new EmployeeEquality());
    GridView1.DataSource = distinctEmployee;
    GridView1.DataBind();
}
}

HostForLIFE.eu ASP.NET 4.6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments. 



ASP.NET 4.6 Hosting Germany - HostForLIFE.eu :: How to Use C# to Track an IP Address

clock October 5, 2015 18:25 by author Rebecca

In this tutorial, you will learn how to track an IP address in ASP.NET using C#.

In ASP.NET it is also very easy to find IP address no matter whether user is behind the proxy or not, you can easily track the user in ASP.NET. So let's have a look over the following code:

    //To get the ip address of the machine and not the proxy use the following code      
                string strIPAddress = Request.UserHostAddress.ToString(); 
                strIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 
     
                if (strIPAddress == null || strIPAddress == "") 
                { 
                    strIPAddress = Request.ServerVariables["REMOTE_ADDR"].ToString(); 
                } 

That's it! Easy right?

HostForLIFE.eu ASP.NET 4.6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments. 



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in