DBMNG数据库管理与应用

抓住自己最有兴趣的东西,由浅入深,循序渐进地学……
当前位置:首页 > 下载中心 > 软件下载

asp.net C# 微软官方URLRewriter例子

asp.net C# 微软官方URLRewriter例子-点击下载

Web.config文件配置URLRewriter示例:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <configSections>
	<!-- The <configSections> element must contain a <section> tag for the <RewriterConfig> section element.
			The type of the section handler is RewriterConfigSerializerSectionHandler, which is responsible for
			deserializing the <RewriterConfig> section element into a RewriterConfig instance... -->
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
  </configSections>

  <RewriterConfig>
	<Rules>
		<!-- Rules for Blog Content Displayer -->
		<RewriterRule>
			<LookFor>~/(\d{4})/(\d{2})/(\d{2})\.aspx</LookFor>
			<SendTo>~/ShowBlogContent.aspx?year=$1&amp;month=$2&amp;day=$3</SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/(\d{4})/(\d{2})/Default\.aspx</LookFor>
			<SendTo><![CDATA[~/ShowBlogContent.aspx?year=$1&month=$2]]></SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/(\d{4})/Default\.aspx</LookFor>
			<SendTo>~/ShowBlogContent.aspx?year=$1</SendTo>
		</RewriterRule>
		
	
		<!-- Rules for Product Lister -->
		<RewriterRule>
			<LookFor>~/Products/Default\.aspx</LookFor>
			<SendTo>~/ListCategories.aspx</SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/Products/Beverages\.aspx</LookFor>
			<SendTo>~/ListProductsByCategory.aspx?CategoryID=1</SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/Products/Condiments\.aspx</LookFor>
			<SendTo>~/ListProductsByCategory.aspx?CategoryID=2</SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/Products/Confections\.aspx</LookFor>
			<SendTo>~/ListProductsByCategory.aspx?CategoryID=3</SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/Products/Dairy\.aspx</LookFor>
			<SendTo>~/ListProductsByCategory.aspx?CategoryID=4</SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/Products/GrainsCereals\.aspx</LookFor>
			<SendTo>~/ListProductsByCategory.aspx?CategoryID=5</SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/Products/MeatPoultry\.aspx</LookFor>
			<SendTo>~/ListProductsByCategory.aspx?CategoryID=6</SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/Products/Produce\.aspx</LookFor>
			<SendTo>~/ListProductsByCategory.aspx?CategoryID=7</SendTo>
		</RewriterRule>
		<RewriterRule>
			<LookFor>~/Products/Seafood\.aspx</LookFor>
			<SendTo>~/ListProductsByCategory.aspx?CategoryID=8</SendTo>
		</RewriterRule>
	</Rules>
  </RewriterConfig>

  <system.web>
	<!--*******************************************************************************
	          Comment either the <httpModules> or <httpHandlers> section to use
			  URL rewriting...  Refer to the article for a discussion on the pros and
			  cons of each approach...
	    *******************************************************************************-->
	<httpModules>
		<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
	</httpModules>
	
	<!--<httpHandlers>
		<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
	</httpHandlers>-->
	<!--*******************************************************************************-->


    <!--  DYNAMIC DEBUG COMPILATION
          Set compilation debug="true" to enable ASPX debugging.  Otherwise, setting this value to
          false will improve runtime performance of this application. 
          Set compilation debug="true" to insert debugging symbols (.pdb information)
          into the compiled page. Because this creates a larger file that executes
          more slowly, you should set this value to true only when debugging and to
          false at all other times. For more information, refer to the documentation about
          debugging ASP.NET files.
    -->
    <compilation 
         defaultLanguage="c#"
         debug="true"
    />

    <!--  CUSTOM ERROR MESSAGES
          Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable. 
          Add <error> tags for each of the errors you want to handle.

          "On" Always display custom (friendly) messages.
          "Off" Always display detailed ASP.NET error information.
          "RemoteOnly" Display custom (friendly) messages only to users not running 
           on the local Web server. This setting is recommended for security purposes, so 
           that you do not display application detail information to remote clients.
    -->
    <customErrors 
    mode="RemoteOnly" 
    /> 

    <!--  AUTHENTICATION 
          This section sets the authentication policies of the application. Possible modes are "Windows", 
          "Forms", "Passport" and "None"

          "None" No authentication is performed. 
          "Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to 
           its settings for the application. Anonymous access must be disabled in IIS. 
          "Forms" You provide a custom form (Web page) for users to enter their credentials, and then 
           you authenticate them in your application. A user credential token is stored in a cookie.
          "Passport" Authentication is performed via a centralized authentication service provided
           by Microsoft that offers a single logon and core profile services for member sites.
    -->
    
    <!-- Forms authentication example -->
    <authentication mode="Forms">
		<forms name=".MYCOOKIE" loginUrl="Login.aspx" timeout="10"></forms>
    </authentication>
    
    <!-- Windows authentication example -->
    <!--<authentication mode="Windows" />-->
    
    

	<!--  AUTHORIZATION 
          This section sets the authorization policies of the application. You can allow or deny access
          to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous 
          (unauthenticated) users.
    -->

    <authorization>
		<!--<deny users="?" />--> <!-- For testing with forms authentication... -->
        <allow users="*" /> <!-- Allow all users -->
        
        
            <!--  <allow     users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
                  <deny      users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
            -->
    </authorization>

    <!--  APPLICATION-LEVEL TRACE LOGGING
          Application-level tracing enables trace log output for every page within an application. 
          Set trace enabled="true" to enable application trace logging.  If pageOutput="true", the
          trace information will be displayed at the bottom of each page.  Otherwise, you can view the 
          application trace log by browsing the "trace.axd" page from your web application
          root. 
    -->
    <trace
        enabled="true"
        requestLimit="10"
        pageOutput="false"
        traceMode="SortByTime"
		localOnly="true"
    />

    <!--  SESSION STATE SETTINGS
          By default ASP.NET uses cookies to identify which requests belong to a particular session. 
          If cookies are not available, a session can be tracked by adding a session identifier to the URL. 
          To disable cookies, set sessionState cookieless="true".
    -->
    <sessionState 
            mode="InProc"
            stateConnectionString="tcpip=127.0.0.1:42424"
            sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
            cookieless="false" 
            timeout="20" 
    />

    <!--  GLOBALIZATION
          This section sets the globalization settings of the application. 
    -->
    <globalization 
            requestEncoding="utf-8" 
            responseEncoding="utf-8" 
   />
 </system.web>

<!-- The following <location> elements can be used to test the effect of forms authentication
	when performing the URL rewriting at different stages in the lifecycle of the request... -->
<!--  
<location path="ListProductsByCategory.aspx">
	<system.web>
		<authorization>
			<deny users="?" />
		</authorization>
	</system.web>
</location>
-->
<!--
<location path="Products/Beverages.aspx">
	<system.web>
		<authorization>
			<deny users="?" />
		</authorization>
	</system.web>
</location>
-->


</configuration>

本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号