Пример #1
0
		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="engine">The rewriting engine.</param>
		/// <param name="rawUrl">The initial, raw URL.</param>
		/// <param name="httpMethod">The HTTP method used (GET, POST, ...)</param>
		/// <param name="mapPath">The method to use for mapping paths.</param>
		/// <param name="serverVariables">Collection of server variables.</param>
		/// <param name="headers">Collection of headers.</param>
		/// <param name="cookies">Collection of cookies.</param>
		internal RewriteContext(RewriterEngine engine,
			string rawUrl, string httpMethod,
			MapPath mapPath,
			NameValueCollection serverVariables,
			NameValueCollection headers,
			HttpCookieCollection cookies)
		{
			_engine = engine;
			_location = rawUrl;
			_method = httpMethod;
			_mapPath = mapPath;

			foreach (string key in serverVariables)
			{
				_properties.Add(key, serverVariables[key]);
			}

			foreach (string key in headers)
			{
				_properties.Add(key, headers[key]);
			}

			foreach (string key in cookies)
			{
				_properties.Add(key, cookies[key].Value);
			}
		}
 public void SetUp()
 {
     XmlDocument doc = new XmlDocument();
     doc.LoadXml(Rules);
     context = new ContextFacadeStub();
     rewriter = new RewriterEngine(context, RewriterConfiguration.LoadFromNode(doc.SelectSingleNode("rewriter")));
 }
Пример #3
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="engine">The rewriting engine.</param>
        /// <param name="rawUrl">The initial, raw URL.</param>
        /// <param name="httpMethod">The HTTP method used (GET, POST, ...)</param>
        /// <param name="mapPath">The method to use for mapping paths.</param>
        /// <param name="serverVariables">Collection of server variables.</param>
        /// <param name="headers">Collection of headers.</param>
        /// <param name="cookies">Collection of cookies.</param>
        internal RewriteContext(RewriterEngine engine,
                                string rawUrl, string httpMethod,
                                MapPath mapPath,
                                NameValueCollection serverVariables,
                                NameValueCollection headers,
                                HttpCookieCollection cookies)
        {
            _engine   = engine;
            _location = rawUrl;
            _method   = httpMethod;
            _mapPath  = mapPath;

            foreach (string key in serverVariables)
            {
                _properties.Add(key, serverVariables[key]);
            }

            foreach (string key in headers)
            {
                _properties.Add(key, headers[key]);
            }

            foreach (string key in cookies)
            {
                _properties.Add(key, cookies[key].Value);
            }
        }
Пример #4
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="engine">The rewriting engine.</param>
        /// <param name="rawUrl">The initial, raw URL.</param>
        /// <param name="httpContext">The HTTP context facade.</param>
        /// <param name="configurationManager">The configuration manager facade.</param>
        internal RewriteContext(
            RewriterEngine engine,
            string rawUrl,
            IHttpContext httpContext,
            IConfigurationManager configurationManager)
        {
            if (engine == null)
            {
                throw new ArgumentNullException("engine");
            }
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            if (configurationManager == null)
            {
                throw new ArgumentNullException("configurationManager");
            }

            _engine = engine;
            _configurationManager = configurationManager;
            _location = rawUrl;
            _method = httpContext.HttpMethod;
            _mapPath = httpContext.MapPath;

            // Initialise the Properties collection from all the server variables, headers and cookies.
            foreach (string key in httpContext.ServerVariables.AllKeys)
            {
                _properties.Add(key, httpContext.ServerVariables[key]);
            }
            foreach (string key in httpContext.RequestHeaders.AllKeys)
            {
                _properties.Add(key, httpContext.RequestHeaders[key]);
            }
            foreach (string key in httpContext.RequestCookies.AllKeys)
            {
                _properties.Add(key, httpContext.RequestCookies[key].Value);
            }
        }
Пример #5
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="engine">The rewriting engine.</param>
        /// <param name="rawUrl">The initial, raw URL.</param>
        /// <param name="httpContext">The HTTP context facade.</param>
        /// <param name="configurationManager">The configuration manager facade.</param>
        internal RewriteContext(
            RewriterEngine engine,
            string rawUrl,
            IHttpContext httpContext,
            IConfigurationManager configurationManager)
        {
            if (engine == null)
            {
                throw new ArgumentNullException("engine");
            }
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            if (configurationManager == null)
            {
                throw new ArgumentNullException("configurationManager");
            }

            _engine = engine;
            _configurationManager = configurationManager;
            _location             = rawUrl;
            _method  = httpContext.HttpMethod;
            _mapPath = httpContext.MapPath;

            // Initialise the Properties collection from all the server variables, headers and cookies.
            foreach (string key in httpContext.ServerVariables.AllKeys)
            {
                _properties.Add(key, httpContext.ServerVariables[key]);
            }
            foreach (string key in httpContext.RequestHeaders.AllKeys)
            {
                _properties.Add(key, httpContext.RequestHeaders[key]);
            }
            foreach (string key in httpContext.RequestCookies.AllKeys)
            {
                _properties.Add(key, httpContext.RequestCookies[key].Value);
            }
        }
Пример #6
0
        public void SetUp()
        {
            string rawXml = @"
            <rewriter>
            <register logger='Rewrite.Test.Log4NetRewriteLogger, Rewrite.Test' />

            <!-- our library -->
            <rewrite url='/Library/(.+)' to='~/Portal/GetLibraryFile.aspx?Path=$1' />

            <!-- once the library files have been dealt with, ignore these files: -->
            <rewrite url='^(/.+(\.gif|\.png|\.jpg|\.ico|\.pdf|\.css|\.js)(\?.+)?)$' to='$1' processing='stop' />

            <!-- the 'sample' site -->
            <rewrite url='/sample/(.+)' to='~/Portal/GetPortalPage.aspx?Requested=Sample/$1' />

            <!-- client site -->
            <rewrite url='/site/(.+)' to='~/Portal/DisplayPortalPage.aspx?Requested=site/$1' />

            <!-- index page rewritten -->
            <rewrite url='/index.aspx' to='~/Portal/DisplayPortalPage.aspx?Requested=site/index.aspx' />

            <!-- handles default page request (should redirect to index.aspx, then reprocess) -->
            <rewrite url='^(.*)/(\?.+)?$' to='$1/index.aspx$2?' processing='restart' />
            </rewriter>
            ";

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(rawXml);
            //redirInstance = new UrlRedirection(doc, DebugLogEnabled);
            context = new ContextFacadeStub();
            rewriter = new RewriterEngine(context, RewriterConfiguration.LoadFromNode(doc.SelectSingleNode("rewriter")));
        }