You need to create a Table in sql server with following field.
UserName Varchar(50) PK, Unique identifier for User
Page Varchar(255) PK, Path and File Name of the Page
Personalization Image Personalization data
Then you have to create a custom personalization provider class which will implement
PersonalizationProvider
class.
You can use the following code, I have created the class which will consume WCF service, so I will remove those parts from the code and you can replace it with simple sql statemetns to read/write from sql server table that you have just created.
using System;
using System.Configuration.Provider;
using System.Security.Permissions;
using System.Web;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Text;
using System.IO;
namespace YourApplicationName
{
public class MyCustomPersonalizationProvider : PersonalizationProvider
{
private string m_ApplicationName;
public override string ApplicationName
{
get { return m_ApplicationName; }
set { m_ApplicationName = value; }
}
private string m_ConnectionStringName;
public string ConnectionStringName
{
get { return m_ConnectionStringName; }
set { m_ConnectionStringName = value; }
}
public override void Initialize(string name, NameValueCollection config)
{
if (config == null)
throw new ArgumentNullException("config");
if (String.IsNullOrEmpty(name))
name = "MyCustomPersonalizationProvider";
if (string.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "My Custom Personalization Provider for Portal");
}
base.Initialize(name, config);
if (string.IsNullOrEmpty(config["connectionStringName"]))
{
throw new ProviderException
("ConnectionStringName property has not been specified");
}
else
{
m_ConnectionStringName = config["connectionStringName"];
config.Remove("connectionStringName");
}
if (string.IsNullOrEmpty(config["applicationName"]))
{
throw new ProviderException
("applicationName property has not been specified");
}
else
{
m_ApplicationName = config["applicationName"];
config.Remove("applicationName");
}
if (config.Count > 0)
{
string attr = config.GetKey(0);
if (!String.IsNullOrEmpty(attr))
throw new ProviderException
("Unrecognized attribute: " + attr);
}
}
protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)
{
sharedDataBlob = null;
userDataBlob = null;
object userBlobDataObject = null;
try
{
System.Data.DataTable dt =
if (dt.Rows.Count > 0)
userBlobDataObject = dt.Rows[0].ItemArray[0];
if (userBlobDataObject != null && userBlobDataObject != DBNull.Value)
userDataBlob =
(byte[])userBlobDataObject;
}
catch (Exception ex)
{
"Dashboard",
MyErrorHandling.FormatErrorMessage(userName,
"Custom Personalization Provider",
"LoadPersonalizationBlobs()", ex.ToString()), 2);
}
}
protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)
{
try
{
}
catch (Exception ex)
{
"Dashboard",
MyErrorHandling.FormatErrorMessage(userName,
"Custom Personalization Provider",
"ResetPersonalizationBlobs()", ex.ToString()), 2);
}
}
protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob)
{
try
{
}
catch (Exception ex)
{
"Dashboard",
MyErrorHandling.FormatErrorMessage(userName,
"Custom Personalization Provider",
"SavePersonalizationBlobs()", ex.ToString()), 2);
}
}
public override PersonalizationStateInfoCollection FindState(PersonalizationScope scope, PersonalizationStateQuery query, int pageIndex, int pageSize, out int totalRecords)
{
throw new NotSupportedException();
}
public override int GetCountOfState(PersonalizationScope scope, PersonalizationStateQuery query)
{
throw new NotSupportedException();
}
public override int ResetState(PersonalizationScope scope, string[] paths, string[] usernames)
{
throw new NotSupportedException();
}
public override int ResetUserState(string path, DateTime userInactiveSinceDate)
{
throw new NotSupportedException();
}
}
}
now after this you have to configure the web.config to use the custom personalization provider instead of
aspnetsqlprovider
add the following block inside
<system.web></system.web>
in the web.config
<webParts>
<personalization defaultProvider="MyCustomPersonalizationProvider">
<providers>
<remove name="AspNetSqlProvider"/>
<add connectionStringName="DashBoardConnection" name="MyCustomPersonalizationProvider" type="YourApplicationName.MyCustomPersonalizationProvider" applicationName="/"/>
</providers>
<authorization>
<allow users="*" verbs="enterSharedScope"/>
</authorization>
</personalization>
</webParts>
If you code the sql statement correctly in the class where I have put the comments, everything will just work fine...