asp.net实验一:hello world!

本文介绍使用IIS7部署ASP.NET应用的注意事项及步骤,包括.NET Framework 4.0与IIS安装顺序、虚拟目录设置等,并通过Hello World示例详细说明从创建项目到部署的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      用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而已。


 

 

  

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_千鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值