当前位置: 首页>>代码示例>>C#>>正文


C# HttpContext.RewritePath方法代码示例

本文整理汇总了C#中System.Web.HttpContext.RewritePath方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContext.RewritePath方法的具体用法?C# HttpContext.RewritePath怎么用?C# HttpContext.RewritePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpContext的用法示例。


在下文中一共展示了HttpContext.RewritePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleRequest

        /// <summary>
        /// Handles the current request.
        /// </summary>
        /// <param name="context">The current context</param>
        /// <param name="draft">Weather to view the draft</param>
        /// <param name="args">Optional url arguments passed to the handler</param>
        protected virtual void HandleRequest(HttpContext context, bool draft, params string[] args)
        {
            if (args != null && args.Length > 0) {
                Permalink perm = Permalink.GetByName(args[0]) ;

                if (perm != null) {
                    if (perm.Type == Permalink.PermalinkType.PAGE) {
                        Page page = Page.GetSingle(perm.ParentId, draft) ;

                        if (!String.IsNullOrEmpty(page.Controller)) {
                            context.RewritePath("~/templates/" + page.Controller + "/" + perm.Name +
                                (draft ? "?draft=true" : ""), false) ;
                        } else {
                            context.RewritePath("~/page/" + perm.Name + (draft ? "?draft=true" : "")) ;
                        }
                    } else {
                        context.RewritePath("~/post/" + perm.Name + (draft ? "?draft=true" : "")) ;
                    }
                }
            } else {
                //
                // Rewrite to current startpage
                //
                Page page = Page.GetStartpage() ;

                if (!String.IsNullOrEmpty(page.Controller))
                    context.RewritePath("~/templates/" + page.Controller, false) ;
                else context.RewritePath("~/page") ;
            }
        }
开发者ID:NJepop,项目名称:Piranha,代码行数:36,代码来源:PermalinkHandler.cs

示例2: HandleStartpage

		/// <summary>
		/// Handles requests to the current startpage
		/// </summary>
		/// <param name="context">The current http context</param>
		public void HandleStartpage(HttpContext context) {
			var page = Page.GetStartpage();

			if (!String.IsNullOrEmpty(page.Controller))
				context.RewritePath("~/" + page.Controller + "?permalink=" + page.Permalink + FormatQuerystring(context), false);
			else context.RewritePath("~/page?permalink=" + page.Permalink + FormatQuerystring(context), false);
		}
开发者ID:284247028,项目名称:Piranha,代码行数:11,代码来源:RouteHandler.cs

示例3: HandlePage

		/// <summary>
		/// Handles requests to the given page.
		/// </summary>
		/// <param name="context">The current http context</param>
		/// <param name="permalink">The permalink</param>
		/// <param name="page">The page</param>
		/// <param name="args">Optional route arguments</param>
		public void HandlePage(HttpContext context, Permalink permalink, Page page, params string[] args) {
			if (!String.IsNullOrEmpty(page.Controller)) {
				context.RewritePath("~/" + page.Controller + "/" + args.Implode("/") + "?permalink=" + permalink.Name +
					(page.IsDraft ? "&draft=true" : "") + FormatQuerystring(context), false);
			} else {
				context.RewritePath("~/page/" + args.Implode("/") + "?permalink=" + permalink.Name +
					(page.IsDraft ? "&draft=true" : "") + FormatQuerystring(context), false);
			}
		}
开发者ID:284247028,项目名称:Piranha,代码行数:16,代码来源:RouteHandler.cs

示例4: RewriteUrl

        /// <summary>
        /// Rewrite's a URL using <b>HttpContext.RewriteUrl()</b>.
        /// </summary>
        /// <param name="context">The HttpContext object to rewrite the URL to.</param>
        /// <param name="sendToUrl">The URL to rewrite to.</param>
        /// <param name="sendToUrlLessQString">Returns the value of sendToUrl stripped of the querystring.</param>
        /// <param name="filePath">Returns the physical file path to the requested page.</param>
        internal static void RewriteUrl(HttpContext context, string sendToUrl, out string sendToUrlLessQString, out string filePath)
        {
            // see if we need to add any extra querystring information
            if (context.Request.QueryString.Count > 0)
            {
                if (sendToUrl.IndexOf('?') != -1)
                    sendToUrl += "&" + context.Request.QueryString.ToString();
                else
                    sendToUrl += "?" + context.Request.QueryString.ToString();
            }

            // first strip the querystring, if any
            string queryString = String.Empty;
            sendToUrlLessQString = sendToUrl;
            if (sendToUrl.IndexOf('?') > 0)
            {
                sendToUrlLessQString = sendToUrl.Substring(0, sendToUrl.IndexOf('?'));
                queryString = sendToUrl.Substring(sendToUrl.IndexOf('?') + 1);
            }

            // grab the file's physical path
            filePath = string.Empty;
            filePath = context.Server.MapPath(sendToUrlLessQString);

            // rewrite the path...
            context.RewritePath(sendToUrlLessQString, String.Empty, queryString);

            // NOTE!  The above RewritePath() overload is only supported in the .NET Framework 1.1
            // If you are using .NET Framework 1.0, use the below form instead:
            // context.RewritePath(sendToUrl);
        }
开发者ID:aNd1coder,项目名称:Wojoz,代码行数:38,代码来源:RewriterUtils.cs

示例5: RewritePost

        /// <summary>
        /// Rewrites the post.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="url">The URL string.</param>
        public static void RewritePost(HttpContext context, string url)
        {
            int year, month, day;

            var haveDate = ExtractDate(context, out year, out month, out day);
            var slug = ExtractTitle(context, url);

            // Allow for Year/Month only dates in URL (in this case, day == 0), as well as Year/Month/Day dates.
            // first make sure the Year and Month match.
            // if a day is also available, make sure the Day matches.
            var post = Post.ApplicablePosts.Find(
                p =>
                (!haveDate || (p.DateCreated.Year == year && p.DateCreated.Month == month)) &&
                ((!haveDate || (day == 0 || p.DateCreated.Day == day)) &&
                 slug.Equals(Utils.RemoveIllegalCharacters(p.Slug), StringComparison.OrdinalIgnoreCase)));

            if (post == null)
            {
                return;
            }

            var q = GetQueryString(context);
            if (q.Contains("id=" + post.Id, StringComparison.OrdinalIgnoreCase))
                q = string.Format("{0}post.aspx?{1}", Utils.ApplicationRelativeWebRoot, q);
            else
                q = string.Format("{0}post.aspx?id={1}{2}", Utils.ApplicationRelativeWebRoot, post.Id, q);

            context.RewritePath(
                url.Contains("/FEED/")
                    ? string.Format("syndication.axd?post={0}{1}", post.Id, GetQueryString(context))
                    : q,
                false);
        }
开发者ID:mukhtiarlander,项目名称:git_demo_torit,代码行数:38,代码来源:UrlRules.cs

示例6: ProcessRequest

 public void ProcessRequest(HttpContext context)
 {
     HttpRequest req=context.Request;
     HttpResponse res=context.Response;
     string path = req.Path;
     if(Path.GetExtension(path)==".aspx") context.RewritePath(path.Replace("/RAGS/","/"));
 }
开发者ID:rags,项目名称:playground,代码行数:7,代码来源:URLHandler.cs

示例7: getPathTranslatedFromSiteGeneratorGUI

        IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            IHttpHandler handler = null;

            if (context.Request.QueryString != null)
                pathTranslated = getPathTranslatedFromSiteGeneratorGUI(url, pathTranslated);
            // check if it is an .aspx page
            if (".aspx" == Path.GetExtension(pathTranslated))
            {
                context.RewritePath(url, url, context.Request.QueryString.ToString());
                handler = PageParser.GetCompiledPageInstance(url, pathTranslated, context);
            }
            else if (".asmx" == Path.GetExtension(pathTranslated).ToLower())
            {
                WebServiceHandlerFactory wshf = new WebServiceHandlerFactory();
                handler = wshf.GetHandler(context, requestType, url, pathTranslated);
            }
            else
            {
                ProcessStaticContent(pathTranslated);      // Process page and
                HttpContext.Current.Response.End();     //  end here
            }

            return handler;
        }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:25,代码来源:SiteGenerator_IIS_HttpHandler.cs

示例8: HandleAjax

        private static void HandleAjax(HttpContext context)
        {
            int dotasmx = context.Request.Path.IndexOf(".asmx");
            string path = context.Request.Path.Substring(0, dotasmx + 5);

            string pathInfo = context.Request.Path.Substring(dotasmx + 5);

            context.RewritePath(path, pathInfo, context.Request.Url.Query);
        }
开发者ID:mograviral,项目名称:MySample,代码行数:9,代码来源:Global.asax.cs

示例9: SendImageToHttpResponse

        public override void SendImageToHttpResponse(HttpContext context, string cacheKey, string fileExtension)
        {
            // Instead of sending image directly to the response, just call RewritePath and let IIS
            // handle the actual serving of the image.
            string filePath = GetDiskCacheFilePath(context, cacheKey, fileExtension);

            context.Items["FinalCachedFile"] = context.Server.MapPath(filePath);

            context.RewritePath(filePath, false);
        }
开发者ID:pacificIT,项目名称:dynamic-image,代码行数:10,代码来源:DiskCacheProviderBase.cs

示例10: CondRewrite

        public void CondRewrite(HttpContext ctx)
        {
            if ( RewriteNeeded ) {
                Common.Log("ModCaseInsensitive: rewritting [ '{0}' -> '{1}' ]",
                    ctx.Request.RawUrl,
                    Url + PathInfo + QueryString
                );

                if ( PathInfo == String.Empty ) {
                    ctx.RewritePath( Url + QueryString );
                }
                else {
                    ctx.RewritePath( Url, PathInfo, QueryString );
                }
            }
            else {
                Common.Log("ModCaseInsensitive: not rewritting [ '{0}' ]", ctx.Request.RawUrl);
            }
        }
开发者ID:PowerMeMobile,项目名称:mod_caseinsensitive,代码行数:19,代码来源:RoutingDecision.cs

示例11: Rewrite

        /// <summary>
        /// Rewrites the specified HTTP context.
        /// </summary>
        /// <param name="httpContext">The HTTP context.</param>
        public void Rewrite(HttpContext httpContext)
        {
            if (httpContext != null)
            {
                string outputUri = null;

                if (RewriteToUri(httpContext.Request.RawUrl, out outputUri))
                {
                    httpContext.RewritePath(outputUri);
                }
            }
        }
开发者ID:rynnwang,项目名称:CommonSolution,代码行数:16,代码来源:UriRewriter.cs

示例12: RewriteCategory

 private static void RewriteCategory(HttpContext context)
 {
     string title = ExtractTitle(context);
       foreach (Category cat in Category.Categories)
       {
     string legalTitle = SupportUtilities.RemoveIllegalCharacters(cat.Title).ToLowerInvariant();
     if (title.Equals(legalTitle, StringComparison.OrdinalIgnoreCase))
     {
       context.RewritePath(SupportUtilities.RelativeWebRoot + "Default.aspx?id=" + cat.Id.ToString() + GetQueryString(context), false);
       break;
     }
       }
 }
开发者ID:chandru9279,项目名称:StarBase,代码行数:13,代码来源:UrlRewrite.cs

示例13: RewriteUrl

        internal static void RewriteUrl(HttpContext context, string sendToUrl)
        {
            //first strip the querystring, if any
            var queryString = string.Empty;
            string sendToUrlLessQString = sendToUrl;
            if ((sendToUrl.IndexOf("?", StringComparison.Ordinal) > 0))
            {
                sendToUrlLessQString = sendToUrl.Substring(0, sendToUrl.IndexOf("?", StringComparison.Ordinal));
                queryString = sendToUrl.Substring(sendToUrl.IndexOf("?", StringComparison.Ordinal) + 1);
            }
			
            //rewrite the path..
            context.RewritePath(sendToUrlLessQString, string.Empty, queryString);
            //NOTE!  The above RewritePath() overload is only supported in the .NET Framework 1.1
            //If you are using .NET Framework 1.0, use the below form instead:
            //context.RewritePath(sendToUrl);
        }
开发者ID:rut5949,项目名称:Dnn.Platform,代码行数:17,代码来源:RewriterUtils.cs

示例14: RewriteUrl

        /// <summary>
        /// Rewrite's a URL using <b>HttpContext.RewriteUrl()</b>.
        /// </summary>
        /// <param name="context">The HttpContext object to rewrite the URL to.</param>
        /// <param name="sendToUrl">The URL to rewrite to.</param>
        /// <param name="sendToUrlLessQString">Returns the value of sendToUrl stripped of the querystring.</param>
        /// <param name="filePath">Returns the physical file path to the requested page.</param>
        internal static void RewriteUrl(HttpContext context, string sendToUrl, out string sendToUrlLessQString, out string filePath)
        {
            if (context.Request.QueryString.Count > 0)
                if (sendToUrl.IndexOf('?') != -1)
                    sendToUrl += "&" + context.Request.QueryString.ToString();
                else
                    sendToUrl += "?" + context.Request.QueryString.ToString();

            string queryString = String.Empty;
            sendToUrlLessQString = sendToUrl;
            if (sendToUrl.IndexOf('?') > 0) {
                sendToUrlLessQString = sendToUrl.Substring(0, sendToUrl.IndexOf('?'));
                queryString = sendToUrl.Substring(sendToUrl.IndexOf('?') + 1);
            }

            filePath = context.Server.MapPath(sendToUrlLessQString);
            context.RewritePath(sendToUrlLessQString, String.Empty, queryString);
        }
开发者ID:kailuowang,项目名称:MindLib,代码行数:25,代码来源:RewriterUtils.cs

示例15: UrlMappingRewritePath

        internal static void UrlMappingRewritePath(HttpContext context) {
            HttpRequest request = context.Request;
            UrlMappingsSection urlMappings = RuntimeConfig.GetAppConfig().UrlMappings;
            string path = request.Path;
            string mappedUrl = null;

            // First check path with query string (for legacy reasons)
            string qs = request.QueryStringText;
            if (!String.IsNullOrEmpty(qs)) {
                mappedUrl = urlMappings.HttpResolveMapping(path + "?" + qs);
            }

            // Check Path if not found
            if (mappedUrl == null)
                mappedUrl = urlMappings.HttpResolveMapping(path);

            if (!String.IsNullOrEmpty(mappedUrl))
                context.RewritePath(mappedUrl, false);
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:19,代码来源:UrlMappingsModule.cs


注:本文中的System.Web.HttpContext.RewritePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。