Step-by-step learning spring.net--First program "Hello,world"

Source: Internet
Author: User

1, create a new class Framework. CS

public class Framework{public Framework () {////todo: Add constructor logic here//} public    string Name {set; get;}}

2. add a label to the index.aspx page

   <div>        

3. Index.aspx.cs

public partial class index:system.web.ui.page{    //define an injection point public    Framework frameworkname {set; get;}     protected void Page_Load (object sender, EventArgs e)    {        This.lblFramework.Text = this. Frameworkname.name;}    }

There are two main ways to define an object, either directly in Web. config , or in an external configuration file.

4, directly defined in the Web. config , using Spring.Context.Support.DefaultSectionHandler . This can be defined directly in the configuration file.

<configSections> <!--Spring Configuration--<sectiongroup name= "Spring" > <section name= "Context" Type= "Spring.Context.Support.WebContextHandler, Spring.web"/> <!--support for defining objects in Web. config--<section Name= "Objects" type= "Spring.Context.Support.DefaultSectionHandler, Spring.core"/> </sectionGroup> </ configsections> <spring> <context> <resource uri= "config://spring/objects"/> </context&    Gt         <!--objects directly defined in Web. config--<objects> <object id= "framework" type= "Framework" ><!--class name--       <property name= "name" value= "Hello,world"/><!--property name, Value-</object> <!--Page Object-- <object type= "~/index.aspx" > <!--ref means the object being referenced--<property name= "FrameworkName" ref= "f Ramework "/><!--index.aspx page Property name--</object> </objects> </spring>

5. Browse index.aspx

6. Configure the object in a separate configuration file.

Create a folder in your Web site named Config to save the standalone configuration file.

In the Config folder, create an XML configuration file named objects.xml . Add A root element named objects, add the default namespace xmlns= "Http://www.springframework.net"

Locate the following schema file and copy to the VS installation directory:C:\Program Files (x86) \microsoft Visual Studio 10.0\xml\schemas

In this way, we have IntelliSense capabilities in the XML file.

Add the original object definition here.

<?xml version= "1.0" encoding= "Utf-8"? ><objects xmlns= "http://www.springframework.net" ><!--default namespace-- >  <object id= "framework" type= "Framework" >    <!--class name--    <property name= "name" value= " Hello,china "/>    <!--property name, Value--  </object>  <!--Page Object--  <object type=" ~/ Index.aspx ">    <!--ref represents objects referenced--    <property name=" FrameworkName "ref=" framework "/>    <! --index.aspx page Property name-  </object></objects>

Remove the Objects configuration section that was originally configured in Web. config, replacing the configuration in the original context configuration section with the following.

    <context>      <resource uri= "~/config/objects.xml"/>      <!--<resource uri= "config://spring/ Objects "/>-->    </context>

6, re-browse index.aspx

Step-by-step learning spring.net--First program "Hello,world"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.