permutations.cs
来自「ajax patterns 这是关于ajax设计模式方面的原代码」· CS 代码 · 共 85 行
CS
85 行
/*
Copyright 2006 Christian Gross http://www.devspace.com
From the book Ajax Patterns and Best Practices
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Text;
using System.Web;
using System.Runtime.Serialization;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Text.RegularExpressions;
using System.IO;
using Devspace.Commons.Tracer;
namespace Devspace.Ajax {
/// <summary>
/// ResourceFactory: Use a class to instantiate the IURLRewriter instance
/// as then you can change the implementation of how the instances are
/// retrieved. For example instead of instantiating, an object pool could be used
/// </summary>
public class ResourceFactory {
public static IURLRewriter[] CreateInstance( HttpApplication app) {
return new IURLRewriter[] {
new Permutations.ConfigurationRewrite( app),
new Permutations.SlashPeriodResource(new Permutations.SlashPeriodRewriter( app))
};
}
}
/// <summary>
/// PermutationsModule: Module used in an ASP.NET application to perform
/// a resource to representation mapping
/// </summary>
[Serializable]
public class PermutationsModule : IHttpModule {
public PermutationsModule() {
}
public void Init(HttpApplication context) {
GenerateOutput.Write( "PermutationsModule.Init", "Initialization");
context.PreRequestHandlerExecute +=
new EventHandler(context_PreRequestHandlerExecute);
}
private void context_PreRequestHandlerExecute(object sender, EventArgs e) {
GenerateOutput.Write( "PermutationsModule.context_PreRequestHandlerExecute",
">>>> Start");
HttpApplication app = (HttpApplication)sender;
IURLRewriter[] urlRewriters = ResourceFactory.CreateInstance( app);
foreach( IURLRewriter urlRewriter in urlRewriters) {
if( urlRewriter.IsResource( app.Context.Request)) {
GenerateOutput.Write( "PermutationsModule.context_PreRequestHandlerExecute",
"Is resource and URL will be rewritten");
urlRewriter.WriteRepresentation( app.Context.Request);
break;
}
else {
GenerateOutput.Write( "PermutationsModule.context_PreRequestHandlerExecute",
"Is not resource and URL will not be rewritten");
}
}
GenerateOutput.Write( "PermutationsModule.context_PreRequestHandlerExecute",
"<<<< End");
}
public void Dispose() {
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?