AD

url static mapping and back treatment

URL rewriting is the intercept incoming Web request and automatically redirect the request to another URL in the process.

For example: the browser sent a request **localhost:90/URLRewriter/1.html,

This request, the server automatically directed to **localhost:90/URLRewriter/url.aspx?id=1

URLRewriter download compiled to extract the URLRewriter.dll and ActionlessForm.dll

1, URL rewriting

Project Reference URLRewriter.dll

web.config configuration:

Code
<? Xml version = "1.0"?>
<configuration xmlns="**schemas.microsoft**/.NetConfiguration/v2.0">
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</ ConfigSections>

<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor> ~ / URLRewriter / (. [0-9] *) \. Html </ LookFor>
<SendTo> ~ / URLRewriter / url.aspx? Id = $ 1 </ SendTo>
</ RewriterRule>
<RewriterRule>
<LookFor> ~ / Web </ LookFor>
<SendTo> ~ / URLRewriter / url.aspx </ SendTo>
</ RewriterRule>
</ Rules>
</ RewriterConfig>

<system.web>
<httpHandlers>
<! - URLRewriter begin using the HTTP handler for rewriting ->
<!--< Add verb = "*" path = "*. aspx" type = "URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /> ->
<! - URLRewriter end ->
</ HttpHandlers>

<httpModules>
<! - URLRewriter begin using the HTTP module implementation of rewriting ->
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
<! - URLRewriter end ->
</ HttpModules>
</ System.web>

</ Configuration>
IIS configuration:

Web site - Properties - Home Directory - Configuration - Insert - C: \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ aspnet_isapi.dll

Untick the file exists

Second, handling PostBack back

ActionlessForm.dll to rewrite the way to handle Form PostBack URL back into the original address after

Projects registered in the page reference ActionlessForm.dll about

<% @ Register TagPrefix = "skm" Namespace = "ActionlessForm" Assembly = "ActionlessForm"%>

The page <form runat="server"> </ form> Replace: <skm:form runat="server"> </ skm: form>

Note: in this manner will be back in the designer view for the error when the Form is not available

Therefore, the following approach:

Microsoft's URLRewriter add the following class after class library compiled

Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/ / / <summary>
/ / / FormRewriter's summary
/ / / </ Summary>
namespace URLRewriter.Form
(
public class FormRewriterControlAdapter: System.Web.UI.Adapters.ControlAdapter
(
public FormRewriterControlAdapter ()
(
)

protected override void Render (HtmlTextWriter writer)
(
base.Render (new RewriteFormHtmlTextWriter (writer));
)
)

public class RewriteFormHtmlTextWriter: HtmlTextWriter
(
public RewriteFormHtmlTextWriter (HtmlTextWriter writer)
: Base (writer)
(
base.InnerWriter = writer.InnerWriter;
)
public RewriteFormHtmlTextWriter (System.IO.TextWriter writer)
: Base (writer)
(
base.InnerWriter = writer;
)

public override void WriteAttribute (string name, string value, bool fEncode)
(
/ / If the attribute we are writing is the "action" attribute, and we are not on a sub-control,
/ / Then replace the value to write with the raw URL of the request - which ensures that we'll
/ / Preserve the PathInfo value on postback scenarios
if (name == "action")
(
HttpContext context = HttpContext.Current;
if (context.Items ["ActionAlreadyWritten"] == null)
(
/ / We will use the Request.RawUrl property within ASP.NET to retrieve the origional
/ / URL before it was re-written.
value = context.Request.RawUrl;
/ / Indicate that we've already rewritten the <form> 's action attribute to prevent
/ / Us from rewriting a sub-control under the <form> control
context.Items ["ActionAlreadyWritten"] = true;
)
)
base.WriteAttribute (name, value, fEncode);
)
)

)
Folder created in App_Browsers Form.browser

Code
<browsers>
<browser refID="Default">
<controlAdapters>
<Adapter controlType = "System.Web.UI.HtmlControls.HtmlForm"
adapterType = "URLRewriter.Form.FormRewriterControlAdapter" />
</ ControlAdapters>
</ Browser>
</ Browsers>
This does not need to be changed without reference to ActionlessForm.dll Form, and as long as the reference URLRewriter.dll on it

Third, when dealing with re-written html original site in the html page will not be used

Use these methods to find the problem would not exist

If still does not work you can add a node in the <compilation debug="true">

<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider" />
</ BuildProviders>

Add in <httpHandlers> node (if used prior to the implementation of rewriting http handler, please EDITORIAL)

<add path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true"/>
标签: implementation, code lt, lt xml, localhost, aspx, gt web, microsoft, home directory, dll, web request, lt system, system web, intercept, project reference, static mapping, sendto, lookfor
分类: DotNet
时间: 2010-08-06

相关文章

  1. The URL path mapping Servlet

    Java programmers are required to be more under the premise of the framework of technology, of course, on the p ...
  2. Static Host Mapping on Windows

    DNS Static mapping redirect the host name to the specific IP address without querying from the DNS. It is very ...
  3. apache rewrite the URL in Substitution | RewriteRule directive

    Rewrite the rules of the Substitution Pattern when match the original URL and when used as a substitute (or re ...
  4. spring 3.0 Application springmvc elaborate structure RESTful URL

    springmvc 3.0 RESTful URL function added to construct a similar javaeye current URL. rest introduction, here a ...
  5. jsp static and pseudo-static

    Let me talk about why static. For the current Web Application, the dynamic page is an absolute high-status, pr ...
  6. Url address to use to achieve URLRewrite pseudo-static

    1.1URLRewirte the usefulness of 1. To meet the requirements of search engines. 2. Hide the technology to impro ...
  7. Baidu reptiles buttoned dynamic url

    In the previous "URL static knot" in the discrimination I Baidu is the dynamic URL in malls, in the ...
  8. php获取当前网址url并替换参数或网址的方法

    今天在项目中用到的两个函数,自己写了下,备用,需要的朋友也可以直接使用了,推荐第一个函数为获取,后面为相关的处理参数. 一是PHP获取当前页面的网址: //获得当前的脚本网址 function GetCurUrl() { ...
  9. Struts2 framework security flaws

    Abstract This article describes the development of popular java framework for struts2, and webwork some of the ...
  10. Content Distribution Network (CDN) technology

    Abstract: As broadband networks and the rise of broadband streaming media applications, CDN, as a way to impro ...
  11. Apache httpd.conf Xiangjie

    Apache server configuration file located in / usr / local / apache / conf / directory, the traditional use of ...
  12. Load balancing algorithm describes the principles and (to)

    A lot of server load balancing algorithm (continuous and non-persistent), including round robin algorithm, the ...
  13. linux configure apache + mongrel_cluster + mongrel

    Operating System: Red Hat Enterprise Linux 5 (1) First of all, we install ruby http://www.ruby-lang.org/zh_CN/ ...
  14. Servlet / JSP Detailed configuration (basic article)

    Beginners question such as: "How to configure the environment variable" "How to run Servlet&quo ...
  15. Struts projects will be moved to Struts2 (b)

    <! - StartFragment -> Please Fuzheng heroes Migrating to Struts 2 - Part II In the first part of this se ...
  16. My first experience Grails

    Agile development has been carrying out in full swing up in the industry, she gave the traditional model of so ...
  17. Use Spring 2.5 annotation driven Spring MVC-based

    http://www.uml.org.cn/j2ee/200907163.asp # N10059 This article includes: Outline A simple annotation-based Con ...
  18. Spring 2.5 annotation based Spring MVC

    A simple annotation-based Controller Low version of the Spring MVC to use the readers to know: When you create ...
  19. [Reprinted] Spring 2.5 annotation-driven Spring MVC-based

    Following an overview of Spring MVC Spring 2.0 On major upgrade, Spring 2.5 has introduced for the Spring MVC ...