Casting - Cast MembershipUser To Custom Class (ASP.NET)?

Oct 15, 2010

I'm using the default SqlMembershipProvider,but I've created a custom MembershipUser class (SoeMembershipUser) because I needed a "DisplayName" property.All the DisplayName does is look at the UserName and format it differently.When I try to cast a MembershipUser to a SoeMembershipUser user I get an InvalidCastException.

Exact error is:
"Unable to cast object of type 'System.Web.Security.MembershipUser' to type 'Soe.Tracker.SoeMembershipUser'."

Here is the code that fails:

SoeMembershipUser user = (SoeMembershipUser)Membership.GetUser(username); // invalid cast

I have also tried casting later like so:

MembershipUser user = Membershipship.GetUser(username); // ok
...
string displayName = ((SoeMembershipUser)user).DisplayName; // invalid cast

Here is the SoeMembershipUser class:

NOTE: I left off the constructors at first, but added them in later when I started having problems. Adding them made no difference.

public class SoeMembershipUser : MembershipUser
{
public SoeMembershipUser()
: base()

[code]...

View 2 Replies


Similar Messages:

Security :: Can Implement Custom MembershipUser/custom Roles And Membership Provider

Oct 13, 2010

I create custom principal for implement logic for users. In identity I store Id, Name. But it abnormally - this classes must use for authenticate and authorize.

I can implement custom MembershipUser, custom Roles and Membership provider.

How to do it? What best practices are?

View 5 Replies

Security :: Use Of The MemberShipUser Class?

Mar 9, 2011

What is the use of the MemberShipUser Class and can we use our own database with MemberShip User Class? Please provide me the some example.

View 1 Replies

C# - Class Library Can't Find MembershipUser

Jan 16, 2011

I've added a class library project to my application.

In one of my classes, I need to use the MembershipUser class, but the project can't find it. I've added references to System.Web, System.Web.Security, and System.Security.Principal.

View 1 Replies

C# - MembershipUser Class - Comments Method Doesn't Work?

Nov 16, 2010

I'm unable to set Comments property of a MembershipUser type objects.

E.g.

MembershipUser mu = Membership.GetUser(username);
mu.Comment = "someComments";

I'd expect this to set the Comment property of mu object to "someComments" and write changes to the database.

Later, I do a following check:
mu.Comment == "someComments";

Comment property is set to null. Is there anythign that I need to change in a web.config or...?

View 2 Replies

C# - Implement Custom MembershipUser And MembershipProvider

Apr 4, 2011

I try to implement a Custom MembershipPriver with a Custom MemberShipUser in my own database (with a specifics Users Table Model) : This is ly diffent files:

iTwitterMembershipProvider.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Collections.Specialized;
using iTwitter.Models;
public class iTwitterMembershipProvider : MembershipProvider
{
public override string ApplicationName
{
get { return _ApplicationName; }
set { _ApplicationName = value; }
}
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
throw new NotImplementedException();
}
public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
{
return false;
}
public override iTwitterMembershipUser CreateUser(string login,
string password,
string email,
string tokenKey,
string tokenSecret,
string twitterUserId,
object providerUserKey,
out MembershipCreateStatus status)
{
ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(login,
password,
true);

[Code.....]

View 2 Replies

Unable To Create MembershipUser For Custom MembershipProvider

Oct 28, 2010

I created a custom membership provider and am getting the following error trying to create a new "MembershipUser".

Could not load type 'MyTestApp.Membership.TestMembershipProvider' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I am running this from a Unit Test project, so I'm not sure if that's causing the issue, but I did include System.Web, System.Web.ApplicationServices as well as a reference to MyApp.Membership and MyApp.DataModels (Entity objects).

The error happens inside my "GetUser" function which is below, my configuration is also below.

[code]....

View 1 Replies

Security :: Using Custom Membershipuser To Create Users In The AD With Membership?

Jul 28, 2010

I'm have a doubt using membershipuser to create users in the AD with Membership.CreateUser Method, does any one knows how can i send other attibutes to the AD, such as First Name and Last Name?, besides those ones: username

As String, _

password As String, _

email As String, _

passwordQuestion As String, _

passwordAnswer As String,

View 3 Replies

Security :: Custom Membership Provider / How To Pass A New MembershipUser To The Validate Method

Jan 29, 2010

Writing a custom membership / role provider and have to validate user with extra parameter to Membership.Validate. So, instead of Membership.Validate(username, password) I need Membership.Validate(username, password, client).

Is this possible with the existing MembershipProvider? I would have liked to pass a new MembershipUser to the Validate method but didn't see anything that would work for that.

View 1 Replies

Unable To Cast A Partial Class Based On LINQ To SQL Object

Mar 28, 2011

I have a database table called Animals which I drag on to my Linq to SQL DBML file.

This creates me a class called Animal.

I then create a class to extend it, like so:

public partial class Animal{
//my extra code here
}

But what I also want to do is have a class like this:

public class Zebra : Animal{
//even more extra code here
}

The trouble is I get an InvalidCastException from my repository, when I do this:

Animal a = dataContext.Animals.Where(c=>c.id.Equals(id)).SingleOrDefault();
return (Zebra)a;

I've stripped back my classes to the point where they're completely empty in an attempt to work why it doesn't work. To no avail.

This casting process did used to work in the non-LINQ-2-SQL project that I'm switching to MVC/LINQ.

View 1 Replies

Security :: Unable To Cast Custom Identity When Using Application_AuthenticateRequest?

Feb 8, 2010

When I add

if (Context.User != null)
{
if (Context.User.Identity.IsAuthenticated)
{
if (!(Context.User is AdministratorPrincipal))
{
Admin.Web.Principal.AdministratorPrincipal newUser = new Admin.Web.Principal.AdministratorPrincipal(Context.User.Identity.Name);
}
}
}

to Application_AuthenticateRequest in global.asax file i always get an error when I try to reference it

Unable to cast object of type 'Admin.Web.Identity.AdministratorIdentity' to type 'Admin.Web.Identity.AdministratorIdentity'.
protected void Page_Load(object sender, System.EventArgs e)
Line 26: {
Line 27: this.adminID = ((AdministratorIdentity)HttpContext.Current.User.Identity).AdminID.ToString();
Line 28: }

I did a test and tried to move the code from global.asax to a Page_Load() of webform and worked fine.

View 1 Replies

Security :: Specified Cast Is Not Valid - Custom Oledb Role Provider?

Feb 5, 2010

I have a custom oledb role provider that pretty much a cust and past of:

[URL]

except I've used oledb instead of odbc. I'm connecting to an oracle database and the tables have been created with out any issues. now if I go into the Website Administration Tool and try to create a new role I get the error

"Specified cast is not valid."

I can create a role directly in the database (through TOAD) and the role will show up in the .NET WAT, so I know it can make the connection and read the info just fine. I just can't create or delete or modify a role without the above error.

I'm using C# in VS 2008 Pro.

My provider code is as follows:

[Code]....

View 1 Replies

Mvc - Can Set A Custom Class As The Default Base Class For Controllers In MVC3

Feb 15, 2011

I'd like to inherit all my controllers from a custom base class that I write myself. I can change the line every time I add a new controller, but it would be nicer if I could somewhere specify the default value that gets set there. That way I wouldn't need to worry about forgetting this, and other people who get added to the project later on would have an easier time.

View 3 Replies

Custom Server Controls :: Implementing An Interface From A Class Library In A Custom Control?

Jul 8, 2010

I'm building an n-tier application, with the web client and the class library separate. I'm also using the factory pattern of development, using interfaces to act as containers for different objects they are associated with. The problem I'm expreriencing is that I declared a public interface class in the class library and I can create an instance of it in in my aspx pages but whenever I declare it in my custom control code-side, i get an error, like so:

Error 20 The type or namespace name 'IContentMaker' could not be found (are you missing a using directive or an assembly reference?)

notge that I have inherited the class library namespace using the 'using' keyword just in case you are wondering. My code is like so:

using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TQO_Classes ; //importing the class library project
public partial class PageContentMgr : System.Web.UI.UserControl
{
private IContentMaker _data; //this line throws the error, it works fine on aspx pages

View 1 Replies

Is There A Way To Call Custom Method Of Custom Role Provider Class

Apr 21, 2010

I have created my own custom role provider class "SGI_RoleProvider" and configured properly.

Everything is working fine.

Suppose that I have added a public method say "SayHello()", then how can i call that. Because if i am using Roles then the method is not displayed. If i am forcefully using that Roles.SayHello() then compiler gives the error.

how can i call this. Because creating a new instance of SGI_RoleProvider is meaningless.

View 1 Replies

C# - Unable To Cast Page As Page Class?

Jan 19, 2011

I'm attempting to access data on a parent page from a user control. I understand this is not the best way to go about it and I do not want to get into that debate. This is HOW I have to go about it due to constraints beyond my control and pay grade.I should be able to do this:

myWebBase myPage = (myWebBase) Parent.Page;
int x = myPage.getX();

But the class name myWebBase is not recognized.

View 2 Replies

Cast Ienumerable Into Specified Cast Using Cast?

May 1, 2010

I have following code in my class file which returns me the Date field in format like 4/4/2010 12:00:00 AM from SQL SERVER

public IEnumerable Mthgetcomplaintdate()
{
var v = objderma.USP_Patient_Dermatology_Complaints_RepDate(PatientID); ;
return v as IEnumerable;
}

But on my aspx page i want to display only the Date part not time.One way is i will iterated throgh my dropdownlist which am binding with the above method and i convert it using Toshortdatestring() method.But i want to cast the whole Ienumerable result using some method? I have read about cast<> ,but could not understand how to implement it exactly.

View 1 Replies

Custom Server Controls :: Custom Server Control Rendering Method In Multiple Class?

May 17, 2010

I am creating custom server control. I have two classes in project. One is main class that render control and another will be used to render content based on condition.I just want to know how to render content from other classes in main class.For example. This isjust an example.My main class code

[Code]....

My TopLeftPane class

[Code]....

My page code on page load event

[Code]....

When I run the page, Header title always getting null. This is a just sample code. I will have more than 20 classes so I dont want to write a code in main class to render whole control.I hope all of you understand my problem.

View 3 Replies

C# - Returning Custom Class From DAL?

Mar 25, 2011

I have an object with following attribute Books ---------- ID , Name

Now, I want to return an object for a gridview in presentation layer which has a lot more attributes then the original object

I don't have any business object composed of these attributes currently & I don't want to create it just for the sake of a gridview.

How do I create & return custom objects like these on the fly ? I am new to DTO's. Can someone give me an example to return a DTO inside my DAL ?

View 3 Replies

C# - MembershipUser Retrieve Data From GridView?

Oct 15, 2010

I need to set IsApproved = true; for a User (using MembershipUser) when I select a CheckBox in a GridView.

The event handler uxRoleCheckBoxSelector_CheckChanged it is setted on the actual CheckBox.

Could you tell me guys what I am doing wrong?

Script does not generate any Exception but does not work.

[Code]....

View 1 Replies

Security :: MembershipUser.ProviderUserKey.ToString?

Mar 20, 2011

When I run the following debugging code it writes out credits:0

Dim MembershipUser As MembershipUser = Membership.GetUser()
Dim UID As String = MembershipUser.ProviderUserKey.ToString
SQL = "SELECT SUM(Credits) As Credits FROM Credits WHERE " & _
"DateDiff(m, [DateTime], GETDATE()) < 6 AND [UserID]=@UserID;"
cmd = New SqlCommand(SQL, Conn)
cmd.Parameters.Add(New SqlParameter("@UserID", UID))
DataReader = cmd.ExecuteReader()
If DataReader.HasRows Then
Do While DataReader.Read

[Code]....

View 4 Replies

How To Remove A Control From Custom Class

May 4, 2010

i have created a class with a sub, which removes a control from the original page...

for example, in the original page:

Code:

dim usertextbox as new textbox
usertextbox.id = "TEXTBOXIE"
form1.controls.add(usertextbox)
in the class:

Code:

public sub DeleteTextBox
dim pagetextbox as textbox
pagetextbox = page.findcontrol("TEXTBOXIE")
if not pagetextbox is nothing then
page.controls.remove(pagetextbox)
end if
end sub

the code in the class doesn't work..

View 2 Replies

Add A Custom Base Class For Web Forms?

Jan 12, 2010

I want to add a custom base class for all of my web forms. I created a "App_code" folder in my asp.net web project and add a simple base page class like this:

namespace MySite.Web
{
// base page for all the pages that need localization
public class LocalizationPage : System.Web.UI.Page
{
protected override void InitializeCulture()
{
base.InitializeCulture();
}
}
}

And then I try to let asp.net web form to inherit from this base page. I have something like this:

using MySite.Web;

namespace MySite.Public
{
public partial class RegisterPage : LocalizationPage
{
}
}

Now I run into problem where Visual Studio doesn't recognize the LocalizationPage class I created. On the above code snippet, LocalizationPage is not highlighted as a class. And when I try to compile, I got the following error message:

Error 1 The type or namespace name 'LocalizationPage' could not be found (are you missing a using directive or an assembly reference?)

View 1 Replies

How To Debug The Custom Class Library

Feb 3, 2010

I have Web Service in Asp.Net Application, i create a break point in Web service. In the web service i create a instance for custom class library and call a method inside the Class library. When i run the Application i can able to debug the Web service that i create the break point, but i want to debug that custom class library code also how to deug this.

When i try to debug by add custom class library inside the current solution, but am unable to debug that custom class library code.

View 2 Replies

C# - Map Class To Get The Db's Records With A Custom Method?

Apr 1, 2010

I'm developing a website with ASP.NET MVC, NHibernate and Fluent NHibernate and want to know how can I customize my Map to get records using a custom Method.

My entities:

public class ImageGallery {
public virtual int Id { get; set; }
public virtual string Titulo { get; set; }
public virtual IList<Image> Images { get; set; }
ublic virtual bool IsActive { get; set; }
}
public class Image {
public virtual int Id { get; set; }
public virtual ImageGallery ImageGallery { get; set; }
public virtual string Low { get; set; }
public virtual bool IsActive { get; set; }
}


My Fluent NHibernate Maps:

public class ImageGalleryMap:ClassMap<ImageGallery> {
public ImageGalleryMap() {
Id(x => x.Id);
Map(x => x.Titulo);
HasMany(x => x.Images)
.KeyColumn("ImageGalleryID");
Map(x => x.IsActive);
}
}
public class ImageMap:ClassMap<Image> {
public ImageMap() {
Id(x => x.Id);
References(x => x.ImageGallery);
Map(x => x.Low);
Map(x => x.IsActive);
}
}

And, a method on my ImageRepository class:

public IList<Image> ListActive() {
return this.Session.CreateCriteria<Image>()
.Add(Restrictions.Eq("IsActive", true))
.List<Image>();
}

If I create an object this way:

ImageGallery ig = new ImageGallery();

I can access my the Image's list using:

foreach(Image img in ig.Images) {
...
}

However, ig.Images give me access to all images records and I would like to access just active records (or another criteria), using ListActive()'s repository methods.

View 1 Replies







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