小旋风asp iis_ASP 4-绕.NET 4(和Visual Studio 2010)Beta 1的旋风之旅

小旋风asp  iis

小旋风asp iis

Hey, we released Visual Studio 2010 Beta 1. JasonZ has a great post with piles of details and a metric crapload of screenshots. Definitely take a moment (or eight) and check out his very detailed post. You can get it NOW if you're an MSDN Subscriber, or after the general announcement on Weds if you're not.

嘿,我们发布了Visual Studio 2010 Beta1。JasonZ发表了一篇很棒的文章,其中包含大量的细节和度量的屏幕截图。 绝对要花一点时间(或八点),然后查看他非常详细的帖子。 如果您是MSDN订阅者,则可以立即获取;如果不是,则可以在Weds上的一般公告后获得。

UPDATE: My bad, of course it's called ASP.NET 4 and not ASP 4. Sorry, typo.

更新:我不好,它的名称叫ASP.NET 4,而不是ASP4。对不起,错字。

你应该吓跑吗? (Should You Freak Out?)

I don't think so. There's a lot of stuff that's new and added in .NET 4, but not in that "overwhelming-I-need-to-relearn-everything" way. More in that, "oh, this is way easier/simpler now" way. Like, moving data around with ADO.NET DataServices is easy, binding with client templates is easy, there's F# if you need it, the "dynamic" keyword if you need it, Silverlight's already installed, oh, and the parallel stuff will freak you out, but in a good way.

我不这么认为。 .NET 4中有很多新内容,但并不是以“压倒性的我需要重新学习一切”的方式。 除此之外,“哦,这现在变得更容易/更简单”了。 就像,使用ADO.NET DataServices轻松移动数据,轻松地与客户端模板绑定一样,如果需要,可以使用F#,如果需要,可以使用“ dynamic”关键字,已经安装了Silverlight,哦,并行的东西会让您抓狂出去,但是很好。

I'll do a series of posts on what I think is cool with lots of details. I'll put code samples up also as I can. I will also point out where you can already do much of this with 3.5 SP1, as well.

我将发表许多我认为很酷的文章,其中包含许多细节。 我也会尽可能地整理代码示例。 我还将指出,在3.5 SP1中您已经可以在其中完成很多工作。

Here's a general outline of a small part of the goodness:

以下是善意的一小部分的概述:

  • New Shell, new File|New, new Extensions Manager

    新的Shell,新的文件|新的扩展管理器
  • Lots of focus on "Code First" (TDD-friendly, etc)

    大量关注“代码优先”(适合TDD等)
  • Office and COM Interop that is actually fun to do.

    Office和COM Interop实际上很有趣。
  • Automatic Properties for VB, no more "_" for multi-line, inline subs, collection initializers

    VB的自动属性,多行,内联子,集合初始化程序不再具有“ _”
  • C# gets the dynamic keyword

    C#获取动态关键字
  • F# is included out of the box

    F#开箱即用
  • WPF Databinding in the Designer

    设计器中的WPF数据绑定
  • Silverlight included out of the box

    开箱即用的Silverlight
  • Piles of HTML Snippets for non-designer people

    面向非设计人员的大量HTML代码段
  • Better JavaScript Intellisense

    更好JavaScript Intellisense
  • MSBuild for C++

    MSBuild for C ++
  • UML for VS Team Architecture

    用于VS团队架构的UML
  • TFS Branch and Changeset visualizers

    TFS分支和变更集可视化器
  • Parallel computing

    并行运算
  • Workflow speedup, new designer

    工作流程加速,新设计师
  • SharePoint tooling

    SharePoint工具

Rather than try to top Jason with a laundry list of what's new and what not, here's some details on a few things that I find particularly interesting. They may be obscure to you, and perhaps not deeply interesting, but they were interesting enough to me that I used them for demos at TechEd last week (with a hat tip to Jonathan Carter and Jason Olson).

与其尝试在Jason上列出新功能和新功能的清单,不如说是我发现特别有趣的一些细节。 它们可能对您来说晦涩难懂,也许并不那么有趣,但是对我来说它们却足够有趣,以至于我上周在TechEd上将它们用于演示(向乔纳森·卡特杰森·奥尔森致敬)。

This is just a smattering of the features (hence: "Whirlwind" although "totally random cool stuff" would have also worked) coming in .NET 4. These are features I'm interested in because they've solved problems I've had in the past.

这只是.NET 4中的一些功能(因此:“旋风”,尽管“完全随机的酷东西”也可以使用),这些是我感兴趣的功能,因为它们已经解决了我遇到的问题以往。

I'm realizing I'll definitely do these as separate posts because they're going to get long. First, ASP.NET and Ajax.

我意识到我一定会把这些作为单独的文章来做,因为它们会变得很长。 首先是ASP.NET和Ajax

ASP.NET 4 (ASP.NET 4)

There is an excellent whitepaper at http://www.asp.net/learn/whitepapers/aspnet40/ with a lot of detail on the changes in ASP.NET 4.

http://www.asp.net/learn/whitepapers/aspnet40/上有一个很好的白皮书,其中详细介绍了ASP.NET 4中的更改。

There's lots new in ASP.NET 4, but at TechEd09 I showed two. First was control over my controls' client ids. Rather than getting a generated ID like ctl09_list45_whatever99, I can make my control ids more predictable.

ASP.NET 4中有很多新功能,但是在TechEd09上我展示了两个。 首先是控制我的控件的客户端ID。 我可以使控件ID更具可预测性,而不是像ctl09_list45_whatever99这样生成ID。

对WebForms中的ClientID的更多控制 (More Control over ClientIDs in WebForms)

For example, here's a ListView (ol/li) of Television shows. It uses jQuery to be sortable. Notice the new attributes in asp:ListView, specifically ClientIDRowSuffix and ClientIDMode.

例如,这是电视节目的ListView(ol / li)。 它使用jQuery进行排序。 请注意asp:ListView中的新属性,特别是ClientIDRowSuffix和ClientIDMode。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Television Series Picker</title>
<link href="Default.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="ui.core.js" type="text/javascript"></script>
<script src="ui.sortable.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function() {
$("#televisionList li").append("<div><span>Click</span></div>");
$("#televisionList").sortable({ handle: $("#televisionList li div") });
});
</script>
</head>
<body>
<form runat="server">
<h1>Television Series Picker</h1>
<p>Order the following television series' based on which you think is most awesome:</p>
<asp:ListView
DataSourceID="televisionDataSource"
ClientIDRowSuffix="ID"
ClientIDMode="Predictable"
runat="server">
<LayoutTemplate>
<ol id="televisionList">
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</ol>
</LayoutTemplate>
<ItemTemplate>
<li id="televisionItem" runat="server">
<%# Eval("Name") %>
</li>
</ItemTemplate>
</asp:ListView>
<asp:ObjectDataSource
ID="televisionDataSource"
TypeName="_01_ClientId.TelevisionDataProvider"
SelectMethod="GetTelevisionSeries"
runat="server" />
</form>
</body>
</html>

The list is populated using an ObjectDataSource and I want the client id's to be created with a suffix using the ID property from the Television object.

该列表是使用ObjectDataSource填充的,我希望使用电视对象的ID属性使用后缀创建客户端ID。

路由和WebForms (Routing and WebForms)

You probably know that System.Web.Routing is a big part of ASP.NET MVC, and you may know it's in .NET 3.5 SP1 as well. In .NET 4 it'll be even more easy to use with better support for WebForms. For example:

您可能知道System.Web.Routing是ASP.NET MVC的重要组成部分,并且您可能也知道它在.NET 3.5 SP1中。 在.NET 4中,有了更好的WebForms支持,它将更加易于使用。 例如:

public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add("Product",
new Route("Products/{category}",
new PageRouteHandler("~/Products.aspx")));
}
}

Here I'm setting update a route such that /Products/SomeCategory routes to the /Products.aspx WebForms Page. The Category parameter is a RouteParameter and can be retrieved (of course) and used. System.Web.UI.Page has a RouteData parameter now, or you can refer to RouteValues in your ASPX markup. For example:

在这里,我正在设置更新路由,以使/ Products / SomeCategory路由到/Products.aspx WebForms页面。 Category参数是RouteParameter,可以(当然)进行检索和使用。 System.Web.UI.Page现在具有RouteData参数,或者您可以在ASPX标记中引用RouteValues。 例如:

<p>The following are all the products within this category:</p>
<h2><asp:Literal Text="<%$ RouteValue:Category %>" runat="server" /></h2>

or into a Data Source via <RouteParameter>:

或通过<RouteParameter>进入数据源:

<asp:EntityDataSource
ID="productsDataSource"
ContextTypeName="AdventureWorksLTEntities"
EntitySetName="Products"
OrderBy="it.Name"
Where="it.Category.Name = @Category"
runat="server">
<WhereParameters>
<asp:RouteParameter
Name="Category"
RouteKey="Category"
Type="String" />
</WhereParameters>
</asp:EntityDataSource>

There will also be Routing Extension Methods like GetUrlForRoute or the like, in Beta 2, as well as IgnoreRoute. Basically anything that makes it simple, simple, simple to use Routes with WebForms. This'll be nice for hybrid WebForms/MVC apps as well.

Beta 2中还将有路由扩展方法,如GetUrlForRoute等,以及IgnoreRoute。 基本上,使路由与WebForms一起使用变得简单,简单,容易的任何事情。 这对于混合WebForms / MVC应用程序也会很好。

阿贾克斯4 (Ajax 4)

The Client Templates stuff in Ajax 4 is pretty sweet. This allows for 2-way data-binding using only JavaScript. For example, this template pulls from a JSON DataService at customers.svc. The JavaScript is below. We create a DataContext pointing to that endpoint, two DataViews that take the "customers-template" and "customer-template" HTML elements and creates a binding between them.

Ajax 4中的Client Templates很不错。 这允许仅使用JavaScript进行2路数据绑定。 例如,此模板从customer.svc的JSON DataService中提取。 JavaScript在下面。 我们创建一个指向该端点的DataContext,这两个DataView带有“ customers-template”和“ customer-template” HTML元素,并在它们之间创建绑定。

Sys.Application.add_init(function()
{
var dataContext = $create(Sys.Data.AdoNetDataContext,
{
serviceUri: "Customers.svc"
});

var customersTemplate = $create(Sys.UI.DataView,
{
dataProvider: dataContext,
fetchOperation: "Customers",
fetchParameters: { $top: 20, $orderby: "FirstName", $expand: "Orders" },
initialSelectedIndex: 0,
selectedItemClass: "selected"
},
null, null,
$get("customers-template"));

var customerTemplate = $create(Sys.UI.DataView,
null, null, null,
$get("customer-template"));

// This imperatively creates the binding
// between the customer grid and the customer
// detail form. When you select a record in
// the grid, it will automatically re-bind
// the detail view as well.
$create(Sys.Binding,
{
defaultValue: null,
source: customersTemplate,
path: "selectedData",
target: customerTemplate,
targetProperty: "data"
});

// This uses jQuery live event bindings to hook up
// the click event for the update button that will be
// "generated" when the customer detail form is bound.
$("#update-button").live("click", function()
{
dataContext.saveChanges();
});
});

Then we use jQuery live events, and then save the changes back to the dataContext. The changes that are made on the client side are tracked automatically, and those changes are sent back via JSON and commited. Note the source: and target: in the $create() call above that sets the master/detail relationship between customers and customer (singular.)

然后,我们使用jQuery实时事件,然后将更改保存回dataContext。 在客户端进行的更改将被自动跟踪,并且这些更改将通过JSON发送回并提交。 注意上面的$ create()调用中的source:和target:,它设置客户和客户之间的主/明细关系(单数)。

The client-side templates are similar to the server-side templates you probably already know how to use. You can even use expressions like to conditionally apply CSS.

客户端模板类似于您可能已经知道如何使用的服务器端模板。 您甚至可以使用表达式来有条件地应用CSS。

image
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AdventureWorks AJAX</title>
<link href="Content/Styles/reset-min.css" rel="stylesheet" type="text/css" />
<link href="Content/Styles/Default.css" rel="stylesheet" type="text/css" />

<script src="Content/Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="Content/Scripts/MicrosoftAjaxTemplates.debug.js" type="text/javascript"></script>
<script src="Content/Scripts/MicrosoftAjaxAdoNet.debug.js" type="text/javascript"></script>
<script src="Content/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>

<script src="Content/Scripts/Default.js" type="text/javascript"></script>
</head>
<body
xmlns:sys="javascript:Sys"
xmlns:class="http://schemas.microsoft.com/aspnet/class">
<h1>Customer Directory</h1>
<table cellspacing="0">
<thead>
<tr>
<th>Title</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>Suffix</th>
</tr>
</thead>
<tbody id="customers-template" class="sys-template">
<tr sys:command="select" class:odd="{{ $index % 2 != 0 }}">
<td>{binding Title, defaultValue=}</td>
<td>{binding FirstName}</td>
<td>{binding MiddleName, defaultValue=}</td>
<td>{binding LastName}</td>
<td>{binding Suffix, defaultValue=}</td>
</tr>
</tbody>
</table>
<fieldset id="customer-template" class="sys-template">
<legend>{{ FirstName + " " + LastName }}</legend>
<label for="first-name">
<span>First Name:</span>
<input type="text" id="first-name" value="{binding FirstName}" />
</label>
<label for="middle-name">
<span>Middle Name:</span>
<input type="text" id="middle-name" value="{binding MiddleName, defaultValue=}" />
</label>
<label for="last-name">
<span>Last Name:</span>
<input type="text" id="last-name" value="{binding LastName}" />
</label>
<input id="update-button" type="button" value="Update" />
</fieldset>
</body>
</html>

This exact scenario can also be done declaratively with you having to write ANY JavaScript at all. The "declarations" from the JavaScript file above are replaced with declarative namespace statements like:

您也完全可以编写ANY JavaScript,从而可以声明性地完成这种情况。 上面JavaScript文件中的“声明”被声明性的名称空间语句替换,例如:

<fieldset
class="sys-template"
sys:attach="dataview"
dataview:data="{binding selectedData, source={{customersTemplate}}}"
dataview:sys-key="customerTemplate">
<legend>{{ FirstName + " " + LastName }}</legend>
...

And the result is the same as above:

结果与上面相同:

image

It's important to point out that while you can go get the VS 2010 Beta 1, you can also play with this stuff TODAY running on .NET 3.5 SP1. Go over to the ASP.NET 4 Ajax Preview site on CodePlex.

重要的是要指出,虽然您可以获取VS 2010 Beta 1,但您也可以在.NET 3.5 SP1上运行今天的东西。 转至CodePlex上的ASP.NET 4 Ajax Preview网站。

Also, don't freak out that ASP.NET MVC isn't baked into VS2010 Beta 1. Phil explains here.

另外,请不要怪异VS2010 Beta 1没有引入ASP.NET MVC。Phil在此进行了解释

Related Links

相关链接

Have fun!

玩得开心!

翻译自: https://www.hanselman.com/blog/asp-4-whirlwind-tour-around-net-4-and-visual-studio-2010-beta-1

小旋风asp iis

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值