Answered by:
Pass Membership data to data layer

Question
-
User188291263 posted
I got a data layer,which basically containt .dbml adn other overrites and partial classes.
How i can pass ApplicationId and UserId,from Insert.aspx or Edit.aspx to data layer?
I was thinking about using System.Threading.Thread.CurrentPrincipal,but cant figure out how.Thank you
Wednesday, August 27, 2008 11:34 PM
Answers
-
User188291263 posted
Fixed problem
I have to sync both in Application_AuthenticateRequest
HttpContext.Current.User = principal;
Thread.CurrentPrincipal = principal;
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 29, 2008 4:06 PM
All replies
-
User-797310475 posted
Could you please clarify what kind of scenario you are trying to achieve?
Thursday, August 28, 2008 4:15 AM -
User188291263 posted
Its 2 projects, one project is Class Library,where i have my DataContext,and another project is dynamic data project.
My project use asp.net Membership feature. I have a
table News
ApplicationId (guid) foreign key to aspnet_Applications
UserId(guid) foreign key to aspnet_Users
News (ntext)
This database will be used by different partners, each website will have a setting in web.config with<membership defaultProvider="SqlPersonalizationProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="SqlPersonalizationProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="NewsDB"
applicationName="/Company1"
.........................
in website i can get Memebership.GetUser() to get UserId,but how to pass it to Business Layer,i dont know. Is Edit.aspx or Insert.aspx allow to assign UserId/ApplicationId? Because this fields are not
editable.
Thursday, August 28, 2008 10:41 AM -
User-330204900 posted
Note if these are columns in your model then they should be available to you even if they are set to ScaffoldColumn false. see below eample:
public partial class NorthwindDataContext : System.Data.Linq.DataContext { partial void InsertCustomer(Customer instance) { var user = HttpContext.Current.User; instance.CreatedBy = user.Identity.Name; instance.CreatedOn = DateTime.Now; instance.UpdatedBy = user.Identity.Name; instance.UpdatedOn = DateTime.Now; // finally send this to the DB this.ExecuteDynamicInsert(instance); } partial void UpdateCustomer(Customer instance) { var user = HttpContext.Current.User; instance.UpdatedBy = user.Identity.Name; instance.UpdatedOn = DateTime.Now; // finally send this to the DB this.ExecuteDynamicUpdate(instance); } }
Hope this helps [:D]Thursday, August 28, 2008 1:23 PM -
User188291263 posted
Steve,
I dont have access to HttpContext in my layer.This layer independent from System.Web. Thats why im having problem.
Thursday, August 28, 2008 2:01 PM -
User188291263 posted
Fixed problem
I have to sync both in Application_AuthenticateRequest
HttpContext.Current.User = principal;
Thread.CurrentPrincipal = principal;
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 29, 2008 4:06 PM