Home
Links
Home Page
HTML_AJAX In operation
The guidebook on an exchange of links
Bases of creation of server elements of management. Events
Postback and Query String - to combine incompatible
Kategorial`noe ordering of results of search
We change URL'? hurriedly
XML+MSSQL+ASP.NET. A part 1.
As work Web services ASP.NET
New in ASP.NET 2. Structures of users
Transformation of a target stream of the XML-given at a conclusion in a browser means ASP.NET and XS
Expectation of performance of long process in ASP.NET
Difference between HttpModule and HttpHandler
New in asp.net 2 - subjects and skiny.
Review GridView
What is GridView
Role of a content in promotion of a site
Review DetailsView
Job with databases
AutoPostBack Binding to the data. Collections. Check of correctness of the entered data

New in ASP.NET 2. Structures of users

Always pleasantly when you remember. Especially when remember not only you, but also your tastes and preferences, you understand, that you not simply one of many. Always it would be desirable to return to such place.


However it zadachka not from easy. Present, what you are a seller of the big shop in whom daily there is not one hundred buyers, and what if you - a site which daily look through tens thousand visitors? It is necessary in fact to remember not simply everyone, but also to save all this while he will not deign to go to you once again that you could show to him the phenomenal memory. And that if for this time his{its} tastes have changed and it is necessary to remember all anew, problems grow as snow whom. To automate a problem{task} one table in a database, set of searches to them is required not, moreover and the heap of a code to connect all together. Well and testing, testing, testing. You will reflect, and whether costs{stands} ovchinka manufactures? However not all so is bad, with an output{exit} ASP.NET 2.0 all problems fade into the background, because now he contains the new built - in opportunity - a structure (Profile) the user.



Structure of the user


Service of personification (personalization) is a new opportunity in ASP.NET which was applied in product Site Server. The given service gives the ready decision for storage of the personal data directly describing the user of a site, a so-called structure of the user (Profile.) some examples of the similar data is a name, a surname, an e-mail address of the user, his{its} time zone, and also ” a basket of the buyer " for the user of a site of electronic commerce or the information on an accessory{a belonging} of the visitor of a site to those or other groups of users. Now such parameters usually store{keep} in session (Session), in files cookie, databases and so on. Irrespective of a place of their storage, ASP.NET 1.x helps in this case a little. It is necessary to develop and adjust by own strength all infrastructure under corresponding storehouse. Also it is independently necessary to obtain these data and to save them. Collection Session facilitates a life, but she is unreliable, and its{her} storage in separate process or in a database resulted in high expenses of resources of the server and increase in time of the response of the application. In effect, service of personification is the collection very similar to session inherently. The same as also session, a structure of the user concerns to one concrete visitor of a site and provides storage of the information concerning directly it{him}. However there are also the significant differences favourably describing new service, among them:


* Strictly typified access to elements of a collection: as against collections such as Application, Session, Context, Cache, and all other collections, pereshedshikh by right of succession from ASP.NET 1.x which provided access to values of the elements on a key, a structure of the user - class HttpProfile - uses strictly typified called properties, to work with which much more conveniently. To remember names and types of properties it is not necessary any more, now it is destiny Intellisense which copes with it much better. Other useful effect - check of types at a stage of compilation. For example, the following fragment of a code shows two variants of reception of date of last activity of the user:

o old, with use of session:

DateTime LastLogin = (DateTime) Session ["LastLogin"];

o new, with attraction of service of personification:

DateTime LastLogin = Profile. LastLogin;

Notice, that in the second case reduction of types was not required, as date is already stored{kept} as date, instead of packed in object.

* Sample of the data of storehouse is made only if necessary. As against class Session the data are taken not at each search of page, borrowing{occupying} resources of the server but only when in them really there is a need{requirement}.

* The storage time of the data is not limited. As against all other collections, time of a life of the saved data in a structure indefinitely also does not depend in any way neither on the application, nor from the current session. Actually given will be stored{kept} eternally if the storehouse is reliable enough also you do not decide them to remove once therefrom.

* The data can be stored{kept} as for known (registered and past autentifikaciju in system), and for unknown persons (anonymous, that is yet not registered or simply not including in system) visitors of a site.

* Access to attributes of a structure is carried out as simply, as well as at job with collection Session. It is possible due to the new property Profile accessible in all derivatives from System. Web. UI.Control classes of the application. Or in all classes of the application through a context of the web - application, using the following syntax: System. Web. HttpContext. Current. Profile or ((ProfileCommon) System. Web. HttpContext. Current. Profile) .MessagesPosted if access to own properties of a structure is necessary. ProfileCommon is the special class automatically created by the compiler at the switched on structure and containing all user properties, added through web.config.

* The storehouse for the data is expanded and can be any. To default one provider enters into delivery ASP.NET 2.0 for a structure of the user - the provider for Microsoft SQL Server. But creation of the own provider of the data is possible also. For this purpose the new model of realization of providers is offered. She means allocation from the program interface of storehouse of a level of job with the data. So the opportunity of transparent access to any data is reached{achieved}, irrespective of type of physical storehouse is there can be a database and a file on a hard disk or even the selected server of the data. The similar architecture of the provider of the data is used and in other services ASP.NET 2.0. Later we shall consider an example of creation of own provider of the data and we shall see, as far as it is simple. The provider of the data can be set statically in a file of a configuration of the application or is dynamically appointed in a mode of performance.


Let's consider, how it is possible to start to use a structure. So, the structure saves the data on the concrete user of your site and allows then to receive these. By default all these data will be saved in tables of database SQL Server Express. The line of connection by default is called "LocalSqlServer" and she is set in a global file of adjustments machine.config. Here is how she looks:



<add name = "LocalSqlServer" connectionString = " data source =. SQLEXPRESS; Integrated

Security=SSPI; AttachDBFilename = | DataDirectory|aspnetdb.mdf; User Instance=true " providerName = " System. Data. SqlClient "/>




That is the database will work in mode User Instance, the name of a file of database ASPNETDB.MDF and at the first attempt of preservation of a structure the database will be automatically created in podpapke App_Data root directory of a site.


Perfectly, there is all is already adjusted, all that to us need to be made is to describe the fields of a structure necessary to us in a file of a configuration of the application web.config. We shall adjust a structure to storage of a name and a surname of the user, and also the counter of his{its} visitings of our site:



<configuration>

<system.web>

<anonymousIdentification enabled = "true"/>

<profile>

<properties>

<add name = "FirstName" allowAnonymous = "true"/>

<add name = "LastName" allowAnonymous = "true"/>

<add name = "Visits" allowAnonymous = "true" type = " System. Int32 " defaultValue = "1"/>

</properties>

</profile>

</system.web>

</configuration>


By default the type of parameter of a structure is System. String, therefore, to store{keep} quantity{amount} of visitings of a site as number, it is necessary for us to set his{its} type obviously. Also the parameter can matter by default (in our case it is 1). If the provider of the data will not find out an option value in storehouse of the data the option value by default will be returned.


After the structure is adjusted, to use it{him} very simply. The code resulted below displays the data from a structure of the current user and updates them by pressing the button. Notice, any additional code for preservation of these data somewhere in a database or receptions of them therefrom to write it is not necessary, infrastructure ASP.NET will take care of it.



<% Page Language = " C * " %>

<html>

<head>

<script runat = "server">

protected override void OnLoad (EventArgs e)

{

if (! IsPostBack)

{

tbFirstName. Text = Profile. FirstName;

tbLastName. Text = Profile. LastName;

lblVisits. Text = Profile. Visits. ToString ();

}

}


protected void Update (object s, EventArgs e)

{

Profile. FirstName = tbFirstName. Text;

Profile. LastName = tbLastName. Text;

Profile. Visits + = 1;

}

</script>

</head>

<body>

Name: <asp:TextBox runat = "server" ID = "tbFirstName"/> <br/>

Surname: <asp:TextBox runat = "server" ID = "tbLastName"/> <br/>

Kol-in visitings: <asp:Label runat = "server" ID = "lblVisits"/> <br/>

<asp:Button runat = "server" ID = "updateProfileButton"

Text = " Update profile "

OnClick = "Update"/>

</body>

</html>



Expansion of a structure of the user


The structure contains the following base parameters:

The name         Type         The description

UserName         String         A login name

IsAnonymous         Boolean         "Lie" if it is a structure of the registered user and "True" matters

In case of the anonymous user, it is meaningful only in the event that it is switched on

Structure for anonymous users

IsDirty         Boolean         Shows, whether there are in a structure changed, but yet data not saved in storehouse

LastActivityDate         DateTime         Date of last activity of the user in system (in this case this last

Preservation or reception of properties of a structure), in UTC

LastUpdatedDate         DateTime         Date of last preservation of a structure, in UTC


For expansion of class Profile the element of the unit of an element of a file of a configuration of the application - web.config is used. With the help of this element we can add new properties to class Profile. At compilation of page ASP.NET will replace class Profile generated by default, with a class constructed on the basis of the properties set in section of an element. All this will take place automatically, without our participation. Support of new properties a IntelliSense-ohm in Visual Studio begins with preservation of a configuration file.


The most simple variant of use of an element is a definition of new property of an individualization with unique attribute - name:



<profile>

<properties>

<add name = "Nickname"/>

</properties>

</profile>


In this case the infrastructure ASP.NET will create property with name Nickname, having type of the data by default - String, inaccessible for neautentificirovannykh users and using for job with storehouse of the data the provider by default (he/she is the provider for job with database SQL Server). By the way, it is possible to set names of new properties and in Russian, and blanks in them are not supposed.



<profile>

<properties>

<add name = "ImjaPol`zovatelja"/>

</properties>

</profile>


The list of the attributes accessible in tege <add/>:

Element         Type         The description

allowAnonymous         Boolean         At installation in true allows neautentificirovannym to users to store{keep} the data in system individalizacii. Thus it is meant, that for a site the opportunity of identification of anonymous users is switched on, that is at a configuration file there is an element <anonymousIdentification enabled = "true"/>. A default value of the given attribute

Is false.

defaultValue         String         Value of property by default. For example, for a site the subject by default can be set.

name         String         The name of property. It is used as a key for access to value of property, and also

Appears as the name of open property of class Profile. Is obligatory at addition of new property.

provider         String         The name of the provider used by system of an individualization for interaction

With storehouse of the data. If not it is set obviously the default value is used

From a file machine.config.

readOnly         Boolean         Serves for the instruction{indication} of that property is property only for reading. Value

By default - false.

serializeAs         String         Defines{determines} a method of serialization of the data. The following values are possible{probable}:

?         String: value will be serializovano

As a line.

?         Xml: the data serializujutsja in

XML, it is necessary to take into account, that will be

serializovany only open (public)

Fields of a class;

?         Binary: binary serialization,

The "deepest" method - serializations are exposed all fields of a class, however he

And most "dear"{"expensive"}, from the point of view of consumed resources. The type of parameter should

To be serializuemym;

?         ProviderSpecific: a data format

At the discretion of the provider of the data. Allows the supplier of the data to define{determine} a format himself

Data storage. Is a default value.

type         String         Type of the data of stored{kept} property. Type String is by default used, but it is possible to set and any other type (for type serialiazacii Binary it is possible to set only

serializuemyj type, that is the type marked with attribute

Serializable, and for type serialiazacii String the class should have the

The successor of class TypeConverter). In the last

Case it is necessary to specify the full name of a class, including space of names.


The elementary variant of realization of own class which satisfies to all conditions of a structure is below resulted and can be serializovan all possible{probable} ways:



using System;

using System. ComponentModel;

using System. Xml. Serialization;


[TypeConverter (typeof (AddressTypeConverter))]

[Serializable]

public class Address

{

string _country;

string _city;

string _street;

int _building;

int _room;


[XmlAttribute]

public string Country

{

get {return _country;}

set {_country = value;}

}

[XmlAttribute]

public string City

{

get {return _city;}

set {_city = value;}

}

[XmlAttribute]

public string Street

{

get {return _street;}

set {_street = value;}

}

[XmlAttribute]

public int Building

{

get {return _building;}

set {_building = value;}

}

[XmlAttribute]

public int Room

{

get {return _room;}

set {_room = value;}

}

}


Realization of a class - successor TypeConverter, allowing serializovat` our class, as a line:



using System;

using System. ComponentModel;

using System. Globalization;


public class AddressTypeConverter: TypeConverter

{

public override bool CanConvertFrom (ITypeDescriptorContext context,

Type sourceType)

{

if (sourceType == typeof (string))

{

return true;

}

return base. CanConvertFrom (context, sourceType);

}


public override object ConvertFrom (ITypeDescriptorContext context,

CultureInfo culture, object value)

{

if (value is string)

{

string [] v = ((string) value) .Split (new char [] {'|'});

Address address = new Address ();

address. Country = v [0];

address. City = v [1];

address. Street = v [2];

address. Building = Convert. ToInt32 (v [3]);

address. Room = Convert. ToInt32 (v [4]);

return address;

}

return base. ConvertFrom (context, culture, value);

}


public override object ConvertTo (ITypeDescriptorContext context,

CultureInfo culture, object value, Type destinationType)

{

if (destinationType == typeof (string))

{

Address address = (Address) value;

return address. Country

+ "|" + address. City

+ "|" + address. Street

+ "|" + address. Building

+ "|" + address. Room;

}

return base. ConvertTo (context, culture, value, destinationType);

}

}



Data storage of Generic-types


For the description similar given as properties of a structure special syntax is used. We shall consider an example - as property of a structure of the user we need to store{keep} property with name Ints having type of data System. Collections. Generic. List <int>. In this case the corresponding parameter in file Web.config should look so:



<add name = "Ints" type = " System. Collections. Generic. List ` 1 [[System. Int32]] "/>


That is all over again the full type of a class - is underlined to a collection, then the quantity{amount} of parameters with a prefix an apostrophe (' 1), and then in square brackets goes the list of types, each of which also is framed by square brackets. For type of data System. Collections. Generic. Dictionary <System. String, System. Double> recording in a config will look as



<add name = "Registry" type = " System. Collections. Generic. List ` 2 [[System. String], [System. Double]] "/>



Identification of anonymous users


The given code will save adjustments of any user, even "anonymous", that is unregister or simply yet not executed an input{entrance} in system. By default the structure is saved only for autentificirovannykh users. That he started to work and for anonymous users it is necessary to switch on the module of recognition of anonymous users. For it the section <anonymousIdentification/> a file of adjustments web.config responds. Also it is necessary for each parameter of a structure which should be stored{kept} and for anonymous users, establish attribute allowAnonymous in value "true" (by default value of this attribute - lie). If it to not make, at each attempt will establish such property for the anonymous user to be generated exception. It is recommended to approach{suit} reasonably to the given question and to not overload a structure of the anonymous user with useless properties for him{it}.


Inclusion of recognition anonymous pol`zovatelj results in that, chno in a chain of processing of entering search one more module - AnonymousIdentificationModule is added. He works as follows - at receipt of search from the anonymous user the module creates globally unique identifier (System. Guid) and writes down it{him} in constantly stored{kept} file cookie with a name by default .ASPXANONYMOUS. Since this moment this Guid also will be a time login name. As the file cookie is created constant the system can "learn{find out}" the user at his{its} each subsequent visiting a site. All parameters of the module are adjusted and can be changed in a file of a configuration, in section of anonymous identification.


What for it is necessary? We admit{allow} you create electronic shop visiting{attending} which user can generate a basket of his{its} interesting goods not being registered on a site and not passing authorization. Then he looks in what his{its} purchases and if the sum of it{him} arranges will cost for him, logins and finishes registration of the order. Thus he can postpone purchase for a week or for a month, all this time the basket will accurately store{keep} all goods chosen him{it} last time, notwithstanding what he has not been registered at all on a site. For "migration" of the user from an anonymous structure on a structure of the registered user in a structure special event - MigrateAnonymous is stipulated. It occurs during that moment when the anonymous user carries out an input{entrance} on a site. This event can be processed in file Global.asax by means of the following code:



void Profile_MigrateAnonymous (object sender, ProfileMigrateEventArgs e)

{

// We receive a structure of the anonymous user on it{him} ID

ProfileCommon anonymous = Profile. GetProfile (e. AnonymousID);

// It is transferable{tolerable} the data in a structure current zaregistr. The user

// if (! isMigrated)

// {

Profile. FirstName = anonymous. FirstName;

Profile. LastName = anonymous. LastName;

Profile. SiteLook. MasterPage = anonymous. SiteLook. MasterPage;

Profile. SiteLook. Theme = anonymous. SiteLook. Theme;

//}

// We erase cookie ".ASPXANONYMOUS" with the anonymous identifier

AnonymousIdentificationModule. ClearAnonymousIdentifier ();

}


It is especially important to execute removal{distance} cookie with the identifier of the anonymous user. Otherwise the module will cause this event at each new search of the user to a site.


It is necessary to take into account also, that event MigrateAnonymous is caused each time when the user will be authorized in system even if the structure of the user already was once migrirovan. Therefore it is meaningful to add in a structure of one more parameter "isMigrated" such as System. Boolean which would have a default value lie, and after migration it would be exposed in true. Thus migration should be spent only if this parameter matters by default (that is the structure still never was migrirovan).


Grouping of parameters of a structure


At a plenty of parameters their association in logic subgroups is supposed. It is done{made} with the help of an element <group>, having unique attribute name which is obligatory and should matter, unique within the framework of the application. We shall consider other example of the task of a structure:



<profile>

<properties>

<add name = "FirstName" allowAnonymous = "true"/>

<add name = "LastName" allowAnonymous = "true"/>

<group name = "SiteLook">

<add name = "Theme" defaultValue = "Orange"/>

<add name = "MasterPage" defaultValue = "Basic.master"/>

</group>

</properties>

</profile>


Here the parameters concerning appearance of a site, are incorporated into one group with general{common} name SiteLook. The quantity{amount} of groups is not limited, however the investment of groups is not supposed. Association of parameters in group adds an additional level and in a code, the reference{manipulation} to properties of group in our case will look so:



Profile. FirstName = "test";

Profile. SiteLook. MasterPage = "Extreme.master";

Profile. SiteLook. Theme = "Yellow";


Job with a structure of the any user


Till now we worked only with a structure of the current user, however in some cases it happens it is necessary to receive a structure of other user. It with ease can be executed by means of method GetProfile () class HttpProfile, it is enough to pass only to him we would like to receive a login name, which structure. The given method returns a new copy of class HttpProfile with which it is possible to work the same as and with a structure of the current user. Probably as well change of properties of the structure received thus. However, in this case, automatic preservation of changes will not take place. That changes have come into force, it will be compulsorily necessary to call method Save () a changeable structure. At use of a structure of the current user in the web - application it is not necessary to cause this method for preservation of a structure as he is caused automatically by the module of a structure at operation of event EndRequest.



ProfileCommon profile = Profile. GetProfile ("Nisus");

profile. FirstName = "SeaEagle";

profile. Save ();


To receive structures of all users of a site also will not make the big work:



public List <ProfileCommon> GetProfiles ()

{

List <ProfileCommon> profiles = new List <ProfileCommon> ();

ProfileInfoCollection profilesInfos = ProfileManager. GetAllProfiles (

*nbspProfileAuthenticationOption. All

);

foreach (ProfileInfo profileInfo in profilesInfos)

{

profiles. Add (Profile. GetProfile (profileInfo. UserName));

}

return profiles;

}


Transfer ProfileAuthenticationOption determined in space of names System. Web. Profile includes three elements:


* All - all users, irrespective of their status;

* Anonymous - anonymous users;

* Authenticated - the registered users.


Access to a structure from external a component


Probably you will need access to a structure of the user from external a component, for example from a layer of job with the data. If simply to write Profile as we did{made} it on page aspx the code will not be compiled as in the external application class ProfileCommon, especially property Profile ASP.NET will not create. Nevertheless such opportunity is - access to a structure can be received through property Profile of a context of search (HttpContext). The context is an object which contains all data on the current search, known ASP.NET. One of new properties of a context in ASP.NET 2.0 is the property Profile containing the link to a structure of the current user.


System. Web. HttpContext context = System. Web. HttpContext. Current;

context. Profile ["FirstName"] = "Adam";

context. Profile. Save ();


Other variant more convenient for use, creation of a class - the successor from class ProfileBase is. We shall add in folder App_Code the new class describing the structure necessary to us:



using System;

using System. Web. Profile;

using System. Collections. Generic;


public class CustomProfile: ProfileBase

{

[SettingsAllowAnonymous (true)]

public string FirstName

{

get {return base ["FirstName"] as string;}

set {base ["FirstName"] = value;}

}


[SettingsAllowAnonymous (true)]

public string LastName

{

get {return (string) base ["LastName"];}

set {base ["LastName"] = value;}

}

}


The given class is the successor of class ProfileBase and expands it{him}, describing the properties necessary to us only a little. All ostal`nyju draft job on dialogue with the provider for polucheniija and preservations of values of our properties vypoljanet a base class. To specify to an infrastructure that as a base class for a structure it is necessary to use our class we shall change the description of a structure in a file of a configuration, plus we shall add new property - phone:



<profile inherits = "CustomProfile">

<properties>

<add name = "Phone" allowAnonymous = "true" serializeAs = "ProviderSpecific"/>

</properties>

</profile>


Now as before we can free get access to properties of a structure on strnicakh our site:



Profile. FirstName = "John";

Profile. LastName = "Smith";


And if we shall bear{shall take out} this class in separate assembly we can use it{him} in any project using obvious reduction of types:



System. Web. HttpContext context = System. Web. HttpContext. Current;

string firstName = ((CustomProfile) context. Profile) .FirstName;


The minus of the given approach that advantage of floppy adjustment of all properties of a structure through change of the circuit in a file of adjustments (base properties is lost, zahhitye in a code of a class without recompilation to change any more it will not be possible), and plus is that now there is possible{probable} an addition of additional logic to object of a structure. For example we can check, that the login name will consist only of letters.


Management of structures


For management of structures there is a special class, ProfileManager. In him a number{line} of the static methods is determined, allowing to make various auxiliary operations. For example, removal{distance} of unused structures. Removal{distance} of superfluous structures plays very important role as at active job of a site the quantity{amount} of stored{kept} structures will grow very quickly, especially if structures for anonymous structures are used. Automatically clearing of storehouse of the data of inactive structures is not made, you should realize her{it} independently. For example it is possible to carry out clearing at each start of the application



void Application_Start (object sender, EventArgs e)

{

ProfileManager. DeleteInactiveProfiles (

ProfileAuthenticationOption. Anonymous,

DateTime. Now. AddMonths (-2) // we Shall remove all structures than 2 months are more senior

);

}


Also the given class gives a number{line} of methods for reception of reports, for example method GetAllProfiles, allowing to receive the list of all stored{kept} structures page by page.

Adjustment of storehouse of the data


Microsoft SQL Server


Let's consider process of creation of storehouse of the data which are distinct from storehouse of the data by default which adjustments are in a file of a global configuration .NET - machine.config.


To create new storehouse to us it is required to create a database. It is done{made} very simply with the help of the utility aspnet_regsql which is delivered in structure .NET Framework 2.0 and, accordingly, is in a folder " C:WINDOWSMicrosoft. NETFrameworkv2.0.50727 ". The utility works in two modes - in a mode of the master and in a mode of the command line. To use her{it} in a graphic mode of the master simply enough to start her{it} on performance or to call with parameter "-W". The mode of the master is rather poor and carries out only primitive general{common} functions - carries out in a database scripts for creation or removals{distances} of all new opportunities given by an infrastructure ASP.NET (among them Membership, Role manager, Profile, Personalization, etc.) . The mode of the command line allows to operate support of all opportunities necessary to you. We shall use the utility in a mode of the graphic interface for creation of a new database and installation in it{her} of all new opportunities given ASP.NET. The given utility allows to work as with the new version - SQL Server 2005, and with previous version 2000, also is supported SQL Server Express Edition (SSE).


First two windows of the master it is left without changes, and in third us suggest to specify the name instansa SQL Server-?. Further we leave type autentifikacii in a mode by default - Windows and naibivaem in a field of a choice of a database a name of a desirable new database - "MyOwnAspnetDB".


Further we press two times button Next and, at a small share of luck, we receive the message that scripts have been successfully installed. It is necessary to copy only a new database from folder Data of the server (for SSE it is possible to learn{find out} its{her} arrangement in the registry - branch HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft SQL ServerSQLEXPRESSSetup) in folder App_Data of the project necessary to you to start her{it} to use in mode UserInstanse at use SSE or simply to specify a correct line of connection in case of use SQL Server of full editions.

Microsoft Access


To use Access as storehouse of the data it is necessary to download Sample Access Provider Starter Kit from a site http://msdn.microsoft.com/vstudio/downloads/starterkits/. Then it{he} will need to be compiled by means of studio or C * Developer Express, having received in a result ASP.NET Access Providers.dll and a file of database ASPNetDB.mdb which should be put in podpaku App_Data the site, and dll-ku the provider sootvestvenno in podpapku bin root directory of a site (if you do not have such folder create her{it}).

Own provider of the data


Probably also use of any other storehouse of the data, however in this case is necessary to realize it{him} independently. This problem{task} in most cases will be simple, but in given clause{article} she is not considered{examined}.

Adjustment of service on job with the certain storehouse of the data.


Initially service is already adjusted to job with SSE in mode UserInstance. these adjustments are set in a global file of a configuration machine.config (C:WINDOWSMicrosoft. NETFrameworkv2.0.50727CONFIGmachine.config) and can be redefined in a file of adjustments of a site web.config. The corresponding adjustments set by default here is how look:



<connectionStrings>

<add name = "LocalSqlServer" connectionString = " data source =. SQLEXPRESS; Integrated Security=SSPI; AttachDBFilename = | DataDirectory|aspnetdb.mdf; User Instance=true " providerName = " System. Data. SqlClient "/>

</connectionStrings>

<system.web>

<profile>

<providers>

<add name = "AspNetSqlProfileProvider" connectionStringName = "LocalSqlServer" applicationName = "/" type = " System. Web. Profile. SqlProfileProvider, System. Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a "/>

</providers>

</profile>

</system.web>


That is service is adjusted to use SSE of the provider, and it is considered, that the database should be called "aspnetdb.mdf" and be located she should in a folder of the data ASP.NET (it podpapka App_Data to root directory of a site). If the provider finds out, that the similar database is not created, he creates its{her} and all objects necessary for job at the first reference{manipulation}.


Use of mode User Instance is extremely convenient by development and testing of the application, however is hardly probable applicable at reliznoj to job of a site, therefore be ready to that at exhibiting the application to the fighting server is necessary attachit` a database to instansu SQL Server and updatings of a line of connection.


So, that the application to use service of a structure with the provider of data SSE it could is possible to change nothing in a file web.config, however it is better produblirovat` than adjustment from a global file of a configuration, accordingly Web.config should look approximately so:



<configuration xmlns = " http: // schemas.microsoft.com/.NetConfiguration/v2.0 ">

<connectionStrings>

        <remove name = "LocalSqlServer"/>

        <add name = "LocalSqlServer" connectionString = " Data Source =. SQLExpress; Integrated Security=True; AttachDBFilename = | DataDirectory|aspnetdb.mdf "/>

</connectionStrings>

<system.web>

        <profile defaultProvider = "AspNetSqlProfileProvider">

         <properties/>

        </profile>

</system.web>

</configuration>


In case of use Sample Access Provider Starter Kit the file of adjustments will a little be complicated, at the expense of necessity of the description of the new provider:



<configuration xmlns = " http: // schemas.microsoft.com/.NetConfiguration/v2.0 ">

        <connectionStrings>

                <add name = "AccessFileName" connectionString = "~/App_Data/ASPNetDB.mdb" providerName = " System. Data. OleDb "/>

        </connectionStrings>

        <system.web>

                <profile enabled = "true" defaultProvider = "AccessProfileProvider">

                        <providers>

                                <add name = "AccessProfileProvider" type = " Samples. AccessProviders. AccessProfileProvider, ASP.NET Access Providers " connectionStringName = "AccessFileName" applicationName = "SampleSite" description = " Stores and retrieves profile data from an ASP.NET_Access_Providers database. "/>

                        </providers>

                        <properties/>

                </profile>

                <anonymousIdentification enabled = "true" cookieName = ". ASPXANONYMOUS " cookieTimeout = "100000" cookiePath = "/" cookieRequireSSL = "false" cookieSlidingExpiration = "true" cookieProtection = "None" domain = ""/>

                <compilation debug = "true"/>

        </system.web>

</configuration>


Where ” ASP.NET Access Providers " in line type = " Samples. AccessProviders. AccessProfileProvider, ASP.NET Access Providers " is a name of assembly (ASP.NET Access Providers.dll at you can have other name) which turns out as a result of compilation of project Sample Access Provider Starter Kit and which should be put in podpapku bin a root folder of your site. Also it is necessary to not forget to copy file ASPNetDB.mdb from a folder bin the project of provider Access in folder App_Data of your project.



The conclusion


The given opportunity is entered to reduce a spelling of a code for the most widespread and obhheupotrebimykh scripts, and she will undoubtedly facilitate a life to the programmers creating websites. All that it was necessary to do{make} manually earlier, now is realized and organized by founders ASP.NET. For use of all these blessings it is not required to write lines of a code - everything, that is necessary for the beginning uses of this an opportunity is to describe a structure of the user in a file of a configuration as the xml-circuit. Further it will be possible to appropriate{give} values to properties, and to read out them, not caring about interaction with storehouse of the data. All care of it is incured with an infrastructure ASP.NET. For already existing complex{difficult} complex decisions which need to be transferred without serious consequences on a new platform, the opportunity to realize job with storehouse manually is left.