Web Part Personalization according to user


Problem 1:I want to set the webparts personalization according to login user i.e. If user1 closed a webpart in the appliaction then this should not reflect to user2. How can i achieve this ?
Problem 2:I have a Users table containing username and password fields. A user has to first login into a form that simplay matches the username and password against the database and then displays a page with web parts. (No web.config hardcoded profiles! No Windows Authentication)
I want to load and save the webpart personalization using the Username of the user who has successfully logged in. Even on same machine different users login should mean diffeent personalization settings.
If i set the Authentication mode to forms it gives me the error stating

“System.ArgumentException was unhandled by user code
Message=”The specified display mode is currently disabled on this page. Make sure personalization is enabled for the current user.\r\nParameter name: value”
Source=”System.Web”
ParamName=”value”
StackTrace:
at System.Web.UI.WebControls.WebParts.WebPartManager.set_DisplayMode(WebPartDisplayMode value)
at LetterGeneration_Default.Page_Load(Object sender, EventArgs e) in c:\CLProject\CLWebClient\CLWebClient\LetterGeneration\Default.aspx.cs:line 222
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()”

Solution:
For webparts personalization an user should be authenticated either by Windows authentication or Forms authentication. Just follow these simple steps for Forms authentication.

In Web.config just insert

<authentication mode=”forms” />

<authorization>

<allow users=”*” />

<deny users=”?” />

</authorization>

Now at loginn page just write …

MembershipUser mUser = Membership.GetUser(this.UserNameTextBox.Text);
if (mUser == null)
{
mUser = Membership.CreateUser(this.UserNameTextBox.Text, “3rdp@rty”, “xyz@tdsc.com”, “no question”, “no answer”, true, out msStatus);
}
FormsAuthentication.RedirectFromLoginPage(mUser.UserName, false);

the bold line above is the most important coz it’s authenticate the user for personalization.

Advertisements

One thought on “Web Part Personalization according to user

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s