Archive for 2月 10th, 2012

  1. Hello, ASP.NET World!

    Posted on 2月 10th, 2012 by cx20

    ASP.NET

    ASP.NET は、ASP の後継でマイクロソフトの Web サーバー(IIS)でプログラムを動作させる技術の一つである。
    既定の言語として Visual Basic(VB.NET)や C# が用いられるが、実際にはコンパイルされた .NET アセンブリが使用される為、JScript.NET や C++/CLI など .NET に対応した他の言語でも記述が可能である。

    ソースコード(Visual Basic)

    <%@ Page Language="VB" %>
    <html>
      <head>
        <title>Hello, World!</title>
      </head>
      <body>
        <p><% Response.Write( "Hello, ASP.NET World!" ) %></p>
      </body>
    </html>

    ソースコード(C#)

    <%@ Page Language="C#" %>
    <html>
      <head>
        <title>Hello, World!</title>
      </head>
      <body>
        <p><% Response.Write( "Hello, ASP.NET World!" ); %></p>
      </body>
    </html>

    ソースコード(JScript.NET)

    <%@ Page Language="JScript" %>
    <html>
      <head>
        <title>Hello, World!</title>
      </head>
      <body>
        <p><% Response.Write( "Hello, ASP.NET World!" ); %></p>
      </body>
    </html>

    上記コードは、以下の .NET のコードに相当する(以下の例は C# のケース)。実行時に .NET アセンブリにコンパイルされ実行される。

    ソースコード

     
    namespace ASP {
        using System.Web;
        using System.Text.RegularExpressions;
        using System.Web.Profile;
        using System.Web.UI.WebControls;
        using System.Web.Security;
        using System.Collections.Generic;
        using System.Collections.Specialized;
        using System;
        using System.Xml.Linq;
        using System.Collections;
        using System.Linq;
        using System.Web.UI;
        using System.Web.DynamicData;
        using System.Text;
        using System.Web.Caching;
        using System.Web.UI.HtmlControls;
        using System.Configuration;
        using System.Web.UI.WebControls.WebParts;
        using System.Web.SessionState;
        using System.ComponentModel.DataAnnotations;
     
        [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
        public class hello_aspx : global::System.Web.UI.Page, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
            private static bool @__initialized;
            private static object @__fileDependencies;
     
            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            public hello_aspx() {
                string[] dependencies;
                ((global::System.Web.UI.Page)(this)).AppRelativeVirtualPath = "~/hello.aspx";
                if ((global::ASP.hello_aspx.@__initialized == false)) {
                    dependencies = new string[1];
                    dependencies[0] = "~/hello.aspx";
                    global::ASP.hello_aspx.@__fileDependencies = this.GetWrappedFileDependencies(dependencies);
                    global::ASP.hello_aspx.@__initialized = true;
                }
                this.Server.ScriptTimeout = 30000000;
            }
     
            protected System.Web.Profile.DefaultProfile Profile {
                get {
                    return ((System.Web.Profile.DefaultProfile)(this.Context.Profile));
                }
            }
     
            protected override bool SupportAutoEvents {
                get {
                    return false;
                }
            }
     
            protected System.Web.HttpApplication ApplicationInstance {
                get {
                    return ((System.Web.HttpApplication)(this.Context.ApplicationInstance));
                }
            }
     
            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            private void @__BuildControlTree(hello_aspx @__ctrl) {
                this.InitializeCulture();
                @__ctrl.SetRenderMethodDelegate(new System.Web.UI.RenderMethod(this.@__Render__control1));
            }
     
            private void @__Render__control1(System.Web.UI.HtmlTextWriter @__w, System.Web.UI.Control parameterContainer) {
                @__w.Write("rn<html>rn<head>rn<title>Hello, World!</title>rn</head>rn<body>rn<p>");
                Response.Write( "Hello, ASP.NET World!" );
                @__w.Write("</p>rn</body>rn</html> ");
            }
     
            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            protected override void FrameworkInitialize() {
                base.FrameworkInitialize();
                this.@__BuildControlTree(this);
                this.AddWrappedFileDependencies(global::ASP.hello_aspx.@__fileDependencies);
                this.Request.ValidateInput();
            }
        }
    }

    実行方法

    1. IIS の公開フォルダ に配置
    2. ブラウザで表示
       http://localhost/doc/hello.aspx

    実行結果

    Hello, ASP.NET World!