Membership.GetUser() Vs Context.User?

Apr 29, 2010

What are the differences between Membership.GetUser() and Context.User, and which is recommended for use in getting information about the current user?

View 2 Replies


Similar Messages:

DataSource Controls :: BLL And Membership.getuser()?

Feb 23, 2010

I have a TableAdapter that queries a table by UserName. The TableAdapter works fine if I preview data and supply a username. I'm trying to become more familiar with BLLs . I can't find any good examples on using the BLL as the datasource and supply the membership.getuser().username to the DAL. Here is what I tried so far, but membership.getuser can not be a string.

Imports DataSet1TableAdapters
Public
Class UserProfilesBLL
Private UserProfilesAdapter
As UserProfilesTableAdapter =
Nothing
Protected
ReadOnly
Property Adapter()
As UserProfilesTableAdapter
Get
If UserProfilesAdapter
Is
Nothing
Then
UserProfilesAdapter =
New UserProfilesTableAdapter()
End
If
Return UserProfilesAdapter
End
Get
End
Property
Public
Function GetDataByUserName(ByVal
serName As
String)
As DataSet1.UserProfilesDataTable
Dim u
As MembershipUser
u = Membership.GetUser().UserName.ToString
Return Adapter.GetDataByUserName(u)
End
Function
End
Class

View 2 Replies

Security :: How To Override Membership.GetUser()

Sep 22, 2010

i have add a new column (CustomeAuth) to aspnet_Users but i need to get the value of this column just like:

Membership.GetUser().UserName

so i can use :

Membership.GetUser().CustomeAuth

View 3 Replies

Security :: Membership.GetUser() Using FireFox Browser

Jun 2, 2010

I am finishing up my asp.net web application targeting .net 4.0. I am using VS2010.

I have deployed my application to a host server and now I am testing with multiple different browsers.

The first issue I ran into comes down to the following code:

[Code]....

If I use IE, login and click something that causes the above code to execute then currentUser is NOT null. However doing the exact same steps in FireFox currentUser is null, even though I know I am logged in as my name and other indications on the webpage confirms I am.

------------------------

Update

----------------------

Since originally posting this thread I have done more testing.

I placed a test button on a random page and the button click will update a label on that page indicating if the currentUser is null or not. This button works both in IE and in FireFox. Also both running locally and running on the host server.

----------------------

So now I am looking at what is different about the one place it appears not to work so let me try to make this clear.

I use a component called Uploadify to upload images into a database. That component calls a page/request called ImageUploader.ashx which inherits from IHttpHandler. Here is all the pertainent code from that file.
[Code]....

The problem is when calling from FireFox, imgProvider.Status = null. This is a problem because the ImageProvider will try to insert a record into my database and the column for Status cannot be null so that causes it to crash. I made the change to detect if Status = null and return the user id if so as an error message to help me debug. To understand how Status is set you only have to look at a little code in the ImageProvider class:

[Code]....

You will notice when the ImageProvider is created it calls ClearFields(). Inside ClearFields() is where it gets the currentUser and if not null it sets the UserID property, which case the setter for UserID must set Status to either Approved or Pending. Whats happening is ONLY in FireFox, and after more testing, ONLY on the host server does currentUser = null even when I am logged in. but in other areas of code I can get currentUser and it works, also this works fine with IE, it also works fine with FireFox running locally. So I have icolated it down to this specific piece of code, when using FireFox, when running on Host server.

View 9 Replies

Security :: Membership.GetUser().UserName On Login Page?

Oct 16, 2010

I have an Employee class in my App_Code folder. On my login page I am trying to create an Employee using the asp.net username as a parameter in my Employee constructor.

I have tried creating the employee in the page load event when it is a post back. I have tried doing it in the Login1_LoggedIn event. For some reason I cannot pull the username in either one of these places, but if I redirect after logging in and do the same thing on another page, it works.

How can I get it done on the login page?

[Code]....

View 3 Replies

Security :: Membership.GetUser(object ProviderUserKey) Throws InvalidCastException In .NET 2.0?

Jan 10, 2011

I have an application that has been running for about 1.5 years. Suddenly, I got a bug report that the support team are receiving an InvalidCastException in the User ManagerUnable to cast object of type 'System.Guid' to type 'System.String'. The line this appears to be happening on is:

string queryStringID = Session["EditID"].ToString();
Guid providerUserKey =
new
Guid(queryStringID)
MembershipUser user =
Membership.GetUser(providerUserKey);
<--- here

This is a rather strange error as the value of the queryStringID is in fact a Guid generated by the Membership.GetUser(UserName).ProviderUserKey on the previous page. It doesn't seem to make any sense at all. I'm using the built-in SqlMembershipProvider with no changes. It's as if it isn't picking up that it should be using the overloaded function Membership.GetUser(object providerUserKey)Anyone else ever seen anything like this? I wouldn't normally post here unless I was absolutely stuck but I can't seem to find any relevant information by Googleing this one. Also, it's just started doing this. There was never an issue before. Very strange

View 5 Replies

Security :: Membership.getuser() Returns Null In Ff And Chrome But Works Fine In IE

Mar 29, 2010

I have strange problem with the membership provider on my mvc application.

I have a webforms page inside admin folder which calls the following code in the models directory.

public int SaveUploadedFile(HttpPostedFileBase fileBase)

View 2 Replies

Intermittent Membership.GetUser() Error - Unable To Cast Object Of Type System.Guid?

Jan 24, 2011

This error is occuring randomly, and I can't seem to pinpoint what is causing it. For the most part, the code works fine. I'm confused why it works sometimes, but then suddently craps out on me, lol.It happens in the code when I call upon the asp.net membership provider. It only seems to happen when i use Membership.GetUser() to grab the logged in user's information.

View 9 Replies

VS 2008 - Context.User.Identity.Name Is Empty

Oct 17, 2010

After setting the auth cookie using

FormsAuthentication.SetAuthCookie("myusername", False)
server.transfer("somepage.aspx") to open a web page.
Context.User.Identity.Name is found to be empty

But if I use

Response.Redirect("somepage.aspx")
Context.User.Identity.Name provides correct result.

I am aware of the differences between Response.Redirect and server.transfer. But exactly what is the reason behind this particular behaviour ?

View 1 Replies

Context.User.Identity.IsAuthenticated Always Authenticated?

Mar 3, 2011

I am trying to create a httphandler which will intercept a sample pdf file which we have in our website. The httphandler works fine from within my development machine and even my locally published website that if I just try to connect to the test url: [URL] I will get sent to the invalid access page. So pushing it to our IIS6 machine when I try to go to the URL it serves up the PDF document. context.User.Identity.IsAuthenticated is always showing as true. I'm using forms authentication. below is the code I am using as the handler.

public void ProcessRequest(HttpContext context)
{
if (context.User.Identity.IsAuthenticated)
{
string SampleURL = context.Request.AppRelativeCurrentExecutionFilePath;
context.Response.Buffer = true;
context.Response.Clear();
using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(SampleURL),FileMode.Open))
{
int length = (int)fs.Length;
byte[] buffer;
using (BinaryReader br = new BinaryReader(fs))
{
buffer = br.ReadBytes(length);
}
context.Response.Clear();
context.Response.Buffer = true;
context.Response.ContentType = "application/pdf";
context.Response.BinaryWrite(buffer);
context.Response.End();
}
}
else
{
context.Response.Redirect(
"~/Error/invalid_access.aspx");
}}

in web.config I have the following for form authentication:

<authentication mode="Forms">
<forms name="Sample.Web" loginUrl="~/Security/" defaultUrl="~/default.aspx" protection="All" timeout="60" path="/" requireSSL="false" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile" domain="">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>

View 3 Replies

Configuration :: .net App That Calls An Exe Under Alternate User Context?

Mar 28, 2011

I'm banging my head against a wall here... can't get to the bottom of this issue. I have code that works fine when debugging in visual studio but breaks when deployed to both IIS 6 and IIS 7.5. Basically, it uses Process and ProcessStartInfo to start a program
(a command line tool, exe) and redirect the output to the web page. It uses the username and password properties of the ProcessStartInfo class to run the exe tool as a specific user. The tool requires admin privelages so I need to run it as such, but certianly don't want to run the IIS service or the asp.net app pool under an admin context.

No exception occurs when run on IIS, but it does not work, when trying to run on IIS 6 I get this error dialog: "The application failed to initialize properly (0xc0000142). Click on ok to terminate the application." It's obviously a security/config issue, but what specifically is the culprit? For IIS 6, an application pool was created for this, runs under 'network service', as usual, but again the process being started by the system.diagnostics.process class is run under a different account, which is an administrator account. For IIS 7.5, same thing,an app pool was created, so it runs under the 'iis appPoolNameOfPool' context.

View 6 Replies

Security :: The Name 'User' Does Not Exist In The Current Context?

Jan 1, 2010

On my master page i have a link button which should be visible only by Administrator or Supervisors roles.

So in the code behind file of the master page i have put the following code in page load event

[Code]....

but i am getting following error

The name 'User' does not exist in the current context

View 2 Replies

Security :: Dynamically Create Membership User And Check If User Name Is Valid Or Used?

Jul 25, 2010

I am createing user dynamially with the below code; string MyPassword = Membership.GeneratePassword(8,0).ToString(); Membership.CreateUser(TextBox7.Text, MyPassword, TextBox8.Text); but before I start creating, I would like to check if the user name is used before or not.

View 2 Replies

Security :: Store User Password In Custom Membership User

Aug 12, 2010

I have a custom membership user class and custom MembershipProvider working against database. Due to security reasons the user passwords are stored in the database as hashed values. So my procedure

public override bool ValidateUser(string username, string password) is
{
//select hashed password from db
return (EncodePassword(password) == dbpassword)
}
[code]....

View 4 Replies

Security :: Transfer ProfileCommon Context To Authenticated User

Feb 7, 2010

I currently have a ProfileCommon enabled on my site and would like to know where I would start to transfer this ProfileCommon's context to a user's profile after he/she has logged in. Here is a snippet of how I have defined this ProfileCommon:

[Code]....

View 2 Replies

C# - Difference Between Http.context.user And Thread.currentprincipal And When To Use Them

Jun 16, 2010

I have just recently run into an issue running an asp.net web app under visual studio 2008. I get the error 'type is not resolved for member...customUserPrincipal'. Tracking down various discussion groups it seems that there is an issue with Visual Studio's web server when you assign a custom principal against the Thread.CurrentPrincipal.

In my code, I now use...

HttpContext.Current.User = myCustomPrincipal
//Thread.CurrentPrincipal = myCustomPrincipal

I'm glad that I got the error out of the way, but it begs the question "What is the difference between these two methods of setting a principal?". There are other stackoverflow questions related to the differences but they don't get into the details of the two approaches.

I did find one tantalizing post that had the following grandiose comment but no explanation to back up his assertions...

[code]....

View 3 Replies

Context Of An Asp.net Website - Way To Check Whether User Has Access To A Particular Record

May 26, 2010

I have a webpage that you pass in an id parameter (via a querystring), which it then uses to fetch data from a database. Typically, a user would navigate to this page from another page that lists only those records that the user has access to. However, if they go directly to the page by typing in the URL in the Address Bar, they can effectively view any record they like. to type something like http://localhost/TestSite/ClientAdmin/ManageLocation.aspx?LocationID=5 into their Address Bar, they can access the database record with the LocationID equal to five - even though they shouldn't have access to it

View 2 Replies

Security :: Set Context.User.Identity.name When Using The Login Controls?

Jun 13, 2010

To avoid going to the Databse to get the user Id, Id like to append userId to the Context.User.Idenity.name field. This way I can split the returned string to get the UserId without going to the database.

Where can I do this when using the login controls?

Is there some event handler where I can add:

FormsAuthentication.SetAuthCookie(NamePlusUserID, false);

View 1 Replies

Security :: GetUser() Does Not Exist?

Dec 2, 2010

This has got to be simple so I am just going to post my code and then list the error I am getting:

[Code]....

When I do a build I get the following error message:

The type or namespace name 'GetUser' does not exist in the namespace 'ScoutingAssistant.Membership' (are you missing an assembly refrence?)

Now if I change Membership.GetUser() to System.Web.Security.Membership.GetUser() it works just fine. But I thought by adding:

using System.Web.Security;

to the top of the unit would prevent me from have to prefix Membership but it seems to be ignoring my using statement.

View 4 Replies

Security :: Setting HttpApplication.Context.User Is Terribly Slow?

Mar 17, 2010

Does anyone have a clue why setting the Principal for the context would be so slow that a request times out? I have a custom HttpModule that subscribes to the "AuthenticateRequest" event. I have this call which works fine to create the Principal (which makes all the DB queries)

[Code]....

where context.User is source.Context.User where source is the HttpApplication.

View 2 Replies

NullReferenceException In Global.asax When Referencing Context.User.Identity In Session_Start

Sep 30, 2010

When I am debugging an application in ASP.NET, after about ~5 minutes I get a NullRefEx coming from global.asax.cs regarding:

protected void Session_Start(Object sender, EventArgs e)
{
WindowsIdentity identity = null;
identity = (WindowsIdentity)(Context.User.Identity);
...

Context is Null at this point. I am a noob in ASP.NET with regards to Global.asax.cs. This code was written by another developer. EDIT: This is the code with HttpContext...

protected void Session_Start(Object sender, EventArgs e)
{
WindowsIdentity identity = null;
identity = (WindowsIdentity)(HttpContext.Current.User.Identity);

View 1 Replies

Security :: IIS7 Recycle Results In Context.User.Identity.IsAuthenticated = False?

Nov 22, 2010

I need an app pool recycle to be completely transparent to the users of my web app. I use ASP.NET 3.5 MVC 1.

Currently, upon an IIS 7 App Pool recycle all users logged into my web app are kicked out and are required to log back in (Context.User.Identity.IsAuthenticated is set to false). I employ SQL State Server, I use forms authentication and both are configured to use cookies. I was under the impression that .NET and/or IIS handles authentication of cookies.

However, every time the app pool is recycled Context.User.Identity.IsAuthenticated is set to false my users are kicked out and are required to log back in. I can see that the session id remains the same throughout logins, I can also view this session information in the database/state server.

Logon method:

[Code]....

Custom Controller Attribute:

[Code]....

WebConfig:

[Code]....

View 1 Replies

Asp.net - IIS7 Itegrated Pipeline Mode: Context.User Is Intermittently Null For Windows Auth?

May 19, 2010

Our code relies on checking the Context.User.Identity value in the Global.asax Application AuthenticateRequest(...) method to retrieve some information about the logged in user. This works fine in classic mode but when I flip IIS to use the Integrated Pipeline "Context.User" comes back as null, but only intermittently.I have < authentication mode="Windows"> and only Windows Auth enabled in the Virtual Directory.

View 1 Replies

.net - Use Of User.IsInRole Without Using Membership ?

Feb 17, 2010

I'm using Forms authentication and I would like to make use of roles, can I somehow set the role of the user without Membership ?

View 4 Replies

Web Forms :: How To Log Out User In Membership

Jun 7, 2012

how to perform log out task in web page in different forms

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved