.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Returning Data based on Logged on User

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net


I've looked through many of similar threads and i'm still unable to get what i require to work. So decided i would request the help of you guys :o).

Firstly im a newbie on ASP and the code might look shocking.

What im trying to do is return data from (Table1) where the logged in userid = the Userid in (table1). I am using the ASPNET membership logins.

Depending on what i change i get diffrent errors.

"Conversion failed when converting from a character string to uniqueidentifier. "

ASPX File Below

<form runat="server">Welcome back
<asp:LoginName ID="LoginName1" runat="server" />
, Please see below.
<br />
<br />

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        <asp:BoundField DataField="Skill" HeaderText="Skill" 
            SortExpression="Skill" />
        <asp:CheckBoxField DataField="Shared" HeaderText="Shared" 
            SortExpression="Shared" />
        <asp:BoundField DataField="TimeFrame" HeaderText="TimeFrame" 
            SortExpression="TimeFrame" />
        <asp:BoundField DataField="MethodText" HeaderText="MethodText" 
            SortExpression="MethodText" />
        <asp:BoundField DataField="guid" HeaderText="guid" SortExpression="guid" 

View Complete Post

More Related Resource Links

logged in user data


I'm using the defualt membership provider, i created a table and used the gridview on the logged in user page to show his information such as address e-mail phone zip code etc,, how can i do this without writing a code?

I am new to asp.net  i need simple help please?

Insert data based on gridview user value on row.. how to



I have three column comes from database table(Table1) and one column is for entering data for the user let us consider it look like this 

ItemNo ItemName Qty  uservalue

001       A               50       20

002       A               20       5

003       B               50  

004       C               60      10

005       D               40 

006       E               90      15 


If its 300 row from database to gridview it will show 50 record with page navigation..

What i need is i need to insert data in to database table which gridview row has user value..

The output of the another table(Table2) will look like this after insert

ItemNo ItemName   uservalue

001       A                    20

002       A                      5  

Best practice? Accessing subset of data based on user


I have a DB and associated Asp.net 3.5 web app. The database holds information on our clients. We're adding client access functionality and I need to know how best to restrict user access to data only pertaining to their client.

The clients are stored in a hierarchy and each user can be associated with multiple clients. The user should only be able to access the data for their associated clients and any sub clients thereof.

My initial thought is to add a collection of clients to their profile, then use that to filter all queries; however, my gut instinct tells me that using the profile for such a security function is inadvisable.

Could anyone provide any insight on a best practice for this? I'm sure it must be a pretty common need.


control the access of data based on user id

Hi, We have a cube (Insurance related project), users are grouped under a windows user group and they have their individual user id's . Now the question is how to restrict the users to view the data only related to them based on the user id(which is included in windows user-group)...?   if any mdx query is needed tell me that also

how to set read only properties to the particular info path form control based on user logged in?

how to set read only properties to the  particular info path form control based on user logged in?

How to redirect logged in user based on role



I want to know how can i redirect a user to a different page when he tries to access a page restricted to another role?

The scenario is as follows:

 I have a folder "Gestao" that only allows users in role "Administrator"

            <!--<allow roles="Administrators"/>
        <deny users="*"/>-->

If an anonymous user tries to access that folder he is redirected to the login page, but if a logged in user whose role is "friend" tries to access this folder he is also redirected to the login page. I want to redirect him to a page showing a message that he has no permission to access that page/area.

How can I do that? Should i have code on the Page_load event of the login page checking the user role and then redirect him to the correct page? Or is there some otherway to do this?

Thanks in advance!
Rui Palhinhas


Getting the logged in user's data after he sings in!


Good day Mates,

I use the default membership provider, after the user is created he is directed to a specific page to put his information.

I have a specific page for the user after he LOGGED IN  and i need his information to be show up on this page that he did put in during

the step of creating new account and putting new information

1-How can i make the page after log in shows up the (specific user info only)?

2- I used this code to link the web form to the sql database:

Dim dashDataSource As New SqlDataSource()
        dashDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("mydataConnectionString1").ToString()
        dashDataSource.InsertCommandType = SqlDataSourceCommandType.Text

Linq - add data to database then email user the details


Hi all

I'm not sure how to structure the code for this but what I want to do is be able to add data to a database, and once this has completed successfully, then email the user to say the details have been added successfully to the database.

I need to:

1. Check that the relevant data has been added into the database then

2. Email the details of the relevant data when completed. 


Thanks in advance for your help,




Storing User Data



I'm trying to get the current logged in UserId Value, using this code

Protected Sub UserProfileDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles UserProfileDataSource.Selecting      ' Get a reference to the currently logged on user      Dim currentUser As MembershipUser = Membership.GetUser()      ' Determine the currently logged on user's UserId value      Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid)      ' Assign the currently logged on user's UserId to the @UserId parameter      e.Command.Parameters("@UserId").Value = currentUserId End Sub

But, I getting an error (NullReferenceException), I did set a url authorization on the page that i try to get the logged in user information, witch is info.aspx, and I made the login.aspx control to be redirected to the info.aspx after the login process, But the info.aspx  only shows me (access in denied), how can i make this page knows that i am already logged in?

How to get data from table based on four table



I need to know how to show top 30 records from four table

with fastest speed.. in ms sql server 2005..

hope You do the needfull


Persist data in a dynamically populated ListBox in a user control


Hi All,

I am trying to persist data in a dynamically populated ListBox in a user control. Here are the details

I have a user control which contains a a listBox and button. On Page_Load of user control I am populating the ListBox control with some values. On Click of button, I am trying to fetch the values which I have selected in ListBox. Though this seems very simple and straight forward I am unable to fetch values.

My Page_Load Function

void Page_Load(object sender, EventArgs e)










My Click Function

Protected Void Button1_Click(object sender, EventArgs e)


       string strValue = listBox.SelectedValue



I have placed brake point at Page_Load and on click function, I am seeing that the moment the breakpoin

Fetching the Currently Logged in user Email


Hey Frnds,

I am using the System.DirectoryServices.UserPrincipal.Current.EmailAddress to fetch the Currently logged in users email from AD.

If  debug my sol am getting the Exact mail id of that Particular user for ex:john@in.domain.com.

If i host My Application on iis

And Access my App am getting some other Email id instead of the john@in.domain.com.

I have changed the Application Pool identity to NetWorkService.

Can any one tell what could be wrong




Toolbox: User-Friendly UIs, Online Data Entry Controls, and More


Microsoft® Office is one of the most well-known and most-used consumer products. For many people, their only experience with a computer is when using Office, be it checking e-mail, creating presentations, or writing a document.

Scott Mitchell

MSDN Magazine February 2006

Beyond ASP: XML and XSL-based Solutions Simplify Your Data Presentation Layer


The combination of XML and XSL can provide a powerful alternative to ASP development. This article presents arguments for building even small-scale Internet applications on the XML model. An example written with traditional ASP programming is compared to the same example written with XML and XSL in order to show the benefits of this approach. The example is followed by nine good reasons to make the switch. These reasons include separation of presentation and data, reusability, extensibility, division of labor, enhanced testing, and legacy integration. The XML/XSL solutions described hold the promise of greater simplicity, flexibility, and durability than ASP solutions built the traditional way.

Scott Howlett and Jeff Dunmall

MSDN Magazine November 2000

Entity Data Model and database view returning the same columns as there are in a table


When adding a stored procedure into the Entity Data Model I can select whether the procedure returns a scalar, a (new) complex type or one of the entity types I already defined. 

How do I do something similar for a view?

I mean assuming I have a view like this

CREATE VIEW FilteredFoos as SELECT Foo.* FROM Foo join ... WHERE ...

(that is a view that implements some involved filtering, but returns all columns from one table) how do I add it to the project so that I can use the entity set, but get the Foo objects, not some new FilteredFoo objects.

var foos = myDB.FilteredFoos.Include("Bar").ToList();

foreach (Foo foo in foos) { ...

Thanks, Jenda

How to process data AFTER page is completely loaded for the user?


I have some logging that has to be done, which are some database update or inserts.

However this logging is of no importance to the user, so I only want to process the data/logs after the page is completed for the user.
As of now, if I process the data while the page is loading, I go from 1.4 to 2.0 speed (server side time processing of code), which is quite a bit comparing it is of no use to the user.

So I want this code only executed after that the page is complete.

I've been checking out Ajax, async pages etc, but the problem is it still gets executed before the page is rendered to the client, which means the client will have to wait longer then it is not being processed.

I've been checking out Threadpool.queueBackgroundWorker, however if I get it correct, this will still be executed before the page is shown to the user, as it has to complete before the prerender.

Then I thought about creating a new thread, and do the processing there, which would not have my page waiting to complete the data/logging.
However when I have 100 or 200 users loading pages at the same time, then that would mean I would be creating 200 threads on those loads, which I doubt will be good for performance. So if I want to solve this, I would have to create my own threadpool and only assign for example a max of 40 threads to it which can pr

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend