`
444878909
  • 浏览: 640962 次
文章分类
社区版块
存档分类
最新评论

asp.net实验一:hello world!

 
阅读更多

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


分享到:
评论

相关推荐

    【Asp.Net MVC 入门Hello World】一步一步改写简单的登录注册(一)

    【Asp.Net MVC 入门Hello World】一步一步改写简单的登录注册(一) 参考:http://www.0379zd.com/news/show/24102.htm

    二 ASP.NET MVC 第一个程序 hello world

    二 ASP.NET MVC 第一个程序 hello world

    十天学会ASP.net--我认为ASP.NET比ASP难很多,希望大家做好准备

    这样ASP.NET就有四种组合:VB+ACCESS,VB+SQL,C#+ACCESS,C#+SQL,本教程会使用C#+ACCESS,兼顾四种来写,让大家对ASP.NET有一个全面的认识。虽然说学习ASP.NET不需要任何ASP基础,但是我觉得如果大家ASP不会,还是...

    ASP.NET编程百例(PDF)

    实例21ASP.NET简易应用程序“Hello,22World!” 实例22读取Config.22Web配置文件 实例23显示BrowseCaps配置段内容 实例24写入文件操作与应用 实例25文件读操作及应用 实例26文件删除与应用 实例27ASP.NET中异常处理...

    ASP.NET应用开发案例教程

    1.3 从HelloWorld开始 1.3.1 用HTML编写的Hello World程序 1.3.2 用C#编写的Hello World程序 1.4 小结 1.5 习题 第2章 ASP.NET语言基础 2.1 C#言简介 2.2 一个简单的程序 .2.3 C#中的数据类型 ...

    asp.net 操作 access 增删改查

    这是为一个想了解asp.net的朋友写的一个helloworld程序,简单的增删改查,简单的三层结构,使用datareader。有简单注释。 推荐初学者下载。高手会失望。

    ASP.NET应用与开发案例教程

    上篇ASP.NET应用与开发基础 第1章ASP.NET概论 1.1ASP.NET简介 1.1.1从.NET谈起 1.1.2动态网站设计技术 1.1.3ASP.NET的介绍 1.1.4ASP.NET和ASP的对比 1.2运行环境配置 1.2.1ASP.NET运行环境介绍 1.2.21lS的安装和配置...

    十天学会ASP.NET

    这样ASP.NET就有四种组合:VB+ACCESS,VB+SQL,C#+ACCESS,C#+SQL,本教程会使用C#+ACCESS,兼顾四种来写,让大家对ASP.NET有一个全面的认识。虽然说学习ASP.NET不需要任何ASP基础,但是我觉得如果大家ASP不会,还是...

    10天学会ASP.NET教程

    Response.Write("Hello World!"); } &lt;/script&gt; &lt;script language="vb" runat="server"&gt; sub page_load() response.write("Hello World!") end sub &lt;/script&gt; 在这里我要说明两点:1、我的示例文件总是有A和...

    《ASP.NET Ajax程序设计 第II卷》附书源码

    因此,我将在书中讲述ASP.NET AJAX的方方面面,从最基础的“Hello World”示例到复杂的整站程序和底层的实现原理分析,从最简单的客户端效果到其深层次的用户心理学分析及用户体验改善。 正因为本书的介绍范围广泛...

    MVC asp.net core入门 helloworld 控制器类的添加 成功输出参数

    MVC asp.net core入门 helloworld 控制器类的添加 成功输出参数

    Test-Drive ASP.NET MVC

    1 Getting Started with ASP.NET MVC 1.1 How ASP.NET MVC Works 1.2 Installing MVC 1.3 MVC in Five Minutes: Building Quote-O-Matic 2 Test-Driven Development 2.1 TDD Explained 2.2 Test-Driving ...

    ASP.NET编程百例 PDF扫描版 附源代码(vb.net)

    ASP NET是微软.NET战略中的一个重要成员 除了可以使用Visual C# VB.NET VisualC++ NET JScript.NET等语言编写外 还可以使用第三方的.NET接口 如COBOL.NET Perl.NET等 进行编写 本书通过100个精彩实例 由浅入深...

    c#、asp.net基础程序练习

    string teststring="hello, world!"; //定义变量 textBox1.Text = teststring; } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button2_Click(object sender, ...

    MVC工程模板_C#_asp.net_

    ASP.NET中MVC编程模式简介与搭建HelloWorld项目

    AspNet5.HelloWorld:Asp.net 5 测试

    ASP.NET 5 主页 最新开发版本: 最新主版本: Home 存储库是人们了解 ASP.NET 5 的起点。此存储库包含示例和,可帮助人们入门并了解有关 ASP.NET 5 即将推出的内容的更多信息。 ASP.NET 5 正在由分配给 Microsoft...

    JS JSP ASP .NET J2AM API接口和返回的版本

    在 Java 客户端中,我们使用了接口来描述远程方法,之后我们通过 useService 方法返回一个远程代理对象,该对象实现了我们定义的接口,之后我们就可以直接调用远程方法 helloWorld 了。如果你比较细心的话,你还会...

    C# 7.1 and .NET Core 2.0 – Modern Cross-Platform Development – Third Edition

    C# 7.1 and .NET Core 2.0 – Modern Cross-Platform Development – Third Edition 版本: Create powerful applications with .NET Standard 2.0, ASP.NET Core 2.0, … Visual Studio 2017 or Visual Studio Code ...

    .NET API接口和返回的版本

    在 Java 客户端中,我们使用了接口来描述远程方法,之后我们通过 useService 方法返回一个远程代理对象,该对象实现了我们定义的接口,之后我们就可以直接调用远程方法 helloWorld 了。如果你比较细心的话,你还会...

    hello-csharp-aspnet:使用Hasura的ASP.NET hello-world应用

    你好,csharp-aspnet 该项目包含一个基本的Hasura项目,并在其上运行了一个简单的C#-ASP.net应用程序。 将此应用程序部署到Hasura群集上后,您将在https://api.&lt;cluster&gt;.hasura-app.io运行该应用程序...

Global site tag (gtag.js) - Google Analytics