visual studio 2010 网页开发教程
- 格式:pdf
- 大小:1.14 MB
- 文档页数:66
学习使用VisualStudio进行程序开发的入门教程第一章:Visual Studio简介Visual Studio是一个由微软公司开发的集成开发环境(IDE),用于编写、调试和部署各种应用程序,包括桌面、移动、Web和云应用等。
它是开发者们非常重要的工具之一,拥有强大的功能和丰富的扩展性。
本章将介绍Visual Studio的基本概念和使用方法。
1.1 Visual Studio的版本选择Visual Studio有多个版本可供选择,包括Community(社区版)、Professional(专业版)和Enterprise(企业版)等。
不同的版本提供了不同的功能和定价策略。
对于初学者来说,Community 版是一个理想的选择,它提供了免费的使用权限,并且可以满足绝大部分的开发需求。
1.2 Visual Studio的安装安装Visual Studio需要从微软官方网站下载安装程序,并按照向导进行操作。
在安装过程中,需要选择所需的开发工作负载(Workload),如通用的.NET开发工作负载、Web开发工作负载或移动开发工作负载等。
此外,还可以选择安装额外的组件和工具。
安装完成后,即可开始使用Visual Studio进行程序开发。
第二章:Visual Studio的基本功能Visual Studio提供了丰富的功能,包括代码编辑器、调试器、版本控制、自动完成等。
本章将介绍一些常用的基本功能和操作方法。
2.1 代码编辑器Visual Studio的代码编辑器具有强大的功能,能够提供语法高亮、代码补全、智能感知等特性。
在编辑器中,可以编写各种编程语言的代码,如C#、Java、Python等。
同时,还可以进行代码重构、查找替换等操作。
2.2 调试器调试器是程序开发中非常重要的工具,它可以帮助开发者找到代码中的错误和问题。
Visual Studio提供了强大的调试功能,可以对代码进行单步调试、断点调试等,帮助查找和修复程序中的错误。
VisualC++2010的使⽤Tools->Settings>Rest... 还原所有设置运⾏程序:"D:\Program Files\VCExpress\Install\Microsoft Visual Studio 10.0\Common7\IDE\VCExpress.exe"⼀、Visual C++2010(微软vc2010)如何编写并运⾏C++程序?1、刚开始打开vc2010编译器的时候是⼀个start page 页⾯。
根据页⾯的New Project. . .提⽰选项新建⼀个项⽬。
2、选择Win32 Console Application(win32控制台程序),键⼊项⽬名。
3、新建⼀个win32的空⼯程Empty project。
4、新建后的界⾯如下图所⽰。
5、选中项⽬名,添加⼀个新项⽬。
右键Add -> New Item。
在⽂件类型中选择C++ file。
6、在菜单栏的空⽩处点击右键添加快捷按钮,点击Build,菜单栏显⽰Build按钮。
7、编写程序如下图所⽰,编写完后按build 和 Start Debugging按钮。
对应位置如图所⽰。
程序运⾏。
今天初次使⽤VS2010版本,在coding完⼀个⼯程后,报错:LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt编译也没有任何错误,链接⼀直报错,也找不出什么原因,上⽹找了找,是⼯具的原因。
Microsoft Visual Studio 2010 英⽂版Project->xx PropertiesManifest->Input and Output->Embed Manifest将yes修改为no再重新编译OK了microsoft visual c++ 2010 express will run for 22 more daysvisual c++ 2010 express注册码6VPJ7-H3CXH-HBTPT-X4T74-3YVY7那么我们怎么来写⼀个C语⾔程序呢?和创建c++程序⼀样我就写了如下C程序,按F5后运⾏⼀下就没了,怎么解决呢?有两种⽅法:(⼀)Ctrl+F5可以解决:最后运⾏到的结果⽅法⼆:加system(“pause”);但是头⽂件要改变为c++标准头⽂件#include<iostream>using namespace std;加好了再按F5就可以了。
VS2010之GUI编程入门到精通教程1. 简介本教程将帮助你从入门到精通掌握使用VS2010进行GUI编程。
我们将介绍如何利用VS2010提供的工具和功能来创建交互式的图形用户界面应用程序。
2. 安装和设置首先,你需要确保已成功安装和设置了VS2010开发环境。
请按照官方指南执行安装步骤,并确保已正确配置环境变量和相关设置。
3. 创建新项目在VS2010中,创建新的GUI项目非常简单。
在菜单栏中选择“文件 > 新建 > 项目”,然后在项目模板中选择“Windows窗体应用程序”。
接下来,选择项目的名称和位置,并点击“确定”按钮。
4. 界面设计VS2010提供了强大的可视化界面设计工具,可帮助你设计和布局应用程序的用户界面。
你可以从工具箱中拖拽控件(如按钮、文本框、标签等)到窗体上,并调整它们的属性和位置。
5. 事件处理在GUI编程中,事件是非常重要的。
VS2010提供了事件处理机制,使你能够对用户操作作出响应。
你可以通过双击控件或通过属性窗口来访问事件处理代码,并在相应的事件处理函数中编写自定义的代码。
6. 调试和测试在开发过程中,调试和测试是至关重要的。
VS2010提供了强大的调试功能,包括断点调试、变量查看和单步执行等。
你可以通过菜单栏中的“调试”选项来访问这些功能,并确保应用程序的正确性和稳定性。
7. 发布和部署当应用程序开发完成后,你需要将其发布和部署到目标计算机上。
VS2010提供了便捷的发布功能,可以将应用程序编译为可执行文件,并自动处理相关的依赖项和配置。
8. 进阶技巧和资源除了基本的GUI编程知识,你还可以进一步研究和掌握一些进阶技巧和资源,例如利用多线程实现异步操作、使用第三方库和控件等。
在互联网上,有许多教程和资源可供研究和参考。
以上是关于使用VS2010进行GUI编程的简要介绍。
通过研究本教程,你将能够从入门到精通掌握这一领域,并开发出漂亮、强大且易于使用的GUI应用程序。
教程1:创建图片查看器Visual Studio 2010其他版本25(共34)对本文的评价是有帮助- 评价此主题在本教程中,您将生成一个从文件加载图片并将其显示在窗口中的程序。
您将学习如何拖动控件(如窗体上的按钮和图片框)、设置控件属性,以及如何使用容器来平滑地调整窗体的大小。
您还将开始编写代码。
您将学习如何:∙创建新项目。
∙测试(调试)应用程序。
∙向窗体中添加基本控件(如复选框和按钮)。
∙使用布局在窗体上定位控件。
∙向窗体中添加“打开文件”和“颜色”对话框。
∙使用IntelliSense 和代码段编写代码。
∙编写事件处理程序方法。
当您完成时,程序将类似下图所示。
在本教程中创建的图片说明步骤1:创建Windows 窗体应用程序项目创建Windows 窗体应用程序项目1.在“文件”菜单上,单击“新建项目”。
2.如果没有使用Visual Studio 学习版,您需要先选择一种语言。
从“安装的模板”列表中选择“C#”或“VisualBasic”。
3.单击“Windows 窗体应用程序”图标,输入“PictureViewer”作为名称,然后单击“确定”。
Visual Studio 将自动为您创建解决方案。
4.在“文件”菜单上,单击“全部保存”;或者在工具栏上单击“全部保存”按钮,此按钮如下所示。
“全部保存”工具栏按钮说明5.确保项目保存在“我的文档”文件夹下的某个文件夹中。
6.确认选中“创建解决方案的目录”复选框。
7.单击“保存”。
说明您可能已经注意到“解决方案”和“项目”这两个词具有不同的含义,本教程稍后将对此进行解释。
下图显示IDE 窗口应具有的外观。
IDE 窗口8.如果您的屏幕与上面的图片不太一样,请在“窗口”菜单上,单击“重置窗口布局”。
如果缺少任何窗口,请在“视图”菜单上,单击“属性窗口”或“解决方案资源管理器”。
如果有多余的窗口打开,请单击右上角的“关闭”(x) 按钮。
9.查看图片。
从左上角开始沿逆时针方向,图片将依次显示:∙主窗口您可在此处执行大部分的工作。
vs2010使用技巧Visual Studio 2010(简称VS2010)是一款由微软开发的集成开发环境(IDE),主要用于开发各种应用程序,包括桌面应用程序、Web应用程序、移动应用程序等。
这里将介绍一些VS2010的使用技巧,帮助用户更高效地开发应用程序。
1. 快速导航:VS2010提供了快速导航的功能,可以帮助我们在大型项目中快速定位到特定的代码行。
使用快速导航,可以通过按下Ctrl + , (逗号键)来打开导航窗口。
在导航窗口中,可以输入要查找的方法名、变量名或文件名,并通过键盘上的上下箭头键来选择并跳转到相应的代码位置。
2. 代码片段:代码片段是一种重用代码的方式,可以帮助我们快速插入常用代码块。
在VS2010中,通过按下Ctrl + K,X来打开代码片段窗口。
在代码片段窗口中,可以选择已有的代码片段,也可以自定义新的代码片段。
代码片段可以包含多个占位符,方便用户根据需要进行替换。
3. 代码重构:VS2010提供了一些代码重构的功能,可以帮助我们改善代码的结构和质量。
例如,可以通过右键点击某段代码,选择“重构”菜单来进行重命名、提取方法、封装字段等操作,以提高代码的可读性和可维护性。
4. 调试工具:VS2010提供了强大的调试工具,可以帮助我们快速定位和修复代码中的错误。
例如,可以使用断点来暂停程序的执行,查看变量的值和调用栈等信息。
还可以使用条件断点、数据断点等高级调试技巧来帮助我们更精确地定位问题。
5. 多项目管理:VS2010允许用户同时打开和管理多个项目,方便我们进行跨项目的开发和调试。
通过选择“文件”菜单中的“添加”选项,可以将其他项目引入到当前解决方案中。
同时,VS2010还提供了一些工程管理的功能,如项目依赖、项目引用等,方便我们更好地管理项目之间的关系。
6. 快捷键使用:VS2010提供了众多快捷键,可以帮助我们加快编码速度。
例如,可以使用Ctrl + K,D来格式化代码,使用Ctrl + K,C来注释选中的代码,使用F12来查找代码的定义等。
VisualStudioCode前端开发工具教程一、Visual Studio Code简介Visual Studio Code是由Microsoft开发的一款轻量级的开源代码编辑器,广泛应用于前端开发领域。
它提供了强大的代码编辑、调试和版本控制等功能,使得前端开发工作更加高效和便捷。
二、安装和配置1. 下载与安装在Visual Studio Code官方网站(https://)上下载对应平台的安装包,并按照提示进行安装。
2. 基本配置安装完成后,打开Visual Studio Code,在顶部菜单中选择“文件”->“首选项”->“设置”打开用户配置文件。
在其中可以进行一系列个性化配置,例如自动保存、字体大小等。
三、常用功能1. 代码编辑Visual Studio Code支持多种编程语言的语法高亮显示,并提供了智能代码补全、自动缩进、括号匹配等功能。
另外,它还支持多光标编辑、快速导航和重构等功能,大大提高了编码效率。
2. 调试功能Visual Studio Code内置了强大的调试功能,可以通过配置调试任务、断点设置和监视变量等,帮助开发者定位和解决代码中的问题。
3. 版本控制Visual Studio Code集成了Git,可以直接在编辑器中进行版本控制操作,如提交代码、查看修改记录和解决冲突等。
四、插件扩展1. 插件市场Visual Studio Code有丰富的插件生态系统,可以通过插件市场方便地安装和管理插件。
在编辑器中点击侧边栏中的“扩展”按钮即可打开插件市场。
2. 常用插件- ESLint:用于代码规范检查和自动修复。
- Prettier:用于代码格式化,让代码风格保持一致。
- Live Server:提供了轻量级的本地开发服务器,支持实时刷新。
- HTML CSS Support:提供HTML和CSS的智能代码补全和提示。
- IntelliSense for CSS class names:快速定位CSS类名。
Visual Studio 2010教程1:创建图片查看器此内容为质量更高的人工翻译。
若想同时查看此页面和原始英文页面的内容,请单击“首选项”然后选择“经典视图”作为您的查看首选项。
在本教程中,您将生成一个从文件加载图片并将其显示在窗口中的程序。
您将学习如何拖动控件(如窗体上的按钮和图片框)、设置控件属性,以及如何使用容器来平滑地调整窗体的大小。
您还将开始编写代码。
您将学习如何:∙创建新项目。
∙测试(调试)应用程序。
∙向窗体中添加基本控件(如复选框和按钮)。
∙使用布局在窗体上定位控件。
∙向窗体中添加“打开文件”和“颜色”对话框。
∙使用IntelliSense 和代码段编写代码。
∙编写事件处理程序方法。
当您完成时,程序将类似下图所示。
在本教程中创建的图片说明相关主题步骤1:创建Windows 窗体应用程序项目此内容为质量更高的人工翻译。
若想同时查看此页面和原始英文页面的内容,请单击“首选项”然后选择“经典视图”作为您的查看首选项。
创建图片查看器的第一步是创建Windows 窗体应用程序项目。
创建Windows 窗体应用程序项目1.在“文件”菜单上,单击“新建项目”。
2.如果没有使用Visual Studio 学习版,您需要先选择一种语言。
从“安装的模板”列表中选择“C#”或“Visual Basic”。
3.单击“Windows 窗体应用程序”图标,输入“PictureViewer”作为名称,然后单击“确定”。
VisualStudio 将自动为您创建解决方案。
4.在“文件”菜单上,单击“全部保存”;或者在工具栏上单击“全部保存”按钮,此按钮如下所示。
“全部保存”工具栏按钮说明5.确保项目保存在“我的文档”文件夹下的某个文件夹中。
6.确认选中“创建解决方案的目录”复选框。
7.单击“保存”。
说明8.您可能已经注意到“解决方案”和“项目”这两个词具有不同的含义,本教程稍后将对此进行解释。
9.下图显示IDE 窗口应具有的外观。
4 and Visual Studio 2010 Web Development Overview1© 2010 Microsoft Corporation ASP .NET 4 and Visual Studio 2010 Web Development OverviewThis document provides an overview of many of the new features for that are included in Framework 4 and in Visual Studio 2010.ContentsCore Services (3)Web.config File Refactoring (3)Extensible Output Caching (3)Auto-Start Web Applications (5)Permanently Redirecting a Page (7)Shrinking Session State (7)Expanding the Range of Allowable URLs (8)Extensible Request Validation (8)Object Caching and Object Caching Extensibility (9)Extensible HTML, URL, and HTTP Header Encoding (11)Performance Monitoring for Individual Applications in a Single Worker Process (12)Multi-Targeting (12)Ajax (13)jQuery Included with Web Forms and MVC (13)Content Delivery Network Support (14)ScriptManager Explicit Scripts (15)Web Forms (16)Setting Meta Tags with the Page.MetaKeywords and Page.MetaDescription Properties (16)Enabling View State for Individual Controls (17)Changes to Browser Capabilities (19)Routing in 4 (25)Setting Client IDs (29)Persisting Row Selection in Data Controls (33) Chart Control (33)Filtering Data with the QueryExtender Control (36)Html Encoded Code Expressions (39)Project Template Changes (40)CSS Improvements (45)Hiding div Elements Around Hidden Fields (47)Rendering an Outer Table for Templated Controls (47)ListView Control Enhancements (49)CheckBoxList and RadioButtonList Control Enhancements (49)Menu Control Improvements (51)Wizard and CreateUserWizard Controls (52) MVC (55)Areas Support (55)Data-Annotation Attribute Validation Support (55)Templated Helpers (55)Dynamic Data (55)Enabling Dynamic Data for Existing Projects (56)Declarative DynamicDataManager Control Syntax (57)Entity Templates (57)New Field Templates for URLs and E-mail Addresses (59)Creating Links with the DynamicHyperLink Control (60)Support for Inheritance in the Data Model (60)Support for Many-to-Many Relationships (Entity Framework Only) (60)New Attributes to Control Display and Support Enumerations (60)Enhanced Support for Filters (61)Visual Studio 2010 Web Development Improvements (61)Improved CSS Compatibility (61)HTML and JavaScript Snippets (62)JavaScript IntelliSense Enhancements (62)Web Application Deployment with Visual Studio 2010 (62)Web Packaging (63)Web.config Transformation (63)Database Deployment (64)One-Click Publish for Web Applications (64) 4 and Visual Studio 2010 Web Development Overview 2 © 2010 Microsoft CorporationResources (64)Disclaimer (66)Core Services 4 introduces a number of features that improve core services such as output caching and session-state storage.Web.config File RefactoringThe Web.config file that contains the configuration for a Web application has grown considerably over the past few releases of the .NET Framework as new features have been added, such as Ajax, routing, and integration with IIS 7. This has made it harder to configure or start new Web applications without a tool like Visual Studio. In .the NET Framework 4, the major configuration elements have been moved to the machine.config file, and applications now inherit these settings. This allows the Web.config file in 4 applications either to be empty or to contain just the following lines, which specify for Visual Studio what version of the framework the application is targeting:<?xml version="1.0"?><configuration><system.web><compilation targetFramework="4.0" /></system.web></configuration>Extensible Output CachingSince the time that 1.0 was released, output caching has enabled developers to store the generated output of pages, controls, and HTTP responses in memory. On subsequent Web requests, can serve content more quickly by retrieving the generated output from memory instead of regenerating the output from scratch. However, this approach has a limitation — generated content always has to be stored in memory, and on servers that are experiencing heavy traffic, the memory consumed by output caching can compete with memory demands from other portions of a Webapplication. 4 adds an extensibility point to output caching that enables you to configure one or more custom output-cache providers. Output-cache providers can use any storage mechanism to persist HTML content. This makes it possible to create custom output-cache providers for diverse persistence mechanisms, which can include local or remote disks, cloud storage, and distributed cache engines. 4 and Visual Studio 2010 Web Development Overview 3 © 2010 Microsoft CorporationYou create a custom output-cache provider as a class that derives from the newSystem.Web.Caching.OutputCacheProvider type. You can then configure the provider in the Web.config file by using the new providers subsection of the outputCache element, as shown in the following example:<caching><outputCache defaultProvider="AspNetInternalProvider"><providers><add name="DiskCache"type="Test.OutputCacheEx.DiskOutputCacheProvider, DiskCacheProvider"/></providers></outputCache></caching>By default in 4, all HTTP responses, rendered pages, and controls use the in-memory output cache, as shown in the previous example, where the defaultProvider attribute is set to AspNetInternalProvider. You can change the default output-cache provider used for a Web application by specifying a different provider name for defaultProvider.In addition, you can select different output-cache providers per control and per request. The easiest way to choose a different output-cache provider for different Web user controls is to do so declaratively by using the new providerName attribute in a control directive, as shown in the following example:<%@ OutputCache Duration="60" VaryByParam="None" providerName="DiskCache" %>Specifying a different output cache provider for an HTTP request requires a little more work. Instead of declaratively specifying the provider, you override the new GetOuputCacheProviderName method in the Global.asax file to programmatically specify which provider to use for a specific request. The following example shows how to do this.public override string GetOutputCacheProviderName(HttpContext context){if (context.Request.Path.EndsWith("Advanced.aspx"))return"DiskCache";elsereturn base.GetOutputCacheProviderName(context);}With the addition of output-cache provider extensibility to 4, you can now pursue more aggressive and more intelligent output-caching strategies for your Web sites. For example, it is now possible to cache the "Top 10" pages of a site in memory, while caching pages that get lower traffic on 4 and Visual Studio 2010 Web Development Overview 4 © 2010 Microsoft Corporationdisk. Alternatively, you can cache every vary-by combination for a rendered page, but use a distributed cache so that the memory consumption is offloaded from front-end Web servers.Auto-Start Web ApplicationsSome Web applications need to load large amounts of data or perform expensive initializationprocessing before serving the first request. In earlier versions of , for these situations you had to devise custom approaches to "wake up" an application and then run initialization code during the Application_Load method in the Global.asax file.A new scalability feature named auto-star t that directly addresses this scenario is available when 4 runs on IIS 7.5 on Windows Server 2008 R2. The auto-start feature provides a controlled approach for starting up an application pool, initializing an application, and then accepting HTTP requests.IIS Application Warm-Up Module for IIS 7.5The IIS team has released the first beta test version of the Application Warm-Up Module for IIS7.5. This makes warming up your applications even easier than previously described. Instead ofwriting custom code, you specify the URLs of resources to execute before the Web applicationaccepts requests from the network. This warm-up occurs during startup of the IIS service (if youconfigured the IIS application pool as AlwaysRunning) and when an IIS worker process recycles.During recycle, the old IIS worker process continues to execute requests until the newlyspawned worker process is fully warmed up, so that applications experience no interruptions orother issues due to unprimed caches. Note that this module works with any version of ,starting with version 2.0.For more information, see Application Warm-Up on the Web site. For a walkthrough thatillustrates how to use the warm-up feature, see Getting Started with the IIS 7.5 ApplicationWarm-Up Module on the Web site.To use the auto-start feature, an IIS administrator sets an application pool in IIS 7.5 to be automatically started by using the following configuration in the applicationHost.config file:<applicationPools><add name="MyApplicationPool"startMode="AlwaysRunning" /></applicationPools>Because a single application pool can contain multiple applications, you specify individual applications to be automatically started by using the following configuration in the applicationHost.config file:<sites> 4 and Visual Studio 2010 Web Development Overview 5 © 2010 Microsoft Corporation<site name="MySite"id="1"><application path="/"serviceAutoStartEnabled="true"serviceAutoStartProvider="PrewarmMyCache" ><!-- Additional content --></application></site></sites><!--Additional content--><serviceAutoStartProviders><add name="PrewarmMyCache"type="MyNamespace.CustomInitialization, MyLibrary" /></serviceAutoStartProviders>When an IIS 7.5 server is cold-started or when an individual application pool is recycled, IIS 7.5 uses the information in the applicationHost.config file to determine which Web applications need to be automatically started. For each application that is marked for auto-start, IIS7.5 sends a request to 4 to start the application in a state during which the application temporarily does not accept HTTP requests. When it is in this state, instantiates the type defined by the serviceAutoStartProvider attribute (as shown in the previous example) and calls into its public entry point.You create a managed auto-start type with the necessary entry point by implementing the IProcessHostPreloadClient interface, as shown in the following example:public class CustomInitialization : System.Web.Hosting.IProcessHostPreloadClient{public void Preload(string[] parameters){// Perform initialization.}}After your initialization code runs in the Preload method and the method returns, the application is ready to process requests.With the addition of auto-start to IIS .5 and 4, you now have a well-defined approach for performing expensive application initialization prior to processing the first HTTP request. For example, 4 and Visual Studio 2010 Web Development Overview 6 © 2010 Microsoft Corporationyou can use the new auto-start feature to initialize an application and then signal a load-balancer that the application was initialized and ready to accept HTTP traffic.Permanently Redirecting a PageIt is common practice in Web applications to move pages and other content around over time, which can lead to an accumulation of stale links in search engines. In , developers have traditionally handled requests to old URLs by using by using the Response.Redirect method to forward a request to the new URL. However, the Redirect method issues an HTTP 302 Found (temporary redirect) response, which results in an extra HTTP round trip when users attempt to access the old URLs. 4 adds a new RedirectPermanent helper method that makes it easy to issue HTTP 301 Moved Permanently responses, as in the following example:RedirectPermanent("/newpath/foroldcontent.aspx");Search engines and other user agents that recognize permanent redirects will store the new URL that is associated with the content, which eliminates the unnecessary round trip made by the browser for temporary redirects.Shrinking Session State provides two default options for storing session state across a Web farm: a session-state provider that invokes an out-of-process session-state server, and a session-state provider that stores data in a Microsoft SQL Server database. Because both options involve storing state information outsidea Web application's worker process, session state has to be serialized before it is sent to remote storage.Depending on how much information a developer saves in session state, the size of the serialized data can grow quite large. 4 introduces a new compression option for both kinds of out-of-process session-stateproviders. When the compressionEnabled configuration option shown in the following example is set to true, will compress (and decompress) serialized session state by using the .NET Framework pression.GZipStream class.<sessionStatemode="SqlServer"sqlConnectionString="data source=dbserver;Initial Catalog=aspnetstate"allowCustomSqlDatabase="true"compressionEnabled="true"/> 4 and Visual Studio 2010 Web Development Overview 7 © 2010 Microsoft CorporationWith the simple addition of the new attribute to the Web.config file, applications with spare CPU cycles on Web servers can realize substantial reductions in the size of serialized session-state data.Expanding the Range of Allowable URLs 4 introduces new options for expanding the size of application URLs. Previous versions of constrained URL path lengths to 260 characters, based on the NTFS file-path limit. In 4, you have the option to increase (or decrease) this limit as appropriate for your applications, using two new httpRuntime configuration attributes. The following example shows these new attributes.<httpRuntime maxRequestPathLength="260"maxQueryStringLength="2048" />To allow longer or shorter paths (the portion of the URL that does not include protocol, server name, and query string), modify the maxRequestPathLength attribute. To allow longer or shorter query strings, modify the value of the maxQueryStringLength attribute. 4 also enables you to configure the characters that are used by the URL character check. When finds an invalid character in the path portion of a URL, it rejects the request and issues an HTTP 400 error. In previous versions of , the URL character checks were limited to a fixed set of characters. In 4, you can customize the set of valid characters using the newrequestPathInvalidChars attribute of the httpRuntime configuration element, as shown in the following example:<httpRuntime requestPathInvalidChars="<,>,*,%,&,:,\,?" />By default, the requestPathInvalidChars attribute defines eight characters as invalid. (In the string that is assigned to requestPathInvalidChars by default, the less than (<), greater than (>), and ampersand (&) characters are encoded, because the Web.config file is an XML file.) You can customize the set of invalid characters as needed.Note 4 always rejects URL paths that contain characters in the ASCII range of 0x00 to 0x1F, because those are invalid URL characters as defined in RFC 2396 of the IETF(/rfc/rfc2396.txt). On versions of Windows Server that run IIS 6 or higher, thehttp.sys protocol device driver automatically rejects URLs with these characters.Extensible Request Validation request validation searches incoming HTTP request data for strings that are commonly used in cross-site scripting (XSS) attacks. If potential XSS strings are found, request validation flags the suspect string and returns an error. The built-in request validation returns an error only when it finds the most common strings used in XSS attacks. Previous attempts to make the XSS validation more aggressive 4 and Visual Studio 2010 Web Development Overview 8 © 2010 Microsoft Corporationresulted in too many false positives. However, customers might want request validation that is more aggressive, or conversely might want to intentionally relax XSS checks for specific pages or for specific types of requests.In 4, the request validation feature has been made extensible so that you can use custom request-validation logic. To extend request validation, you create a class that derives from the new System.Web.Util.RequestValidator type, and you configure the application (in the httpRuntime section of the Web.config file) to use the custom type. The following example shows how to configure a custom request-validation class:<httpRuntime requestValidationType="Samples.MyValidator, Samples" />The new requestValidationType attribute requires a standard .NET Framework type identifier string that specifies the class that provides custom request validation. For each request, invokes the custom type to process each piece of incoming HTTP request data. The incoming URL, all the HTTP headers (both cookies and custom headers), and the entity body are all available for inspection by a custom request validation class like that shown in the following example:public class CustomRequestValidation : RequestValidator{protected override bool IsValidRequestString(HttpContext context, string value,RequestValidationSource requestValidationSource,string collectionKey,out int validationFailureIndex){...}}For cases where you do not want to inspect a piece of incoming HTTP data, the request-validation class can fall back to let the default request validation run by simply callingbase.IsValidRequestString.Object Caching and Object Caching ExtensibilitySince its first release, has included a powerful in-memory object cache(System.Web.Caching.Cache). The cache implementation has been so popular that it has been used in non-Web applications. However, it is awkward for a Windows Forms or WPF application to include a reference to System.Web.dll just to be able to use the object cache.To make caching available for all applications, the .NET Framework 4 introduces a new assembly, a new namespace, some base types, and a concrete caching implementation. The new 4 and Visual Studio 2010 Web Development Overview 9 © 2010 Microsoft Corporation 4 and Visual Studio 2010 Web Development Overview10© 2010 Microsoft Corporation System.Runtime.Caching.dll assembly contains a new caching API in the System.Runtime.Cachingnamespace. The namespace contains two core sets of classes:Abstract types that provide the foundation for building any type of custom cache implementation.A concrete in-memory object cache implementation (the System.Runtime.Caching.MemoryCache class).The new MemoryCache class is modeled closely on the cache, and it shares much of theinternal cache engine logic with . Although the public caching APIs in System.Runtime.Caching have been updated to support development of custom caches, if you have used the Cache object, you will find familiar concepts in the new APIs.An in-depth discussion of the new MemoryCache class and supporting base APIs would require an entire document. However, the following example gives you an idea of how the new cache API works. The example was written for a Windows Forms application, without any dependency on System.Web.dll . private void btnGet_Click(object sender, EventArgs e){//Obtain a reference to the default MemoryCache instance.//Note that you can create multiple MemoryCache(s) inside//of a single application.ObjectCache cache = MemoryCache.Default;//In this example the cache is storing the contents of a filestring fileContents = cache["filecontents"] as string ;//If the file contents are not currently in the cache, then//the contents are read from disk and placed in the cache.if (fileContents == null ){//A CacheItemPolicy object holds all the pieces of cache//dependency and cache expiration metadata related to a single//cache entry.CacheItemPolicy policy = new CacheItemPolicy();//Build up the information necessary to create a file dependency.//In this case we just need the file path of the file on disk.List <string > filePaths = new List <string >();filePaths.Add("c:\\data.txt");//In the new cache API, dependencies are called "change monitors". 4 and Visual Studio 2010 Web Development Overview11© 2010 Microsoft Corporation //For this example we want the cache entry to be automatically expired //if the contents on disk change. A HostFileChangeMonitor provides//this functionality.policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths));//Fetch the file's contentsfileContents = File.ReadAllText("c:\\data.txt");//And then store the file's contents in the cachecache.Set("filecontents", fileContents, policy);}MessageBox .Show(fileContents);}Extensible HTML, URL, and HTTP Header EncodingIn 4, you can create custom encoding routines for the following common text-encoding tasks:HTML encoding.URL encoding.HTML attribute encoding. Encoding outbound HTTP headers.You can create a custom encoder by deriving from the new System.Web.Util.HttpEncoder type and then configuring to use the custom type in the httpRuntime section of the Web.config file, as shown in the following example:<httpRuntime encoderType="Samples.MyCustomEncoder, Samples " />After a custom encoder has been configured, automatically calls the custom encoding implementation whenever public encoding methods of the System.Web.HttpUtility orSystem.Web.HttpServerUtility classes are called. This lets one part of a Web development team create a custom encoder that implements aggressive character encoding, while the rest of the Web development team continues to use the public encoding APIs. By centrally configuring a custom encoder in the httpRuntime element, you are guaranteed that all text-encoding calls from the public encoding APIs are routed through the custom encoder.Performance Monitoring for Individual Applications in a Single Worker ProcessIn order to increase the number of Web sites that can be hosted on a single server, many hosters run multiple applications in a single worker process. However, if multiple applications use a single shared worker process, it is difficult for server administrators to identify an individual application that is experiencing problems. 4 leverages new resource-monitoring functionality introduced by the CLR. To enable this functionality, you can add the following XML configuration snippet to the aspnet.config configuration file.<?xml version="1.0" encoding="UTF-8" ?><configuration><runtime><appDomainResourceMonitoring enabled="true"/></runtime></configuration>Note The aspnet.config file is in the directory where the .NET Framework is installed. It is not the Web.config file.When the appDomainResourceMonitoring feature has been enabled, two new performance counters are available in the " Applications" performance category: % Managed Processor Time and Managed Memory Used. Both of these performance counters use the new CLR application-domain resource management feature to track estimated CPU time and managed memory utilization ofindividual applications. As a result, with 4, administrators now have a more granular view into the resource consumption of individual applications running in a single worker process.Multi-TargetingYou can create an application that targets a specific version of the .NET Framework. In 4, a new attribute in the compilation element of the Web.config file lets you target the .NET Framework 4 and later. If you explicitly target the .NET Framework 4, and if you include optional elements in theWeb.config file such as the entries for system.codedom, these elements must be correct for the .NET Framework 4. (If you do not explicitly target the .NET Framework 4, the target framework is inferred from the lack of an entry in the Web.config file.)The following example shows the use of the targetFramework attribute in the compilation element of the Web.config file.<compilation targetFramework="4.0"/> 4 and Visual Studio 2010 Web Development Overview 12 © 2010 Microsoft Corporation 4 and Visual Studio 2010 Web Development Overview13© 2010 Microsoft CorporationNote the following about targeting a specific version of the .NET Framework:In a .NET Framework 4 application pool, the build system assumes the .NET Framework 4 as a target if the Web.config file does not include the targetFramework attribute or if the Web.config file is missing. (You might have to make coding changes to your application to make it run under the.NET Framework 4.)If you do include the targetFramework attribute, and if the system.codeDom element is defined in the Web.configfile, this file must contain the correct entries for the .NET Framework 4.If you are using the aspnet_compiler command to precompile your application (such as in a build environment), you must use the correct version of the aspnet_compiler command for the target framework. Use the compiler that shipped with the .NET Framework 2.0(%WINDIR%\\Framework\v2.0.50727) to compile for the .NET Framework 3.5 and earlier versions. Use the compiler that ships with the .NET Framework 4 to compile applicationscreated using that framework or using later versions.At run time, the compiler uses the latest framework assemblies that are installed on the computer (and therefore in the GAC). If an update is made later to the framework (for example, a hypothetical version 4.1 is installed), you will be able to use features in the newer version of the framework even though the targetFramework attribute targets a lower version (such as 4.0). (However, at design time in Visual Studio 2010 or when you use the aspnet_compiler command, using newer features of the framework will cause compiler errors).AjaxjQuery Included with Web Forms and MVCThe Visual Studio templates for both Web Forms and MVC include the open-source jQuery library. Whenyou create a new website or project, a Scripts folder containing the following 3 files is created:jQuery-1.4.1.js –The human-readable, unminified version of the jQuery library.jQuery-14.1.min.js –The minified version of the jQuery library.jQuery-1.4.1-vsdoc.js – The Intellisense documentation file for the jQuery library.Include the unminified version of jQuery while developing an application. Include the minified version of jQuery for production applications.For example, the following Web Forms page illustrates how you can use jQuery to change the background color of TextBox controls to yellow when they have focus.<%@ Page Language ="C#" AutoEventWireup ="true" CodeFile ="ShowjQuery.aspx.cs"Inherits ="ShowjQuery" %>。