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


C# Route.GetVirtualPath方法代码示例

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


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

示例1: LinkTo

        public static string LinkTo(this UrlHelper urlHelper, Route route, RouteValueDictionary routeValues)
        {
            //TODO: remove code dupe see HtmlLinkToExtensions
            var requestCtx = urlHelper.RequestContext;
            var httpCtx = requestCtx.HttpContext;

            if (routeValues != null)
            {
                foreach (var d in route.Defaults)
                {
                    if (!routeValues.ContainsKey(d.Key))
                        routeValues.Add(d.Key, d.Value);
                }
            }
            else
            {
                routeValues = route.Defaults;
            }

            VirtualPathData vpd = route.GetVirtualPath(requestCtx, routeValues);
            if (vpd == null)
                return null;

            return httpCtx.Request.ApplicationPath + vpd.VirtualPath;

        }
开发者ID:goneale,项目名称:AppAir.Web,代码行数:26,代码来源:UrlLinkToExtensions.cs

示例2: GetRedirectHandler

        private static IHttpHandler GetRedirectHandler(RequestContext requestContext, string targetUrl, bool permanently)
        {
            string prefix = string.Empty;
            var slashPosition = targetUrl.IndexOf('/');
            if (slashPosition >= 0)
            {
                prefix = targetUrl.Substring(0, slashPosition + 1);
                targetUrl = targetUrl.Substring(slashPosition + 1);

            }
            var route = new Route(targetUrl, null);
            var virtualPathData = route.GetVirtualPath(requestContext, requestContext.RouteData.Values);
            if (virtualPathData != null)
            {
                targetUrl = prefix + virtualPathData.VirtualPath;
            }
            return new DelegateHttpHandler(httpContext => Redirect(httpContext, targetUrl, permanently), false);
        }
开发者ID:medvekoma,项目名称:portfotolio,代码行数:18,代码来源:RedirectRouteExtensions.cs

示例3: GetClientUrl

        public string GetClientUrl(string url, RouteValueDictionary values)
        {
            var site = _frontContext.Site;
            var subFolder = site.MatchedUrl.GetSubFolder();
            if (!String.IsNullOrWhiteSpace(subFolder))
            {
                url = subFolder + "/" + url;
            }

            var route = new Route(url, new MvcRouteHandler());
            var data = route.GetVirtualPath(HttpContext.Current.Request.RequestContext, values);
            if (data == null)
            {
                return "/";
            }

            return "/" + data.VirtualPath;
        }
开发者ID:wenbinke,项目名称:susucms,代码行数:18,代码来源:FrontUrlHelper.cs

示例4: GenerateTargetLocation

        private static string GenerateTargetLocation(this RequestContext context, string target, bool permanent)
        {
            if (target.StartsWith("~/", StringComparison.Ordinal))
            {
                Route route = new Route(target.Substring(2), null);
                var vpd = route.GetVirtualPath(context, context.RouteData.Values);
                if (vpd != null)
                    return string.Format(CultureInfo.InvariantCulture, "{0}/{1}", permanent ? string.Empty : "~", vpd.VirtualPath);
            }
            else if (target.StartsWith("/", StringComparison.Ordinal))
            {
                Route route = new Route(target.Substring(1), null);
                var vpd = route.GetVirtualPath(context, context.RouteData.Values);
                if (null != vpd)
                    return "/" + vpd.VirtualPath;
            }

            return target;
        }
开发者ID:Iristyle,项目名称:Authentic,代码行数:19,代码来源:RouteCollectionExtensions.cs

示例5: GenerateOutboundVirtualPath

        /// <summary>
        /// Generates an outbound url from the specified values.  
        /// </summary>
        /// <param name="routeValues">The route values from which to generate the url</param>
        /// <param name="route">The route to use to generate the url</param>
        /// <returns>The virtual path data object</returns>
        public static VirtualPathData GenerateOutboundVirtualPath(RouteValueDictionary routeValues, Route route)
        {
            HttpContextBase mockHttp = MockHelpers.HttpContext(null).Object;
            RequestContext context = new RequestContext(mockHttp, new RouteData());

            // Act (generate a URL)
            return route.GetVirtualPath(context, routeValues);
        }
开发者ID:triggerfish,项目名称:Common,代码行数:14,代码来源:OutboundRoutingHelpers.cs

示例6: GetVirtualPath2

		public void GetVirtualPath2 ()
		{
			var r = new Route ("{foo}/{bar}", null);
			var hc = new HttpContextStub ("~/x/y", String.Empty);
			var rd = r.GetRouteData (hc);
			var vp = r.GetVirtualPath (new RequestContext (hc, rd), null);
			Assert.IsNotNull (vp, "#1");
			Assert.AreEqual ("x/y", vp.VirtualPath, "#2");
			Assert.AreEqual (r, vp.Route, "#3");
			Assert.AreEqual (0, vp.DataTokens.Count, "#4");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:11,代码来源:RouteTest.cs

示例7: GetVirtualPath

		public void GetVirtualPath ()
		{
			var r = new Route ("foo/bar", null);
			var rd = new RouteData ();
			var vp = r.GetVirtualPath (new RequestContext (new HttpContextStub ("~/foo/bar"), rd), null);
			Assert.AreEqual ("foo/bar", vp.VirtualPath, "#1");
			Assert.AreEqual (r, vp.Route, "#2");

			vp = r.GetVirtualPath (new RequestContext (new HttpContextStub ("~/foo/bar/baz"), rd), null);
			Assert.AreEqual ("foo/bar", vp.VirtualPath, "#3");
			Assert.AreEqual (r, vp.Route, "#4");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:12,代码来源:RouteTest.cs

示例8: GetVirtualPathNullValues

		public void GetVirtualPathNullValues ()
		{
			// null values is allowed.
			var r = new Route (null, null);
			var rd = new RouteData ();
			var vp = r.GetVirtualPath (new RequestContext (new HttpContextStub (), rd), null);
			Assert.AreEqual (String.Empty, vp.VirtualPath, "#1");
			Assert.AreEqual (r, vp.Route, "#2");
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:9,代码来源:RouteTest.cs

示例9: GetVirtualPathNullContext

		public void GetVirtualPathNullContext ()
		{
			try {
				var r = new Route (null, null);
				r.GetVirtualPath (null, new RouteValueDictionary ());
			} catch (NullReferenceException) {
				// .NET lacks null arg check here. (No need to mimic silly behavior here.)
				throw new ArgumentNullException ();
			}
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:10,代码来源:RouteTest.cs

示例10: GetVirtualPath19

		public void GetVirtualPath19 ()
		{
			var context = new HttpContextWrapper (
				new HttpContext (new HttpRequest ("filename", "http://localhost/filename", String.Empty),
						 new HttpResponse (new StringWriter())
				)
			);
			var rc = new RequestContext (context, new RouteData ());

			var route = new Route ("HelloWorld", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary (new {controller = "Home", action = "HelloWorld"})
			};

			var lowercase = route.GetVirtualPath (rc, new RouteValueDictionary
			{
				{"controller", "home"},
				{"action", "helloworld"}
			});
			var standardCase = route.GetVirtualPath (rc, new RouteValueDictionary
			{
				{"controller", "Home"},
				{"action", "HelloWorld"}
			});
			var uppercase = route.GetVirtualPath (rc, new RouteValueDictionary
			{
				{"controller", "HOME"},
				{"action", "HELLOWORLD"}
			});

			Assert.IsNotNull(lowercase, "#A1");
			Assert.AreEqual ("HelloWorld", lowercase.VirtualPath, "#A2");

			Assert.IsNotNull(standardCase, "#A3");
			Assert.AreEqual ("HelloWorld", standardCase.VirtualPath, "#A4");

			Assert.IsNotNull(uppercase, "#A5");
			Assert.AreEqual ("HelloWorld", uppercase.VirtualPath, "#A6");
		}
开发者ID:rabink,项目名称:mono,代码行数:38,代码来源:RouteTest.cs

示例11: GetVirtualPath16

		public void GetVirtualPath16 ()
		{
			var context = new HttpContextWrapper (
				new HttpContext (new HttpRequest ("filename", "http://localhost/filename", String.Empty),
						 new HttpResponse (new StringWriter())
				)
			);
			var rc = new RequestContext (context, new RouteData ());

			var route = new Route ("Hello", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary (new {controller = "Home", action = "Hello", page = 1})
			};

			var routeValues = new RouteValueDictionary
			{
				{"controller", "Home"},
				{"action", "Hello"},
				{"page", 1}
			};

			var result = route.GetVirtualPath(rc, routeValues);
			Assert.IsNotNull(result, "#A1");
			Assert.AreEqual("Hello", result.VirtualPath, "#A2");
		}
开发者ID:rabink,项目名称:mono,代码行数:24,代码来源:RouteTest.cs

示例12: GetHttpHandler

        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            if (_redirectParams.RedirectTo.StartsWith("~/"))
              {
            string virtualPath = _redirectParams.RedirectTo.Substring(2);
            Route route = new Route(virtualPath, null);
            var vpd = route.GetVirtualPath(requestContext, requestContext.RouteData.Values);
            if (vpd != null)
            {
              _redirectParams.RedirectTo = "~/" + vpd.VirtualPath;
            }
              }

              return new RedirectHandler(_redirectParams, false);
        }
开发者ID:bbqchickenrobot,项目名称:XRouter,代码行数:15,代码来源:RedirectRoute.cs


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