Пример #1
0
        /// <summary>
        /// Route the request.
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <returns><see cref="ModuleResult.Stop"/> will stop all processing including <see cref="IHttpModule.EndRequest"/>.</returns>
        /// <remarks>Simply change the request URI to something else.</remarks>
        public ModuleResult Route(IHttpContext context)
        {
            MatchResult results = _routes.Match(context);

            if (results != null)
            {
                if (results.MatchStatus.Success)
                {
                    DefaultRoute defaultRoute = results.MappedRoute.defaults;

                    string path = String.Empty;

                    if (!StringUtility.IsNullOrEmpty(defaultRoute.controller))
                    {
                        path += string.Concat("/", defaultRoute.controller);
                    }

                    if (!StringUtility.IsNullOrEmpty(defaultRoute.action))
                    {
                        path += string.Concat("/", defaultRoute.action);
                    }

                    if (!StringUtility.IsNullOrEmpty(defaultRoute.id))
                    {
                        path += string.Concat("?id=", defaultRoute.id);
                    }

                    if (StringUtility.IsNullOrEmpty(path))
                    {
                        path = context.Request.Uri.AbsolutePath;
                    }

                    Uri    url  = context.Request.Uri;
                    string port = string.Empty;

                    if (url.Port != 80)
                    {
                        port = string.Concat(";", url.Port);
                    }

                    context.Request.UriRewrite = new Uri(
                        string.Concat(url.Scheme, "://", url.Host, port, path));
                }
                return(ModuleResult.Continue);
            }

            context.Response.StatusCode        = 403;
            context.Response.StatusDescription = "Forbidden";
            return(ModuleResult.Stop);
        }