asp.net实验一:hello world!

本文介绍使用IIS7部署ASP.NET应用时常见的问题及解决方案,并通过一个简单的HelloWorld示例展示从创建项目到部署的全过程。

摘要生成于 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而已。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值