.NET Framework Type
|
ADO.NET Database Type
|
SQL Data Type
|
String
|
Varchar
|
Varchar()
|
String
|
Nvarchar
|
Nvarchar()
|
String
|
NChar
|
Nchar()
|
String
|
NText
|
NText
|
String
|
Text
|
Text
|
Double
|
BigInt
|
Float
|
DateTime
|
DateTime
|
Datetime
|
DateTime
|
SmallDateTime
|
Smalldatetime
|
Int
|
Int
|
Int
|
Int64
|
BigInt
|
Bigint
|
Int16
|
SmallInt
|
smallint
|
Byte[]
|
Binary
|
Binary()
|
Byte[]
|
Image
|
Image
|
Byte[]
|
VarBinary
|
Varbinary()
|
Byte
|
TinyInt
|
Tinyint
|
Bool
|
Bit
|
Bit
|
Decimal
|
Decimal
|
Decimal
|
Decimal
|
Money
|
Money
|
Decimal
|
SmallMoney
|
SmallMoney
|
Float
|
Float
|
Float
|
Guid
|
UniqueIdentifier
|
Uniqueidentifier
|
Real
|
Real
|
Real
|
Friday, September 19, 2014
The data type comparison chart below
Tuesday, September 16, 2014
Logging In Using External Sites in an ASP.NET Web Pages
This article explains how to log in to your ASP.NET Web Pages (Razor) site using Facebook, Google, Twitter, Yahoo, and other sites — that is, how to support OAuth and OpenID in your site.
What you'll learn:
- How to enable login from other sites when you use the WebMatrix Starter Site template.
This is the ASP.NET feature introduced in the article:
- The
OAuthWebSecurityhelper.
Software versions used in the tutorial
ASP.NET Web Pages includes support for OAuth and OpenID providers. Using these providers, you can let users log into your site using their existing credentials from Facebook, Twitter, Microsoft, and Google. For example, to log in using a Facebook account, users can just choose a Facebook icon, which redirects them to the Facebook login page where they enter their user information. They can then associate the Facebook login with their account on your site. A related enhancement to the Web Pages membership features is that users can associate multiple logins (including logins from social networking sites) with a single account on your website.
This image shows the Login page from the Starter Site template, where a user can choose a Facebook, Twitter, Google or Microsoft icon to enable logging in with an external account:

You can enable OAuth and OpenID membership by uncommenting a few lines of code in the Starter Site template. The methods and properties you use to work with the OAuth and OpenID providers are in the
WebMatrix.Security.OAuthWebSecurity class. The Starter Site template includes a full membership infrastructure, complete with a login page, a membership database, and all the code you need to let users log into your site using either local credentials or those from another site.
This section provides an example of how to let users log in from external sites to a site that's based on the Starter Site template. After creating a starter site, you do this (details follow):
- For the sites that use an OAuth provider (Facebook, Twitter, and Microsoft), you create an application on the external site. This gives you application keys that you'll need in order to invoke the login feature for those sites.
- For sites that use an OpenID provider (Google), you do not have to create an application. For all of these sites, you must have an account in order to log in and to create developer applications.Note Microsoft applications only accept a live URL for a working website, so you cannot use a local website URL for testing logins.
- Edit a few files in your website in order to specify the appropriate authentication provider and to submit a login to the site you want to use.
This article provides separate instructions for the following tasks:
Enabling Google Logins
- Create or open an ASP.NET Web Pages site that's based on the WebMatrix Starter Site template.
- Open the _AppStart.cshtml page and uncomment the following line of code.
OAuthWebSecurity.RegisterGoogleClient();
Testing Google login
- Run the default.cshtml page of your site and choose the Log in button.
- On the Login page, in the Use another service to log in section, choose either the Google or Yahoo submit button. This example uses the Google login.The web page redirects the request to the Google login page.
- Enter credentials for an existing Google account.
- If Google asks you whether you want to allow Localhost to use information from the account, click Allow.The code uses the Google token to authenticate the user, and then returns to this page on your website. This page lets users associate their Google login with an existing account on your website, or they can register a new account on your site to associate the external login with.
- Choose the Associate button. The browser returns to your application's home page.
Enabling Facebook Logins
- Choose the Create New App button, and then follow the prompts to name and create the new application.
- In the section Select how your app will integrate with Facebook, choose the Website section.
- Fill in the Site URL field with the URL of your site (for example, http://www.example.com). The Domain field is optional; you can use this to provide authentication for an entire domain (such as example.com).Note If you are running a site on your local computer with a URL likehttp://localhost:12345 (where the number is a local port number), you can add this value to the Site URL field for testing your site. However, any time the port number of your local site changes, you will need to update the Site URL field of your application.
- Choose the Save Changes button.
- Choose the Apps tab again, and then view the start page for your application.
- Copy the App ID and App Secret values for your application and paste them into a temporary text file. You will pass these values to the Facebook provider in your website code.
- Exit the Facebook developer site.
Now you make changes to two pages in your website so that users will able to log into the site using their Facebook accounts.
- Create or open an ASP.NET Web Pages site that's based on the WebMatrix Starter Site template.
- Open the _AppStart.cshtml page and uncomment the code for the Facebook OAuth provider. The uncommented code block looks like the following:
OAuthWebSecurity.RegisterFacebookClient( appId: "", appSecret: "");
- Copy the App ID value from the Facebook application as the value of the
appIdparameter (inside the quotation marks). - Copy App Secret value from the Facebook application as the
appSecretparameter value. - Save and close the file.
Testing Facebook login
- Run the site's default.cshtml page and choose the Login button.
- On the Login page, in the Use another service to log in section, choose the Facebook icon.The web page redirects the request to the Facebook login page.
- Log into a Facebook account.The code uses the Facebook token to authenticate you and then returns to a page where you can associate your Facebook login with your site's login. Your user name or email address is filled into the Email field on the form.
- Choose the Associate button.The browser returns to the home page and you are logged in.
Enabling Twitter Logins
- Browse to the Twitter developers site.
- Choose the Create an App link and then log into the site.
- On the Create an Application form, fill in the Name and Description fields.
- In the WebSite field, enter the URL of your site (for example, http://www.example.com).Note If you're testing your site locally (using a URL like http://localhost:12345), Twitter might not accept the URL. However, you might be able to use the local loopback IP address (for example http://127.0.0.1:12345). This simplifies the process of testing your application locally. However, every time the port number of your local site changes, you'll need to update the WebSite field of your application.
- In the Callback URL field, enter a URL for the page in your website that you want users to return to after logging into Twitter. For example, to send users to the home page of the Starter Site (which will recognize their logged-in status), enter the same URL that you entered in the WebSite field.
- Accept the terms and choose the Create your Twitter application button.
- On the My Applications landing page, choose the application you created.
- On the Details tab, scroll to the bottom and choose the Create My Access Token button.
- On the Details tab, copy the Consumer Key and Consumer Secret values for your application and paste them into a temporary text file. You'll pass these values to the Twitter provider in your website code.
- Exit the Twitter site.
Now you make changes to two pages in your website so that users will be able to log into the site using their Twitter accounts.
- Create or open an ASP.NET Web Pages site that's based on the WebMatrix Starter Site template.
- Open the _AppStart.cshtml page and uncomment the code for the Twitter OAuth provider. The uncommented code block looks like this:
OAuthWebSecurity.RegisterTwitterClient( consumerKey: "", consumerSecret: "");
- Copy the Consumer Key value from the Twitter application as the value of the
consumerKeyparameter (inside the quotation marks). - Copy the Consumer Secret value from the Twitter application as the value of the
consumerSecretparameter. - Save and close the file.
Testing Twitter login
- Run the default.cshtml page of your site and choose the Login button.
- On the Login page, in the Use another service to log in section, choose the Twitter icon.The web page redirects the request to a Twitter login page for the application you created.
- Log into a Twitter account.
- The code uses the Twitter token to authenticate the user and then returns you to a page where you can associate your login with your website account. Your name or email address is filled into the Email field on the form.
- Choose the Associate button.The browser returns to the home page and you are logged in.
Additional Resources
Source:http://www.asp.net/web-pages/tutorials/security/enabling-login-from-external-sites-in-an-aspnet-web-pages-site#To_enable_Facebook_logins
Add user tables with ASP.net membership
It will be in 3 steps:
Those are the following ....
Step1: how to install asp.net membership database schema in SQL Server
Introduction:
In this article I will explain how to install asp.net Membership database schema in Sql Server.
Description:
In one of my project I got requirement like using asp.net membership concept with custom database. First of all we learn what is asp.net membership? And why we need to use this one?
ASP.NET membership gives you a built-in way to validate and store user credentials. ASP.NET membership therefore helps you manage user authentication in your Web sites. You can use ASP.NET membership with ASP.NET Forms authentication or with the ASP.NET login controls to create a complete system for authenticating users.
By Using ASP.NET membership we can create new users and passwords and we can authenticate users who visit your site. You can authenticate users programmatically, or you can use the ASP.NET login controls to create a complete authentication system that requires little or no code and we can manage passwords, which includes creating, changing, and resetting them.
Now we will do the step by step process how to use Custom membership database.
1. Go to the Start menu and open Run and enter%WINDIR%\Microsoft.Net\Framework\v2.0.50727\aspnet_regsql.exe and click ok it will open the Asp.net SQL Server setup wizard like this |
|
We can get this in alternatively go toC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe![]() |
In this wizard we have two options
1. Configure SQL Server for application Services
2. Remove application services information from an existing database.
Now select first option Configure SQL Server for application services because first time we are creating database. If you want to delete already created database select second option
After selecting the first option click next now the window like this
![]() |
After that enter your database server name and select database from existing list or give new name and click next you will see the window like this
![]() |
After that click next button you now your aspnet membership database installation is completed and now that is ready to use with our application final window like this
![]() |
Now check your database everything installed and ready to use in our application.
Everything is ready how to use that custom database in our application for that create one new web application and name it as Registration.aspx now drag and drop the one new control CreateUserWizardfrom Login Controls list that aspx page like this
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</div>
</form>
</body>
</html>
|
Now open Web.config file and write the following code
Write the connectionstring like this
<connectionStrings>
<add name="Connection" connectionString="Data Source=ICOI;UserName=; password=Initial Catalog=AspMembership" providerName="System.Data.SqlClient"/>
</connectionStrings>
|
After that write the following code in system.web section
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"connectionStringName="Connection" applicationName="SampleApplication"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider"connectionStringName="Connection" applicationName="SampleApplication"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"connectionStringName="Connection" applicationName="SampleApplication"/>
</providers>
</roleManager>
|
After that run your application and create user by using CreateUserWizard
Here functionality of inserting the user details and everything will take care by CreatUserWizard no need to write any coding just set the database and set the conditions in web.config file that is enough. Now your program will work perfectly
Step2: CreateUserWizard control to create user accounts in asp.net membership
Introduction:
In this article I will explain how to create users using CreateUserWizard using asp.net membership concept.
Description:
In previous post I explained clearly . After install asp.net membership database check your database everything installed and ready to use in our application or not.
Now open visual studio and create new web application after that drag and drop the new controlCreateUserWizard from Login Controls section into aspx page and check the aspx page code that would be like this
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Create Users Using CreateUserWizard Control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</div>
</form>
</body>
</html>
|
After that run your application and create users by using CreateUserWizard control.
Here the functionality of insert user details and everything will take care by CreatUserWizard no need to write any coding just set the database and set the conditions in web.config file that is enough it will work perfectly.
During the time of create user if you get error like “Password length minimum: 7. Non-alphanumeric characters required: 1.” check this post solve password length minimum: 7 problem. This problem because of our password basically asp.net membership concept will accept the password only if it contains mixed of alphanumeric and special characters.
If you observe above demo in that we need to enter different options like UserName, password (strong password like mixed of alphanumeric and special characters), Email (Unique Email), Security Question and answer to register new user.
If we don’t want security question and answer options and we need to allow users to enter his own password without any restrictions for that we need to configure some properties in web.config file likerequiresQuestionAndAnswer="false", minRequiredPasswordLength="6" andminRequiredNonalphanumericCharacters="0" to set those properties check this post solve password length problem.
Step3:Asp.net login control to check user details using Membership concept
Introduction:
In this article I will explain how to use Login Control to validate user details using asp.net membership.
Description:
In previous post I explained clearly how to install asp.net membership database schema in SQL Serverand create users using CreateUserWizard in asp.net membership. Here I am using these two concepts to validate user details with Login Control using asp.net membership in our login page.
In this article I will explain how to use Login Control to validate user details using asp.net membership.
Description:
In previous post I explained clearly how to install asp.net membership database schema in SQL Serverand create users using CreateUserWizard in asp.net membership. Here I am using these two concepts to validate user details with Login Control using asp.net membership in our login page.
In visual studio toolbox we have Login control in Login list section this control contain built in functionalities like validate username, password and check the user details against asp.net membership. We can use this control directly in login page instead of writing huge code in your login page with username, password textbox controls etc with asp.net membership database.
To install asp.net membership database schema in sql server check this post install membership database in SQL Server and to create user accounts check this post user accounts with CreateUserWizard.
After completion of database setup and user accounts creation open visual studio and create new web application after that right click on your application and Add new item select WebForm and give name asLogin.aspx (If you want another name you can give another name also that is your wish). Now drag and drop the new control Login from Login Controls section into Login.aspx page after that check your aspx page code that would be like this
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Control to validate User Details</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Default.aspx">
</asp:Login>
</div>
</form>
</body>
</html>
|
Now open Default.aspx page drag and drop the Login status control and one label to our Default.aspxpage will be like this
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Control to validate User Details</title>
</head>
<body>
<form id="form1" runat="server">
<table align="center" width="200px">
<tr>
<td>
</td>
<td>
<asp:LoginStatus ID="LoginStatus1" runat="server" />
</td>
</tr>
<tr>
<td><asp:Label ID="lblResult" runat="server" Font-Bold="true"/></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
|
Now write the following code in Default.aspx code behind to get login username
protected void Page_Load(object sender, EventArgs e)
{
lblResult.Text = "Welcome "+ Page.User.Identity.Name;
}
|
Now open Web.config file and change authentication mode to Forms and deny permissions for anonymous access
<authentication mode="Forms"/>
<authorization>
<deny users="?"/>
</authorization>
|
Now run your application and check user credentials with asp.net membership database
Demo
Source:
http://www.aspdotnet-suresh.com/2011/12/createuserwizard-control-to-create-user.html
Subscribe to:
Comments (Atom)









