Referencing RoleProvider in a class library - asp.net

I'm trying to create a custom role provider in a class library, and for some reason I can't reference System.Web.Security.RoleProvider.
I have added a reference to System.Web in the project, yet still no luck. Is there a reason why I can't do this?

You need to reference the assembly System.Web.ApplicationServices.dll. The RoleProvider class is not defined in System.Web.dll.
In this cases and when in doubt check the MSDN page for the associated class and at the top of the page you can see in what namespace and assembly it is defined.
For the RoleProvider class you have:
Namespace: System.Web.Security
Assembly: System.Web.ApplicationServices (in System.Web.ApplicationServices.dll)

Related

Error while implementing MembershipProvider

Today i got an error while trying to implement MembershipProvider.
Error 1 The type 'System.Configuration.Provider.ProviderBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The thing that i have done is i added a reference of system.web because i had to implement membershipProvider which is under System.Web.Security. and now i get this error. thanks in advance !
When implementing a custom MembershipProvider, you must also put a reference to System.Configuration (as indicated by the exception), because the MembershipProvider gets configured via settings in web.config.

In ASP.NET where and all we can refer the assembly reference?

In ASP.NET where and all we can refer the assembly reference in Project? for ex: generally we can refer the file in web.config file as like below
<%# Register assembly="System.Web" namespace="System.JavaScript.Web" tagprefix="ex" %>
Except this what are the other pages in which we can refer assembly as like above.
secondly you can refer the assembly in project. Right click on references and select the required assembly, and click add. This will add assembly reference to your project.
Some assemblies like ajaxtoolkit.dll or if you are using some partial views (ascx) pages, then you can use the reference which you have mentioned.

Add a namespace reference to ALL web application web pages in a different project

I have a solution with three projects:
Project 1 - Reusable Logic/Methods (applicable to all other projects)
Project 2 - Web site
Project 3 - Web application (project 2 being converted to a web application)
In project 1 I have this code:
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web
Imports System.Runtime.CompilerServices
Namespace MyCompany
Public Module DataExtensionMethods
<Extension()> _
Public Function SortByColumn(ByVal dt As DataTable, ByVal SortString As String) As DataTable
' Amazing stuff here...
Return dt
End Function
End Module
End Namespace
In the old-fashioned Project 2 web site, this extension method was easily accessible by adding the following to web.config:
<pages controlRenderingCompatibilityVersion="4.0" validateRequest="true" clientIDMode="AutoID">
<namespaces>
<add namespace="MyCompany.DataExtensionMethods"/>
</namespaces>
</pages>
The extension method immediately became available on all references to a DataTable variable.
However, I cannot get this to work in Project 3 (web application) on an application-wide scale.
In each page, I can add this:
Imports MyCompany.DataExtensionMethods
This then makes the extension method available, but how do I achieve the same application-wide, without having to use Imports on each and every page?
In both Project 2 and 3 I have defined a reference to Project 1 using the Add Reference dialog. The check box shows that still exists, but Project 3 cannot see Project 1's logic. There seems to be loads of people seeing the same behaviour with WebAPI, but not with web page apps.
In VB, you can set a globally imported namespace for the project by right clicking your project in the solution explorer, choosing properties.
On the references tab, at the bottom is the Imported namespaces section. You can add your namespace MyCompany.DataExtensionMethods there and it will act as if you're typed Imports MyCompany.DataExtensionMethods in all your source files.

How can I use the class that is inside a codeSubDirectories in another other codeSubDirectories in Asp.Net

I want to have separate dlls for each namespace and I want to move each namespace class into codeSubDirectories in App_Code, but the class that is in one directory cant see the class in another directory
I can't add other project to my website to create separate dll and I can't place dependent class into one directory because I have a team that has a class for each other and have public class that all team members must use.
I use this in web config:
<codeSubDirectories>
<add directoryName="dir1" />
<add directoryName="dir2" />
</codeSubDirectories>
Can't be done. One project, one DLL/EXE.

Register custom class in assembly with web project

I'm using web project and web forms.
I create Custom Class
Namespace CustomWebControls
Public Class NoValidationDDL
Inherits DropDownList
End Class
End Namespace
and i try to register this class in assembly web.config page section
<controls>
<add tagPrefix="customDDL" namespace="CustomWebControls" assembly="ae" />
</controls>
and try to use in ascx
<customDDL:NoValidationDDL ID ="id" runat="server"></customDDL:NoValidationDDL>
How can i do this in web project?
This should work (assuming the assembly name for your project is ae) - make sure that you build the project after creating/modifying your custom control. Unless updated 'ae.dll' is present in your bin directory, intellisense etc will not work.
Instead of modify web.config, you may also try register control at page(aspx) or control(ascx) level by adding register directive after page directive:
<%# Register Assembly="ae" Namespace="CustomWebControls" TagPrefix="customDDL" %>

Resources