user comment display on asp.net page - c#

I have an asp.net page which uses the asp membership control. I want to use the user comment field to hold an additional piece of information. I'm creating the user via the Web Site Administration Tool.
So how would I access the comment field and write it to the page?
Ok I'm not totally mad (well maybe but that's my state of mind!).
the comment field lives in the aspnet_Membership table if you create a user and go to manage that user you see it has a Description labelled text box this maps through to the Comment field.
Maybe I'm using the wrong terms! sorry...

I don't quite understand what "comment field" you are talking about, because the default Web Site Administration Tool created users don't have such fields.
If you want to create such a field you would need to implement different MembershipProvider class or work with Profile properties
I would recommend you to read these articles first:
Examining ASP.NET's Membership, Roles, and Profile
Storing Additional User Information
EDIT:
For that particular "Description" field (wich I'm sure wasn't there when I was looking for it >.<), it really puts data into "aspnet_Membership" table "Comment" column.
You can easily access it with MembershipUser class:
#{MembershipUser user = Membership.GetUser();}
#if ( user != null)
{
#user.Comment
}
Razor syntax
EDIT
Membership.GetUser() support simple overrides so you don't really need to use Context.User.Identity.Name as parameter for currently logged-on user.

Gotta go with Ilya on this one... I'm not seeing a "comment" field in my instance of Web Site Adminstration.
But, a possible answer to your question would be ASP.NET Profiles:
http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx

Related

Localization for user profile information Asp.net

I'm trying to implement page localization to my webpage made in asp.net-mvc. I understand how to implement titles and other modular data.
The problem comes when i want to give user/admin of this page rights to change his personal information/bio on her webpage if needed. Do i save the bio in the database? With another column in the table which indicates for which language it is meant?
Or is there any better solution?

Confused in making a C# Login Control

I need help in creating a simple login control using 2 custom text boxes to allow users to log into a profile of their own.
I have created the profile page. But I'm kind of clueless on how to write the code behind the
> btnLogin
I have a register page which allows me perfectly to save the details onto a SQL database table. I know this must be a simple set of code but I'm probably making it too complicated.
as an example
my text box Variables are
txtUserName
txtPassword
My SQL table name is UserDetails which includes the Username and password and few other fields which is irrelevant to the login activity.
............
Response redirect page I want the User to go to is ProfileOfUser.aspx based on UserIds.
something similar to this,
Response.Redirect("ProfileOfUser.aspx?Id=" + Session["UserId"].ToString());
would be really appreciative if anyone can help me figure this out :)
Why don't you use ASP.NET login control?
ASP.NET Login Controls

How do you store custom user data in asp.net?

I may be overlooking a question like this, but I couldn't find it. I have an asp.net site with C# codebehind, and I have a working means of creating user accounts, passwords, and associating other data with each user. I started this site by creating a web application, and the login/register functions were all included and work fine. I also have a database that the user can search and display data on the site (all of this also works). However, I want the user to be able to search the database for data, and then be able to go back to pages that they've saved as pages that they're "following." All I would need to store would be a unique identifier from the database to note that the person wanted to follow that page. Where would be the best place to store these values? Could I do so by saving the data in the aspnetdb database? If so, how would I write custom values in this database if using an asp.net web application?
If you're using ASP.NET's Membership feature, you'll probably want to use the MembershipUser.ProviderKey as the unique ID mentioned by #dcreight. Use it to access your own table. I would not recommend writing into the aspnetdb directly.

How to tie custom properties to a registered user in C#/asp.net MVC 4

Say there are three roles, namely:
Registered
Administrator
Sponsor
I'd like users to be able to self-register as Registered (easy enough out-of-box).
I'd like an Administrator to be able to see all registered users and check off the "Sponsor" checkbox, making the user a Sponsor.
Once the user is "checked" as a Sponsor, the Administrator should be able to add additional parameters for the Sponsor, including logo and Sponsor URL, which webpage(s) they are sponsoring, the valid date range for the sponsorship by webpage, the number of impressions and clicks, and also "paid/not paid".
I'm trying to wrap my head around Memberships and Profiles, and see how they apply to this.
Can anyone provide a general framework as to how I can properly architect this? Are there Nuget packages to do just this?
Advice appreciated.
Maybe my answer to another question will help a bit Using out of the box aspnet membership for public facing website
In Nuget - Thinktecture.IdentityModel is a way to go.
Use the table profile provider.
You can then edit the values in this table directly through a simple page.
Excluding the profile provider, is there an easy way to add custom fields to ASP.NET membership?
You can then use the web interface to assign a user to a role as an admin:
http://msdn.microsoft.com/en-us/library/t32yf0a9.aspx
Or simply code this page and use Roles.AddUserToRole
http://msdn.microsoft.com/en-us/library/system.web.security.roles.addusertorole.aspx

Conditional/limited access in a controller/view? (MVC2)

I have two roles being used on my site currently, author & admin. Authors cannot access user administration functions. However, they should be able to edit certain parts of their profile. An admin is currently able to edit all parts of a user's profile. For example:
employee ID [admin]
display name [author,admin]
roles [admin]
I would like to re-use code where possible. I'm not sure what the best solution would be here. There are 2 things to deal with
Only allowing a user to edit their own profile and not others
Restricting which fields that user can edit vs which fields an admin can edit
I think #1 is best achieved by a custom Authorize attribute (I already have one I can extend further). If you have a better approach please share. And #2 I am unsure, view model? I have my allowed fields bound for a user using a partial class which would be different for each role.
Your solution for #1 is spot on, you need to use the AuthorizeAttribute.
For #2 you can just do security trimming where you only render for the particular user.
Some pseudo code in your view (or move it to a partial view):
if administrator
render employee ID text box
if administrator || author
render display name text box
if administrator
render roles check list
So you're going to need to control how to determine if the user is in a "role". You can use ASP.NET's Membership Provider or roll something of your own.

Categories