2013年8月4日 星期日

tomcat vs asp.net

tomcat vs asp.net
vbasic.net vs java
.dll vs .class

http://msdn.microsoft.com/en-us/library/vstudio/ba0z6a33%28v=vs.100%29.aspx

XML Web Services Using ASP.NET



http://msdn.microsoft.com/en-us/library/2tw134k3%28v=vs.100%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

How to: Create Custom Configuration Sections Using ConfigurationSection

 




web.xml (java) vs web.config (asp.net)

web.config
<configuration>
<!-- Configuration section-handler declaration area. -->
  <configSections>
    <sectionGroup name="pageAppearanceGroup">
      <section 
        name="pageAppearance" 
        type="Samples.AspNet.PageAppearanceSection" 
        allowLocation="true" 
        allowDefinition="Everywhere"
      />
    </sectionGroup>
      <!-- Other <section> and <sectionGroup> elements. -->
  </configSections>

  <!-- Configuration section settings area. -->

</configuration>
 
 
<configuration>

<!-- Configuration section-handler declaration area. -->

  <!-- Configuration section settings area. -->
  <pageAppearanceGroup>
    <pageAppearance remoteOnly="true">
      <font name="TimesNewRoman" size="18"/>
      <color background="000000" foreground="FFFFFF"/>
    </pageAppearance>
  </pageAppearanceGroup>

  <!-- Other configuration settings, such as system.web -->

</configuration>
 
 
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 
PageAppearanceSection.vb
 
Imports System
Imports System.Collections
Imports System.Text
Imports System.Configuration
Imports System.Xml

Namespace Samples.AspNet

    Public Class PageAppearanceSection
        Inherits ConfigurationSection

        ' Create a "remoteOnly" attribute.
        <ConfigurationProperty("remoteOnly", DefaultValue:="false", IsRequired:=False)> _
        Public Property RemoteOnly() As Boolean
            Get
                Return CType(Me("remoteOnly"), Boolean)
            End Get
            Set(ByVal value As Boolean)
                Me("remoteOnly") = value
            End Set
        End Property

        ' Create a "font" element.
        <ConfigurationProperty("font")> _
        Public Property Font() As FontElement
            Get
                Return CType(Me("font"), FontElement)
            End Get
            Set(ByVal value As FontElement)
                Me("font") = value
            End Set
        End Property

        ' Create a "color element."
        <ConfigurationProperty("color")> _
        Public Property Color() As ColorElement
            Get
                Return CType(Me("color"), ColorElement)
            End Get
            Set(ByVal value As ColorElement)
                Me("color") = value
            End Set
        End Property
    End Class

    ' Define the "font" element
    ' with "name" and "size" attributes.
    Public Class FontElement
        Inherits ConfigurationElement

        <ConfigurationProperty("name", DefaultValue:="Arial", IsRequired:=True), _
         StringValidator(InvalidCharacters:="~!@#$%^&*()[]{}/;'\""|\\", MinLength:=1, MaxLength:=60)> _
        Public Property Name() As String
            Get
                Return CType(Me("name"), String)
            End Get
            Set(ByVal value As String)
                Me("name") = value
            End Set
        End Property

        <ConfigurationProperty("size", DefaultValue:="12", IsRequired:=False), _
         IntegerValidator(ExcludeRange:=False, MaxValue:=24, MinValue:=6)> _
        Public Property Size() As Integer
            Get
                Return CType(Me("size"), Integer)
            End Get
            Set(ByVal value As Integer)
                Me("size") = value
            End Set
        End Property
    End Class

    ' Define the "color" element 
    ' with "background" and "foreground" attributes.
    Public Class ColorElement
        Inherits ConfigurationElement

        <ConfigurationProperty("background", DefaultValue:="FFFFFF", IsRequired:=True), _
         StringValidator(InvalidCharacters:="~!@#$%^&*()[]{}/;'\""|\\GHIJKLMNOPQRSTUVWXYZ", MinLength:=6, MaxLength:=6)> _
        Public Property Background() As String
            Get
                Return CType(Me("background"), String)
            End Get
            Set(ByVal value As String)
                Me("background") = value
            End Set
        End Property

        <ConfigurationProperty("foreground", DefaultValue:="000000", IsRequired:=True), _
         StringValidator(InvalidCharacters:="~!@#$%^&*()[]{}/;'\""|\\GHIJKLMNOPQRSTUVWXYZ", MinLength:=6, MaxLength:=6)> _
        Public Property Foreground() As String
            Get
                Return CType(Me("foreground"), String)
            End Get
            Set(ByVal value As String)
                Me("foreground") = value
            End Set
        End Property
    End Class
End Namespace
 

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 
someFileName.aspx 

<%@ Page Language="VB"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim config As Samples.AspNet.PageAppearanceSection = _
      CType(System.Configuration.ConfigurationManager.GetSection( _
        "pageAppearanceGroup/pageAppearance"),  _
      Samples.AspNet.PageAppearanceSection)

    Response.Write("<h2>Settings in the PageAppearance Section:</h2>")
    Response.Write("RemoteOnly: " _
                    + config.RemoteOnly.ToString() + "<br>")
    Response.Write("Font name and size: " _
                    + config.Font.Name + " " _
                    + config.Font.Size.ToString() + "<br>")
    Response.Write("Background and foreground color: " _
                    + config.Color.Background + " " _
                    + config.Color.Foreground + "<br>")
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Custom Configuration Section Example</title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <h1>
  </div>
  </form>
</body>
</html>


 

沒有留言:

張貼留言