By Bipin Joshi
ASP.NET 2.0 introduced various application services—such as Membership, Roles, and Profiles—that eliminate a lot of coding that was required to provide the same functionality. However, these services are part of ASP.NET's server-side framework, which could pose a challenge when you use ASP.NET AJAX to consume the services from client-side JavaScript code. Fortunately, ASP.NET AJAX provides an out-of-the-box solution to this problem. This article explains how to use this solution in C# with Visual Studio.
Sample Scenario
Suppose you are developing a new web site and want to implement forms authentication. The web site will have a user registration page, a login page, and one or more pages that you must secure. The user registration and login pages use ASP.NET AJAX for an enhanced user experience. Also, the site must capture details such as birth date and address at the time of registration. This information is to be stored in the Profile of the user.
To develop a web site that fulfills all the above requirements, begin by creating a new ASP.NET AJAX-enabled web site with C# (see Figure 1).
More...
http://www.developer.com/net/asp/article.php/10917_3661801_1
Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts
Tuesday, September 9, 2008
Monday, September 8, 2008
Multi User Chat Room Using ASP.NET 2.0 and AJAX
By Mosalem
Describes how you can build a multi user chat room using ASP.NET 2.0 and AJAX extensions
Introduction
Building an interactive chat room requires keeping the users up to date with the messages and status of other users. Using ASP.NET AJAX to implement the chat room will remove the unnecessary post backs and will provide a seamless chat experience to the user.
Background
You can read my previous article on how to build a one to one chat room, this article was built using ASP.NET 1.1 and a third party AJAX library. Most of the Chatting Logic (rooms, users, messages sending, etc..) is used here.
Code Walkthrough
The App_Code folder contains all the classes that will be used to create our chat application. Let us start with the ChatUser
Collapse
//ChatUser.cs
public class ChatUser:IDisposable
{
#region Members
public string UserID;
public string UserName;
public bool IsActive;
public DateTime LastSeen;
public int LastMessageReceived;
#endregion
#region Constructors
public ChatUser(string id,string userName)
{
this.UserID=id;
this.IsActive=false;
this.LastSeen=DateTime.MinValue ;
this.UserName=userName;
this.LastMessageReceived=0;
}
#endregion
#region IDisposable Members
public void Dispose()
{
this.UserID="";
this.IsActive=false;
this.LastSeen=DateTime.MinValue ;
this.UserName="";
this.LastMessageReceived=0;
}
#endregion
}
This class represents the user that will join the chat room. The properties we are interested in are IsActive, LastSeen and LastMessageReceived. Note that in your application you may be using the ASP.NET membership providers. You can easily use this with our chat application. You will find that the MembershipUser class contains two properties IsOnline and LastActivityDate that can be used to replace the properties IsActive and LastSeen respectively.
Each message that appears in the chat room is represented by the following class:
Collapse
//ChatMessage.cs
public class Message
{
#region Members
public string user;
public string msg;
public MsgType type;
#endregion
#region Constructors
public Message(string _user, string _msg, MsgType _type)
{
user = _user;
msg = _msg;
type = _type;
}
public Message(string _user, MsgType _type) :
this(_user, "", _type) { }
public Message(MsgType _type) : this("", "", _type) { }
#endregion
#region Methods
public override string ToString()
{
switch(this.type)
{
case MsgType.Msg:
return this.user+" says: "+this.msg;
case MsgType.Join :
return this.user + " has joined the room";
case MsgType.Left :
return this.user + " has left the room";
}
return "";
}
#endregion
}
public enum MsgType { Msg, Start, Join, Left, Action}
Each chat room contains a hashtable of users and a list of messages.
More...
http://www.codeproject.com/KB/aspnet/ASPNetChat.aspx
Describes how you can build a multi user chat room using ASP.NET 2.0 and AJAX extensions
Introduction
Building an interactive chat room requires keeping the users up to date with the messages and status of other users. Using ASP.NET AJAX to implement the chat room will remove the unnecessary post backs and will provide a seamless chat experience to the user.
Background
You can read my previous article on how to build a one to one chat room, this article was built using ASP.NET 1.1 and a third party AJAX library. Most of the Chatting Logic (rooms, users, messages sending, etc..) is used here.
Code Walkthrough
The App_Code folder contains all the classes that will be used to create our chat application. Let us start with the ChatUser
Collapse
//ChatUser.cs
public class ChatUser:IDisposable
{
#region Members
public string UserID;
public string UserName;
public bool IsActive;
public DateTime LastSeen;
public int LastMessageReceived;
#endregion
#region Constructors
public ChatUser(string id,string userName)
{
this.UserID=id;
this.IsActive=false;
this.LastSeen=DateTime.MinValue ;
this.UserName=userName;
this.LastMessageReceived=0;
}
#endregion
#region IDisposable Members
public void Dispose()
{
this.UserID="";
this.IsActive=false;
this.LastSeen=DateTime.MinValue ;
this.UserName="";
this.LastMessageReceived=0;
}
#endregion
}
This class represents the user that will join the chat room. The properties we are interested in are IsActive, LastSeen and LastMessageReceived. Note that in your application you may be using the ASP.NET membership providers. You can easily use this with our chat application. You will find that the MembershipUser class contains two properties IsOnline and LastActivityDate that can be used to replace the properties IsActive and LastSeen respectively.
Each message that appears in the chat room is represented by the following class:
Collapse
//ChatMessage.cs
public class Message
{
#region Members
public string user;
public string msg;
public MsgType type;
#endregion
#region Constructors
public Message(string _user, string _msg, MsgType _type)
{
user = _user;
msg = _msg;
type = _type;
}
public Message(string _user, MsgType _type) :
this(_user, "", _type) { }
public Message(MsgType _type) : this("", "", _type) { }
#endregion
#region Methods
public override string ToString()
{
switch(this.type)
{
case MsgType.Msg:
return this.user+" says: "+this.msg;
case MsgType.Join :
return this.user + " has joined the room";
case MsgType.Left :
return this.user + " has left the room";
}
return "";
}
#endregion
}
public enum MsgType { Msg, Start, Join, Left, Action}
Each chat room contains a hashtable of users and a list of messages.
More...
http://www.codeproject.com/KB/aspnet/ASPNetChat.aspx
ASP/SQL Server Based Chat program
By cdidave
Simple ASP/SQL Server Chat application
Introduction
This chat program was created simply because I didn’t want to buy one that had everything I wanted. This application is certainly not a complete application but it does take care of most general chat functions. I even included a few things some other applications don’t have such as smileys, language filters and room invitations.
Background
Since I have a content management system that uses a domain_id identifier, I wanted to be able to offer the chat program to many of my clients without having to create a database for each one of them. So I added the domain_id identifier to allow many domains to use it without cross contamination. You will see that almost all functions will filter by this identifier.
The database is SQL Server. I tried to use an Access database but I had trouble getting Access to support multiple recordsets in a singe SQL call. Instead of describing the database in detail, I have included a script that will build the SQL database. The data_access.asp contains the username and password that is written into the SQL script. These can be changed as long as they are the same in both places. I use a separate config file when I integrate these. For the demo, I simply hard coded them.
Using the code
Install
The code simply needs to be copied to any ASP virtual directory. No global.asa is needed. A database script is provided and just simply needs to be ran on the SQL Server with create database privileges.
Configure
In the install folder include/data_access.asp, simply replace the settings with your server info and you are all set. In my applications, this is an application variable. You may handle it however you wish.
Run
default.htm is a sample of how you can integrate the chat into any page. Sessions are used to track user info and stuff like that but by changing the domain_id parameter, you can run as many simultaneous instances as you want.
Happy chatting!
More...
http://www.codeproject.com/KB/asp/CDIChatSubmit.aspx
Simple ASP/SQL Server Chat application
Introduction
This chat program was created simply because I didn’t want to buy one that had everything I wanted. This application is certainly not a complete application but it does take care of most general chat functions. I even included a few things some other applications don’t have such as smileys, language filters and room invitations.
Background
Since I have a content management system that uses a domain_id identifier, I wanted to be able to offer the chat program to many of my clients without having to create a database for each one of them. So I added the domain_id identifier to allow many domains to use it without cross contamination. You will see that almost all functions will filter by this identifier.
The database is SQL Server. I tried to use an Access database but I had trouble getting Access to support multiple recordsets in a singe SQL call. Instead of describing the database in detail, I have included a script that will build the SQL database. The data_access.asp contains the username and password that is written into the SQL script. These can be changed as long as they are the same in both places. I use a separate config file when I integrate these. For the demo, I simply hard coded them.
Using the code
Install
The code simply needs to be copied to any ASP virtual directory. No global.asa is needed. A database script is provided and just simply needs to be ran on the SQL Server with create database privileges.
Configure
In the install folder include/data_access.asp, simply replace the settings with your server info and you are all set. In my applications, this is an application variable. You may handle it however you wish.
Run
default.htm is a sample of how you can integrate the chat into any page. Sessions are used to track user info and stuff like that but by changing the domain_id parameter, you can run as many simultaneous instances as you want.
Happy chatting!
More...
http://www.codeproject.com/KB/asp/CDIChatSubmit.aspx
Subscribe to:
Posts (Atom)