用IIS 7 部署asp.net我觉得真的很让人头疼,简直就是难产。
不过总结起来又几条值得注意:
一、安装iis和.NET F4.0先后顺序:如果先装.NET4.0,再装IIS,会出错,解决办法是修复重装.NET4.0;
二、需要在网站应用程序中添加虚拟目录,否则只能用IIS部署ASP,而不能部署ASP.NET;
三、部署的时候最好测试连接,看是否具有文件读写权限;
用visual stdio 开发时也许会成功,但是部署就是会出问题,要是你也遇到,多百度一下吧,下面具体说一个开发hello world的asp.net。
一、建立工程项目
新建一个空的解决方案,在解决方案中添加一个ASP.NET WET 空应用程序aspnet3
二、向改asp.net 应用程序添加web 窗体,命名为index.aspx;
添加代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="aspnet3.index" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="166px"></asp:TextBox>
<asp:Button ID="button" runat="server" Text="确定" onclick="button_Click" />
</div>
</form>
</body>
</html>
切换到 设计或拆分模式,双击buutom按钮,添加响应代码:
index.aspx.cs代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace aspnet3
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void button_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text == String.Empty)
{
this.Session["work"] = "World!";
}
else
{
this.Session["work"] = this.TextBox1.Text.ToString();
}
Response.Redirect("hello.aspx"); //跳转到hello.aspx
}
}
}
同index.aspx一样,添加hello.aspx 的web窗体:
hello.aspx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hello.aspx.cs" Inherits="aspnet3.hello" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
修改hello.aspx.cs代码,hello.aspx.cs完全代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace aspnet3
{
public partial class hello : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Label1.Text = "Hello " + this.Session["work"];
}
}
}
运行即可查看程序。
人懒了,写得不是很详细,仅仅是记录下asp.net的hello world而已。