<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Security</title><link>http://forums.asp.net/25.aspx</link><description>All about ASP.NET security (authentication, authorization, membership, roles, etc.) and the Login controls. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=24&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3279390.aspx</link><pubDate>Tue, 07 Jul 2009 15:29:01 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3279390</guid><dc:creator>papabear</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3279390.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3279390</wfw:commentRss><description>&lt;p&gt;You can use it, but what you need to so is simply cast it as the appropriate class. Remember inheritance - your class can &amp;#39;become&amp;#39; a Membership.Provider, but a Membership.Provider can NOT become your class...&lt;/p&gt;&lt;p&gt;You HAVE to use your own class because of inheritance. No way around the concrete rules of OO...&lt;/p&gt;&lt;p&gt;:)&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3279350.aspx</link><pubDate>Tue, 07 Jul 2009 15:11:48 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3279350</guid><dc:creator>RickNZ</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3279350.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3279350</wfw:commentRss><description>&lt;p&gt;You can put the module anywhere, as long it can be referenced (implicitly!) from the class where you want to call it (through an appropriate Imports statement, for example).&amp;nbsp; Extension methods are &amp;quot;magic&amp;quot; that way.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s are a couple of links that describe them in more detail; maybe they will help:&lt;/p&gt;&lt;p&gt;http://msdn.microsoft.com/en-us/magazine/cc163317.aspx&lt;/p&gt;&lt;p&gt;http://blogs.msdn.com/vbteam/archive/2007/01/05/extension-methods-part-1.aspx&lt;/p&gt;&lt;p&gt;Your comment about extensibility is correct.&amp;nbsp; It&amp;#39;s a characteristic of the language, though, more than that particular code.&lt;/p&gt;&lt;p&gt;FWIW, I made a test extension method (in C#) for MembershipProvider, and it worked fine...&amp;nbsp; One quick test you might try is to see if the extension method shows up in Intellisense from within the extension method itself.&amp;nbsp; If not, then you might have the function signature wrong.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3279163.aspx</link><pubDate>Tue, 07 Jul 2009 13:54:00 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3279163</guid><dc:creator>vipergtsrz@gmail.com</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3279163.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3279163</wfw:commentRss><description>&lt;p&gt;Hey Rick,&lt;/p&gt;&lt;p&gt;I guess my problem is that I don&amp;#39;t know where to put this module and how that module is associated with the Membership provider.&lt;/p&gt;&lt;p&gt;After doing some more research, I now know that I can&amp;#39;t add functions to the Membership Provider because it&amp;#39;s not meant to be extended like that. &lt;/p&gt;&lt;p&gt;I still can&amp;#39;t get it to be called by doing the Membership.Provider.GetUserIDFromUsername() call. &lt;/p&gt;&lt;p&gt;I think I&amp;#39;m just spending too much time caring about how this function is called when I can just cast my Membership Provider and deal with it. I just expected the Base Membership Provider to be more extensible I guess.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3278082.aspx</link><pubDate>Tue, 07 Jul 2009 05:36:58 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3278082</guid><dc:creator>RickNZ</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3278082.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3278082</wfw:commentRss><description>&lt;p&gt;The &amp;lt;Extension()&amp;gt; attribute tells the compiler that the method is an extension method.&amp;nbsp; You definitely should not have to call it as you said in your post.&lt;/p&gt;&lt;p&gt;It should be Membership.Provider.GetUserByName(&amp;quot;username&amp;quot;);&lt;/p&gt;&lt;p&gt;If it compiles the way you had it, then you have the arguments backwards.&amp;nbsp; The class to which the extension method should be added must be the first argument.&lt;/p&gt;&lt;p&gt;Things to check:&lt;/p&gt;&lt;p&gt;1. Make sure that the namespace/class in which the extension method is located can be referenced from the class where you&amp;#39;re using it.&lt;/p&gt;&lt;p&gt;2. Intellisense understands extension methods.&amp;nbsp; Type Membership.Provider.&amp;nbsp; -- and it should be listed there.&amp;nbsp; If it isn&amp;#39;t, then something isn&amp;#39;t set up right.&lt;/p&gt;&lt;p&gt;If that doesn&amp;#39;t work, post your code for the extension method and I&amp;#39;ll take a look.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3276798.aspx</link><pubDate>Mon, 06 Jul 2009 13:10:44 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3276798</guid><dc:creator>vipergtsrz@gmail.com</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3276798.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3276798</wfw:commentRss><description>&lt;p&gt;Hey Rick,&lt;/p&gt;&lt;p&gt;I&amp;#39;m tried using your suggestion, but I&amp;#39;m not sure it does what I was expecting. &lt;/p&gt;&lt;p&gt;In order to call that function on the front end, I would have to do something like&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="vb.net"&gt;Extensions.GetUserIDByUsername(&amp;quot;username&amp;quot;, Membership.Provider)&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; Right?&lt;/p&gt;&lt;p&gt;I have spent a lot of time looking into this and it seems like the Membership Provider just can&amp;#39;t be extended to allow for other functions to be added to it from the Membership namespace. I assume this is the same for the Roles and Profile Providers as well. &lt;/p&gt;&lt;p&gt;What does the &amp;lt;Extension()&amp;gt; do for me in the code you provided? I am still not able to call Membership.Provider.GetUserIDByUsername. &lt;/p&gt;&lt;p&gt;Maybe I just expected the Membership Provider to be more extensible than it is?&lt;/p&gt;&lt;p&gt;Thanks again for your help Rick!&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3274083.aspx</link><pubDate>Fri, 03 Jul 2009 23:27:23 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274083</guid><dc:creator>RickNZ</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274083.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3274083</wfw:commentRss><description>&lt;p&gt;My VB is pretty weak, but you could try something like the following, although you&amp;#39;ll need to make the connectionString property static:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="vb.net"&gt;Imports System.Runtime.CompilerServices

Module Extensions
         Private ReadOnly Property connectionString() As String  
             Get  
                 Return _sqlConnectionString  
             End Get  
         End Property  
 
         &amp;lt;Extension()&amp;gt;
         Sub GetUserIDByUsername(ByVal MembershipProvider prov,
             ByVal Username As String) As Guid  
             Using ccData As New Data.ccDataContext(connectionString)  
                 Dim usrID = (From m In ccData.Members _  
                               Where m.UserName = Username _  
                               Select m.UserId).SingleOrDefault()  
                 Return usrID  
             End Using  
         End Sub
End Module
  &lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3274004.aspx</link><pubDate>Fri, 03 Jul 2009 21:01:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274004</guid><dc:creator>vipergtsrz@gmail.com</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274004.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3274004</wfw:commentRss><description>&lt;p&gt;Double post, sorry...&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3274003.aspx</link><pubDate>Fri, 03 Jul 2009 20:56:31 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274003</guid><dc:creator>vipergtsrz@gmail.com</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274003.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3274003</wfw:commentRss><description>&lt;p&gt;Here is the snippit of my custom membership provider&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="vb.net"&gt;Namespace Providers
Public Class ccMembershipProvider
        Inherits MembershipProvider

        Private ReadOnly Property connectionString() As String
            Get
                Return _sqlConnectionString
            End Get
        End Property

        Public Function GetUserIDByUsername(ByVal Username As String) As Guid
            Using ccData As New Data.ccDataContext(connectionString)
                Dim usrID = (From m In ccData.Members _
                              Where m.UserName = Username _
                              Select m.UserId).SingleOrDefault()
                Return usrID
            End Using
        End Function

End Class
End Namespace&lt;/pre&gt;&lt;p&gt;In the web.config...&lt;br /&gt;&lt;/p&gt; &lt;pre name="code" class="xhtml"&gt;		&amp;lt;membership defaultProvider=&amp;quot;ccMembershipProvider&amp;quot;&amp;gt;
			&amp;lt;providers&amp;gt;
				&amp;lt;clear/&amp;gt;
				&amp;lt;add name=&amp;quot;ccMembershipProvider&amp;quot; type=&amp;quot;cc.Providers.ccMembershipProvider, cc&amp;quot; passwordFormat=&amp;quot;Clear&amp;quot; connectionStringName=&amp;quot;ccSQL&amp;quot; applicationName=&amp;quot;/&amp;quot; /&amp;gt;
			&amp;lt;/providers&amp;gt;
		&amp;lt;/membership&amp;gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt; And this is how I currently have to call it...&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="vb.net"&gt;Dim mem As ccMembershipProvider = CType(Membership.Provider, ccMembershipProvider)
mem.GetUserIDByUsername(&amp;quot;username&amp;quot;)&lt;/pre&gt;&lt;p&gt;&lt;br /&gt; The rest of my custom membership provider is basically just all the other MustOverride Functions that I have put code into that I need. When I call something like Membership.GetUserNameByEmail(Email), that works fine because it&amp;#39;s part of the base Membership class. It&amp;#39;s just the custom functions I make that I can&amp;#39;t do it.&lt;/p&gt;&lt;p&gt;If I can get it to a point where I can just call Membership.Provider.GetUserIDByUsername(&amp;quot;username&amp;quot;), that would be awesome.&lt;/p&gt;&lt;p&gt;Thanks for your help looking into this.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3273676.aspx</link><pubDate>Fri, 03 Jul 2009 14:28:21 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273676</guid><dc:creator>RickNZ</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273676.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3273676</wfw:commentRss><description>&lt;p&gt;Can you post your code?&lt;/p&gt;&lt;p&gt;Extension methods only work from class instances.&amp;nbsp; You can&amp;#39;t add new static methods, and you can&amp;#39;t instantiate the Membership class itself (all of its methods are static).&amp;nbsp; So, it wouldn&amp;#39;t be Membership.YourMethod().&amp;nbsp; It would probably be:&lt;/p&gt;&lt;p&gt;Membership.Provider.YourMethod();&lt;/p&gt;&lt;p&gt;With YourMethod() as an extension method of MembershipProvider.&lt;/p&gt;&lt;p&gt;Maybe not as clean as you were hoping, but it should still avoid a cast....&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3273533.aspx</link><pubDate>Fri, 03 Jul 2009 12:49:46 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273533</guid><dc:creator>vipergtsrz@gmail.com</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273533.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3273533</wfw:commentRss><description>&lt;p&gt;Thanks for your reply Rick,&lt;/p&gt;&lt;p&gt;I tried what you suggested, and I still can&amp;#39;t call the function from the Membership keyword.&lt;/p&gt;&lt;p&gt;The only way I can successfuly call my custom functions is if I cast Membership to my custom membership provider.&lt;/p&gt;&lt;p&gt;Any other suggestions?&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3272704.aspx</link><pubDate>Fri, 03 Jul 2009 05:22:44 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3272704</guid><dc:creator>RickNZ</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3272704.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3272704</wfw:commentRss><description>&lt;p&gt;Would an extension method work for you?&lt;/p&gt;&lt;p&gt;Something like this:&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;public static class MyProvider
{
    public static string GetUserIDFromUserName(this Provider prov, string name)
    {
        . . .
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; That would let you call Provider.GetUserIDFromUserName(), as an instance method (not a static method).&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Custom Membership Provider Using Additional Functions</title><link>http://forums.asp.net/thread/3272296.aspx</link><pubDate>Thu, 02 Jul 2009 21:31:42 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3272296</guid><dc:creator>vipergtsrz@gmail.com</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3272296.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=3272296</wfw:commentRss><description>&lt;p&gt;I have built a custom membership provider that inherits from the MembershipProvider class. In my custom provider, I have defined a few new functions that I need to use, but my issue is that I can&amp;#39;t access those functions on the front end using the Membership namespace.&lt;/p&gt;&lt;p&gt;So in my default.aspx code behind, I would like to call a function GetUserIDFromUserName() by just typing Membership.GetUserIDFromUserName(). &lt;/p&gt;&lt;p&gt;In order for me to be able to do that right now, I have to cast Membership to my custom provider like this&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="vb.net"&gt;Dim mem As ccMembershipProvider = CType(Membership.Provider, ccMembershipProvider)&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; In my web.config I have the following code&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="xhtml"&gt;&amp;lt;membership defaultProvider=&amp;quot;ccMembershipProvider&amp;quot;&amp;gt;
			&amp;lt;providers&amp;gt;
				&amp;lt;clear/&amp;gt;
				&amp;lt;add name=&amp;quot;ccMembershipProvider&amp;quot; type=&amp;quot;cc.Providers.ccMembershipProvider, cc&amp;quot; passwordFormat=&amp;quot;Clear&amp;quot; connectionStringName=&amp;quot;SQLConnectionString&amp;quot; applicationName=&amp;quot;/&amp;quot; /&amp;gt;
			&amp;lt;/providers&amp;gt;
		&amp;lt;/membership&amp;gt;&lt;/pre&gt;How can I make it so Membership is pulling from my class that is inheriting from that without having to cast it to my provider every time?&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>