asp.net4.0 new Features

Source: Internet
Author: User

Original: asp.net4.0 new features

In the previous trial VS2010 has been concerned about its web development support in some of the changes, for this I also made a PPT, originally planned on April 12 that day, the results because of unexplained cause no voice so that give up on the livemeeting of this lecture, Also led to the creation of this article.

Added a project template

You can see that more Web project templates are added when you create a Web project
The corresponding situation in VS2008 is as follows:

The following improvements are available in the new template:
Basic membership functionality. Authentication is required in most websites and applications, so adding authentication to the new template allows users to quickly get started on the Web Project Squadron, and the files for the authentication module are placed under the account folder;
The default master page is added. The use of master pages can be more convenient to unify the display of Web pages, such as related to the top of the page, user login status display and the menu section, the default master page file name is Site.master;
The default CSS style file is added. Using CSS style files allows us to easily adjust the style of the site, when creating a new site will be added a style file named Site.css, which is located in the Styles folder;
A mini Web. config file. In VS2010, the Web. config file is very small, and most of the configuration is placed in the Machine.config file;
Integrated jquery. jquery is a very powerful JavaScript class library that makes it easy for web developers to manipulate XHTML documents, supported by the VS2008 installation of SP1, and supported directly in VS2010, with jquery class library files under the Scripts folder.
By doing this, we have a similar structure to our site, which is easier to maintain (unlike the earlier versions, where the folders where you store these files are different).


Better JavaScript and HTML code IntelliSense
JavaScript IntelliSense support in previous versions of VS was poor, and there was no support for HTML snippets, but this is now available in VS2010.

JavaScript script IntelliSense has been improved in VS2010 to sense the function names and variables on this page

HTML code snippet support is available in VS2010


Enhanced control of the server control's ID
We know that an ASP. NET server control has three IDs, namely: Id,clientid and UniqueID.
where the ID is the server label for the server control, the server control is uniquely differentiated by ID in the server code (so the ID must be unique on the same page);
ClientID is the ID of the server control in the client after it is converted to an HTML element, in order to prevent the naming conflict from appearing. ASP. NET automatically generates a unique ClientID value for each server control on the page. The ClientID value is generated by connecting the control's ID value and the UniqueID value of its parent control. The individual parts of the generated ID are delimited by the underscore character (_);
UniqueID is the only, hierarchically qualified identifier of a server control that is also the name identity of the client after the server control is converted to an HTML element.
Sometimes we want to use JavaScript in the client to manipulate HTML elements through the ID of the HTML element, if the server control in the data-bound control, then it ultimately the corresponding HTML element ID and we usually use a very different, which makes us very inconvenient to operate, In particular, we are not convenient when we use JavaScript to implement a select-all inverse of the data, because we can also write JavaScript code as follows when manipulating a single control:
<script type= "text/javascript" ><!--function dosomething () {alert (' <%= control.clienti D%> '); }//--></script>
provides more control over the ID of the corresponding HTML element for the server control in ASP. NET, with the addition of the ClientIDMode property. Here is an example that shows the usage of the ClientIDMode attribute, encoded as follows on the server:

<asp:gridview id= "gvuserlist" runat= "Server" autogeneratecolumns= "False" > <Columns> <asp: TemplateField headertext= "Userid_autoid" > <ItemTemplate> <asp:label runat= "Server" id= "L B1 "clientidmode=" autoid "text= ' <% #Eval (" UserId ")%> '/> </ItemTemplate> </asp:tem platefield> <asp:templatefield headertext= "userid_static" > <ItemTemplate> <asp:label runat= "Server" id= "LB1" clientidmode= "Static" text= ' <% #Eval ("UserId")%> '/> </itemte mplate> </asp:TemplateField> <asp:templatefield headertext= "Userid_predictable" > <ItemTemplate> <asp:label runat= "Server" id= "LB1" clientidmode= "predictable" text= ' <% #Eval (" UserId ")%> '/> </ItemTemplate> </asp:TemplateField> </Columns> &l T;/asp:gridview>
If we do data binding and then look at the generated HTML source code, we see a similar section:
<textarea cols="50" rows="15" name="code" class="xhtml"><table cellspacing= "0" rules= "All" border= "1" id= "maincontent_gvuserlist" style= "border-collapse:collapse;" Mce_style= "Border-collapse:collapse;" ><tr><th scope= "col" >userid_autoid</th><th scope= "col" >userid_static</th><th Scope= "col" >userid_predictable</th></tr><tr><td><span id= "Ctl00_MainContent_ GVUSERLIST_CTL02_LB1 ">136</span></td><td><span id=" LB1 ">136</span></td> <td><span id= "Maincontent_gvuserlist_lb1_0" >136</span></td></tr>....</table ></textarea>
You can see that the client ID of the control when clientidmode= "Autoid" is not the same as when we were in the early ASP, and the client ID of the control does not change when clientidmode= "Static"; in Clientidmode= " Predictable "when a control has a data row identity in its client ID (for example," 0 "in id=" Maincontent_gvuserlist_lb1_0 "), which identifies the position in the data source as 0, which is the first record.
It is also convenient to control the ID of the HTML element that is ultimately generated by the server-side control by specifying the ClientIDMode property.


ViewState View Control
In the previous development process, ViewState is a people and love and hate things: good use can bring great convenience, the use of bad will also bring great trouble. We know that viewstate is stored as a hidden domain in the client, and for the sake of secrecy, the ViewState is BASE64 encoded and saved in the client-side hidden domain, and the server ends the Base64 decoding of this part of the hidden data in the Web page after committing to the server. Extracts the control data that is saved in the hidden field. Because HTTP requests are stateless and non-connected, it is convenient to use ViewState to save data between different requests on the same page, but if the control has a large number of state data, it can cause the volume of the viewstate to become larger and affect the response speed. And in the previous version of asp.net4.0 is enabled by default, in order to mitigate the adverse effects of viewstate, we have to set in the page or the control is viewstate enabled (although we can set the global disable ViewState in Web. config, but sometimes we may also Indirect use of this property, such as in the management of the background because we do less, the performance concerns are not as good as the foreground).
Now that's all changed in ASP. asp.net4.0 for ViewState properties is not enabled by default, but you can enable it individually for a control (although you might set it to disabled at a higher level in the control).
Look at the following sections of code:

<asp:panel runat= "Server" id= "Panel" viewstatemode= "Disabled" > <asp:label runat= "Server" id= " Lbenableviewstate "viewstatemode=" Enabled "text=" set in Code "/><br/> <asp:label runat=" Server "id=" Lbdisa Bleviewstate "text=" set in code "/> </asp:Panel> <asp:button id=" Button1 "runat=" Server "text=" Btntestvie Wstate "/>
The background code is as follows:

if (! Page.IsPostBack) {Lbdisableviewstate.text = "The ViewState ID enabled"; Lbenableviewstate.text = "The ViewState ID is enabled";}
The first run of the page results in the following:

Because the first time you run the match! Page.IsPostBack judgment, so the Text property is set to "the ViewState ID enabled", when clicked on the page button, the following effect:

This result occurs because the text of the first label is saved through ViewState, and the second label control is disabled, so the state data is not saved after the page is refreshed.


SEO optimization Support
For foreign sites, search engines will read the pages of the description and keywords fields, so that the search engine through the two meta-nodes to identify our pages, than simply through the Web page of the frequency analysis of the words to know the content of the page is much easier, So if we make good use of these two things in search of the same content may our page display will be compared to the front, this is the so-called SEO (search engine optimization, ie, search engine optimization) technology, In the previous ASP. We had no way to directly set these two properties for each page, but in asp.net4.0 we could do it directly in the code.
As in the following code:

<textarea cols="50" rows="15" name="code" class="c-sharp">if (! Page.IsPostBack) {page.title = "The Title of the page can be set here"; Page.metadescription = "The description of the page can be set here"; Page.metakeywords = "Here can set the page keywords, do seo";}</textarea>
In this way, we can see the following sections in the HTML source code of the final page:
<textarea cols="50" rows="15" name="code" class="xhtml"><meta name= "description" content= "Here you can set the description of the page"/><meta name= "keywords" content= " Here you can set the page keywords, do seo "/></textarea>
This makes search engine optimization more convenient.
Need to explain two points: 1, SEO involves more things, operation is more complex, set description and keywords is only one aspect. 2, because of the tireless pursuit of people in SEO, so that almost go to the point of the obsession, so many search engines on the Chinese site of these two fields are not too cold.
Routing Features
Friends who have done MVC may be familiar with routing features, especially those of ASP. We know that the usual way for a blog or store URL with user name ZHOUFOXCN may be the following:
Http://www.xxx.com/user.aspx?username=zhoufoxcn
http://www.xxx.com/user.aspx?userid=4419544 (if the ZHOUFOXCN corresponds to a userid of 4419544)
This is very inconvenient to remember, if we use URL rewrite way can become more friendly, such as:
Http://www.xxx.com/user/zhoufoxcn.aspx (note depends on URL rewrite rules)
If you take a route, you can make the URL more friendly and more convenient for search engine inclusion, such as:
Http://www.xxx.com/user/zhoufoxcn
If you want to use routing in a non-ASP. NET MVC project, you can follow these steps:
When you configure a route when the ASP. NET program starts, the ASP will execute the code in the Application_Start method in Global.asax.cs, which we can write:

void Application_Start (object sender, EventArgs e) {//routetable.routes.ignore (); Code that runs the on application Startup#region set the route//Parameter Description://////////route name "userlist", routing rule "{userlist}", "~/default.aspx" is processing page Face RouteTable.Routes.Add ("UserList", New Route ("{userlist}/{page}", New Pageroutehandler ("~/userlist2.aspx")); Endregion}
Then, write in the place where you need to use it:

link. Text = "|" + i.tostring () + "|"; /link for Hyperlink control in the night String expression = String.Format ("routename={0}, Userlist={1}, Page={2}", "UserList", "userlist ", i); link. NAVIGATEURL = Routeurlexpressionbuilder.getrouteurl (this, expression);
This completes the use of the routing function.


Summarize:
In addition to the above mentioned, a number of new server controls, such as Queryextender, have been added to asp.net4.0. Using asp.net4.0, we have more flexibility in developing ASP, so it is more convenient to meet the needs of different situations.

asp.net4.0 new Features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.