• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Routing.RouteData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



RouteData类属于System.Web.Routing命名空间,在下文中一共展示了RouteData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: given_controller

        public given_controller()
        {
            this.bus = Mock.Of<ICommandBus>();
            this.conferenceDao = Mock.Of<IConferenceDao>(x => x.GetConferenceAlias(conferenceAlias.Code) == conferenceAlias);
            this.orderDao = Mock.Of<IOrderDao>();

            this.routes = new RouteCollection();

            this.routeData = new RouteData();
            this.routeData.Values.Add("conferenceCode", conferenceAlias.Code);

            var requestMock = new Mock<HttpRequestBase>(MockBehavior.Strict);
            requestMock.SetupGet(x => x.ApplicationPath).Returns("/");
            requestMock.SetupGet(x => x.Url).Returns(new Uri("http://localhost/request", UriKind.Absolute));
            requestMock.SetupGet(x => x.ServerVariables).Returns(new NameValueCollection());

            var responseMock = new Mock<HttpResponseBase>(MockBehavior.Strict);
            responseMock.Setup(x => x.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(s => s);

            var context = Mock.Of<HttpContextBase>(c => c.Request == requestMock.Object && c.Response == responseMock.Object);

            this.sut = new RegistrationController(this.bus, this.orderDao, this.conferenceDao);
            this.sut.ConferenceAlias = conferenceAlias;
            this.sut.ConferenceCode = conferenceAlias.Code;
            this.sut.ControllerContext = new ControllerContext(context, this.routeData, this.sut);
            this.sut.Url = new UrlHelper(new RequestContext(context, this.routeData), this.routes);
        }
开发者ID:wayne-o,项目名称:delete-me,代码行数:27,代码来源:RegistrationControllerFixture.cs


示例2: GetBySlug

 /// <summary>
 /// You can take this information from cache or table from database as you like
 /// </summary>
 /// <param name="slug"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 private string GetBySlug(string slug , RouteData data)
 {
     // you can take it from cache or sql table every ID and it's value for URL
     if (slug == "Eng-Mohamad-Alsaid")
     {
         data.Values["SeName"] = slug;
         data.Values["controller"] = "Engineers";
         data.Values["action"] = "EngineerDetails";
         data.Values["Engineerid"] = 1;
         return "OK";
     }
     else if (slug == "Syria")
     {
         data.Values["SeCountry"] = slug;
         data.Values["controller"] = "Engineers";
         data.Values["action"] = "EngineerDetails";
         data.Values["Engineerid"] = 2;
         return "OK";
     }
     else if (slug == "0090538972117")
     {
         data.Values["SeMobile"] = slug;
         data.Values["controller"] = "Engineers";
         data.Values["action"] = "EngineerDetails";
         data.Values["Engineerid"] = 3;
         return "OK";
     }
     else
          return null;
 }
开发者ID:mosaeedesraa,项目名称:MVC-SEO-ROUTES,代码行数:36,代码来源:GenericPathRoute.cs


示例3: TestIncomingRouteResult

        private bool TestIncomingRouteResult(RouteData routeResult, string controller, string action, object propertySet = null)
        {
            Func<object, object, bool> valCompare = (v1, v2) =>
            {
                return StringComparer.InvariantCultureIgnoreCase.Compare(v1, v2) == 0;
            };

            bool result = valCompare(routeResult.Values["controller"], controller) &&
                          valCompare(routeResult.Values["action"], action);

            if (propertySet != null)
            {
                PropertyInfo[] propInfo = propertySet.GetType().GetProperties();

                foreach (var pi in propInfo)
                {
                    if (!(routeResult.Values.ContainsKey(pi.Name) &&
                          valCompare(routeResult.Values[pi.Name], pi.GetValue(propertySet, null))))
                    {
                        result = false;
                        break;
                    }
                }
            }

            return result;
        }
开发者ID:Kazempour,项目名称:mvc,代码行数:27,代码来源:RouteTests.cs


示例4: RedirectToErrorPage

        private void RedirectToErrorPage(Exception ex)
        {
            var httpException = ex as HttpException;

            var routeData = new RouteData();
            routeData.Values["controller"] = "Errors";
            routeData.Values["action"] = "General";
            routeData.Values["exception"] = httpException;

            //Production: Handle any specific Http errors with custom views

            //Response.StatusCode = 500;

            //if (httpException != null)
            //{
            //    Response.StatusCode = httpException.GetHttpCode();
            //    switch (Response.StatusCode)
            //    {
            //        case 403:
            //            routeData.Values["action"] = "Http403";
            //            break;
            //        case 404:
            //            routeData.Values["action"] = "Http404";
            //            break;
            //    }
            //}

            using (var scope = AutofacConfig.Container.BeginLifetimeScope())
            {
                var uiService = scope.Resolve<IUiService>();
                IController errorsController = new ErrorsController(uiService);
                var requestContext = new RequestContext(new HttpContextWrapper(Context), routeData);
                errorsController.Execute(requestContext);
            }
        }
开发者ID:tylerstevens,项目名称:Jt76EmberBase,代码行数:35,代码来源:Global.asax.cs


示例5: Application_Error

 protected void Application_Error()
 {
     var exception = Server.GetLastError();
     var httpException = exception as HttpException;
     Response.Clear();
     Server.ClearError();
     var routeData = new RouteData();
     routeData.Values["controller"] = "Errors";
     routeData.Values["action"] = "General";
     routeData.Values["exception"] = exception;
     Response.StatusCode = 500;
     if (httpException != null)
     {
         Response.StatusCode = httpException.GetHttpCode();
         switch (Response.StatusCode)
         {
             //case 403:
             //    routeData.Values["action"] = "Http403";
             //    break;
             case 404:
                 routeData.Values["action"] = "Http404";
                 break;
         }
     }
     // Avoid IIS7 getting in the middle
     Response.TrySkipIisCustomErrors = true;
     IController errorsController = new ErrorsController();
     HttpContextWrapper wrapper = new HttpContextWrapper(Context);
     var rc = new RequestContext(wrapper, routeData);
     errorsController.Execute(rc);
 }
开发者ID:LTHD,项目名称:WebBanHang,代码行数:31,代码来源:Global.asax.cs


示例6: Log

 private void Log(string methodName, RouteData routeData)
 {
     var controllerName = routeData.Values["controller"];
     var actionName = routeData.Values["action"];
     var message = String.Format("{0} controller:{1} action:{2}", methodName, controllerName, actionName);
     Debug.WriteLine(message, "Action Filter Log");
 }
开发者ID:hiepbh,项目名称:Assignment,代码行数:7,代码来源:LogActionFilters.cs


示例7: ExecuteErrorPage

        private void ExecuteErrorPage()
        {
            ErrorInfo errorInfo = new ErrorInfo(httpStatusCode, this.exception, HttpContext.Current.Request);

            RouteData routeData = new RouteData();
            routeData.Values.Add("controller", this.config.ErrorControllerName);
            routeData.Values.Add("action", this.config.ErrorActionName);
            routeData.Values.Add("errorInfo", errorInfo);

            HttpContextWrapper httpContextWrapper = new HttpContextWrapper(HttpContext.Current);
            RequestContext requestContext = new RequestContext(httpContextWrapper, routeData);

            IControllerFactory controllerFactory = ControllerBuilder.Current.GetControllerFactory();
            IController errorController = controllerFactory.CreateController(requestContext, this.config.ErrorControllerName);

            errorController.Execute(requestContext);

            if (httpStatusCode > 0)
            {
                HttpContext.Current.Response.StatusCode = httpStatusCode;
                HttpContext.Current.Response.ContentType = "text/html";
            }

            HttpContext.Current.Response.TrySkipIisCustomErrors = true;
        }
开发者ID:mholec,项目名称:mvcexceptionhandler,代码行数:25,代码来源:MvcExceptionHandler.cs


示例8: AssetRequestHandler_Tests

        public AssetRequestHandler_Tests()
        {
            var requestContext = new Mock<RequestContext>();
            var routeData = new RouteData();
            request = new Mock<HttpRequestBase>();
            response = new Mock<HttpResponseBase>();
            cache = new Mock<HttpCachePolicyBase>();
            requestHeaders = new NameValueCollection();

            routeData.Values.Add("path", "test/asset.js");
            requestContext.SetupGet(r => r.RouteData)
                          .Returns(routeData);

            requestContext.SetupGet(r => r.HttpContext.Response)
                          .Returns(response.Object);
            requestContext.SetupGet(r => r.HttpContext.Request)
                          .Returns(request.Object);
            requestContext.SetupGet(r => r.HttpContext.Items)
                          .Returns(new Dictionary<string, object>());

            response.SetupGet(r => r.OutputStream).Returns(() => outputStream);
            response.SetupGet(r => r.Cache).Returns(cache.Object);
            request.SetupGet(r => r.Headers).Returns(requestHeaders);

            var bundleContainer = new Mock<IBundleContainer>();
            bundleContainer.Setup(c => c.FindBundleContainingPath<Bundle>(It.IsAny<string>()))
                           .Returns(() => bundle);
            handler = new AssetRequestHandler(requestContext.Object, () => bundleContainer.Object);
        }
开发者ID:hempels,项目名称:cassette,代码行数:29,代码来源:AssetRequestHandler.cs


示例9: Application_Error

        protected void Application_Error()
        {
            var exception = Server.GetLastError();
            var httpException = exception as HttpException;
            Response.Clear();
            Server.ClearError();
            var routeData = new RouteData();
            routeData.Values["controller"] = "Errors";
            routeData.Values["action"] = "General";
            routeData.Values["exception"] = exception;
            Response.StatusCode = 500;
            if (httpException != null)
            {
                Response.StatusCode = httpException.GetHttpCode();
                switch (Response.StatusCode)
                {
                    case 403:
                        routeData.Values["action"] = "Http403";
                        break;
                    case 404:
                        routeData.Values["action"] = "Http404";
                        break;
                }
            }

            IController errorsController = new ErrorController();
            var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
            errorsController.Execute(rc);
        }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:29,代码来源:Global.asax.cs


示例10: Log

 private static void Log(RouteData routeData, /*[CallerMemberName]*/string methodName = "")
 {
     var controllerName = routeData.Values["Controller"];
     var actionName = routeData.Values["Action"];
     var message = string.Format("{0} controller: {1} action: {2}", methodName, controllerName, actionName);
     Debug.WriteLine(message, "Action Filter Log");
 }
开发者ID:Marpriori,项目名称:cursoMVC,代码行数:7,代码来源:LogActionFilter.cs


示例11: Application_Error

        protected void Application_Error(object sender, EventArgs e)
        {
            Exception lastError = Server.GetLastError();
            Server.ClearError();

            int statusCode = 0;

            if (lastError.GetType() == typeof(HttpException))
            {
                statusCode = ((HttpException)lastError).GetHttpCode();
            }
            else
            {
                statusCode = 500;
            }

            HttpContextWrapper contextWrapper = new HttpContextWrapper(this.Context);

            RouteData routeData = new RouteData();
            routeData.Values.Add("controller", "Error");
            routeData.Values.Add("action", "Index");
            routeData.Values.Add("statusCode", statusCode);
            routeData.Values.Add("exception", lastError);

            IController controller = new ErrorController();

            RequestContext requestContext = new RequestContext(contextWrapper, routeData);

            controller.Execute(requestContext);
            Response.End();
        }
开发者ID:StephanieMCraig,项目名称:personalsite,代码行数:31,代码来源:Global.asax.cs


示例12: GetNamespaceFrom

 static string GetNamespaceFrom(RouteData routeData)
 {
     return string.Format("{0}.{1}.{2}",
         routeData.Values["boundedContext"],
         routeData.Values["module"],
         routeData.Values["feature"]);
 }
开发者ID:JoB70,项目名称:Bifrost,代码行数:7,代码来源:KnockoutRazorView.cs


示例13: ShowCustomErrorPage

        private void ShowCustomErrorPage(Exception exception)
        {
            HttpException httpException = exception as HttpException;
            if (httpException == null)
                httpException = new HttpException(500, "Internal Server Error", exception);

            Response.Clear();
            RouteData routeData = new RouteData();
            routeData.Values.Add("controller", "Error");

            switch (httpException.GetHttpCode())
            {

                case 404:
                    routeData.Values.Add("action", "Http404");
                    break;

                default:
                    routeData.Values.Add("action", "Http404");
                    break;
            }

            Server.ClearError();

            var contentService = (IWebContent)DependencyResolver.Current.GetService(typeof(IWebContent));
            var domainService = (IDomain)DependencyResolver.Current.GetService(typeof(IDomain));
            var userService = (IUser)DependencyResolver.Current.GetService(typeof(IUser));
            var ecommerceService = (IECommerce)DependencyResolver.Current.GetService(typeof(IECommerce));
            //var stripeService = (IStripe) DependencyResolver.Current.GetService(typeof (IStripe));

            IController controller = new ErrorController(domainService, contentService, ecommerceService, userService);
            controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
        }
开发者ID:nhtera,项目名称:CrowdCMS,代码行数:33,代码来源:Global.asax.cs


示例14: GetHtmlHelper

        public static HtmlHelper GetHtmlHelper(bool clientValidationEnabled = true)
        {
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(Substitute.For<IViewEngine>());

            var controller = Substitute.For<ControllerBase>();
            var httpContext = Substitute.For<HttpContextBase>();
            httpContext.Request.Headers.Returns(new NameValueCollection());

            var routeData = new RouteData();
            routeData.Values["controller"] = "home";
            routeData.Values["action"] = "index";

            var controllerContext = new ControllerContext(httpContext, routeData, controller);

            var viewContext = new ViewContext(controllerContext, Substitute.For<IView>(), new ViewDataDictionary(), new TempDataDictionary(), new StringWriter())
                                  {
                                      HttpContext = httpContext,
                                      ClientValidationEnabled = clientValidationEnabled,
                                      UnobtrusiveJavaScriptEnabled = clientValidationEnabled,
                                      FormContext = new FormContext()
                                  };

            return new HtmlHelper(viewContext, Substitute.For<IViewDataContainer>());
        }
开发者ID:Kingefosa,项目名称:FunnelWeb,代码行数:25,代码来源:HtmlHelperBuilder.cs


示例15: GetRouteData

 private static RouteData GetRouteData()
 {
     var rd = new RouteData();
     rd.Values.Add("controller", "home");
     rd.Values.Add("action", "oldaction");
     return rd;
 }
开发者ID:mmoore99,项目名称:ActionMailerNext,代码行数:7,代码来源:UrlHelperExtensionsTests.cs


示例16: EngineLookupFailureThrows

        public void EngineLookupFailureThrows() {
            // Arrange
            ControllerBase controller = new Mock<ControllerBase>().Object;
            HttpContextBase httpContext = CreateHttpContext();
            RouteData routeData = new RouteData();
            routeData.Values["action"] = _viewName;
            ControllerContext context = new ControllerContext(httpContext, routeData, controller);
            Mock<IViewEngine> viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
            List<IViewEngine> viewEngines = new List<IViewEngine>();
            viewEngines.Add(viewEngine.Object);
            Mock<ViewEngineCollection> viewEngineCollection = new Mock<ViewEngineCollection>(MockBehavior.Strict, viewEngines);
            PartialViewResult result = new PartialViewResultHelper { ViewEngineCollection = viewEngineCollection.Object };
            viewEngineCollection
                .Expect(e => e.FindPartialView(It.IsAny<ControllerContext>(), _viewName))
                .Returns(new ViewEngineResult(new[] { "location1", "location2" }));
            viewEngine
                .Expect(e => e.FindPartialView(It.IsAny<ControllerContext>(), _viewName, It.IsAny<bool>()))
                .Callback<ControllerContext, string>(
                    (controllerContext, viewName) => {
                        Assert.AreSame(httpContext, controllerContext.HttpContext);
                        Assert.AreSame(routeData, controllerContext.RouteData);
                    })
                .Returns(new ViewEngineResult(new[] { "location1", "location2" }));

            // Act & Assert
            ExceptionHelper.ExpectInvalidOperationException(
                () => result.ExecuteResult(context),
                @"The partial view '" + _viewName + @"' was not found. The following locations were searched:
location1
location2");

            viewEngine.Verify();
            viewEngineCollection.Verify();
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:34,代码来源:PartialViewResultTest.cs


示例17: GetUrlHelper

 private static UrlHelper GetUrlHelper(RouteData routeData = null, RouteCollection routeCollection = null)
 {
     HttpContextBase httpcontext = MvcHelper.GetHttpContext("/app/", null, null);
     var urlHelper = new UrlHelper(new RequestContext(httpcontext, routeData ?? new RouteData()),
         routeCollection ?? new RouteCollection());
     return urlHelper;
 }
开发者ID:mmoore99,项目名称:ActionMailerNext,代码行数:7,代码来源:UrlHelperExtensionsTests.cs


示例18: GetFormHelper

        private static HtmlHelper GetFormHelper(out StringWriter writer) {
            Mock<HttpRequestBase> mockHttpRequest = new Mock<HttpRequestBase>();
            mockHttpRequest.Setup(r => r.Url).Returns(new Uri("http://www.contoso.com/some/path"));
            Mock<HttpResponseBase> mockHttpResponse = new Mock<HttpResponseBase>(MockBehavior.Strict);

            mockHttpResponse.Setup(r => r.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(r => AppPathModifier + r);
            Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
            mockHttpContext.Setup(c => c.Request).Returns(mockHttpRequest.Object);
            mockHttpContext.Setup(c => c.Response).Returns(mockHttpResponse.Object);
            RouteCollection rt = new RouteCollection();
            rt.Add(new Route("{controller}/{action}/{id}", null) { Defaults = new RouteValueDictionary(new { id = "defaultid" }) });
            rt.Add("namedroute", new Route("named/{controller}/{action}/{id}", null) { Defaults = new RouteValueDictionary(new { id = "defaultid" }) });
            RouteData rd = new RouteData();
            rd.Values.Add("controller", "home");
            rd.Values.Add("action", "oldaction");

            Mock<ViewContext> mockViewContext = new Mock<ViewContext>();
            mockViewContext.Setup(c => c.HttpContext).Returns(mockHttpContext.Object);
            mockViewContext.Setup(c => c.RouteData).Returns(rd);
            writer = new StringWriter();
            mockViewContext.Setup(c => c.Writer).Returns(writer);

            HtmlHelper helper = new HtmlHelper(
                mockViewContext.Object,
                new Mock<IViewDataContainer>().Object,
                rt);
            return helper;
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:28,代码来源:FormExtensionsTest.cs


示例19: ChildActionExtensionsTest

        public ChildActionExtensionsTest()
        {
            route = new Mock<RouteBase>();
            route.Setup(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>()))
                .Returns(() => virtualPathData);

            virtualPathData = new VirtualPathData(route.Object, "~/VirtualPath");

            routes = new RouteCollection();
            routes.Add(route.Object);

            originalRouteData = new RouteData();

            string returnValue = "";
            httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(hc => hc.Request.ApplicationPath).Returns("~");
            httpContext.Setup(hc => hc.Response.ApplyAppPathModifier(It.IsAny<string>()))
                .Callback<string>(s => returnValue = s)
                .Returns(() => returnValue);
            httpContext.Setup(hc => hc.Server.Execute(It.IsAny<IHttpHandler>(), It.IsAny<TextWriter>(), It.IsAny<bool>()));

            viewContext = new ViewContext
            {
                RequestContext = new RequestContext(httpContext.Object, originalRouteData)
            };

            viewDataContainer = new Mock<IViewDataContainer>();

            htmlHelper = new Mock<HtmlHelper>(viewContext, viewDataContainer.Object, routes);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:30,代码来源:ChildActionExtensionsTest.cs


示例20: Application_Error

        //protected void Application_PreRequestHandlerExecute()
        //{
        //    var culture = CultureInfo.CreateSpecificCulture("en-GB");
        //    culture.DateTimeFormat = CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat;
        //    Thread.CurrentThread.CurrentCulture = culture;

        //    culture = new CultureInfo("en-GB") {DateTimeFormat = Thread.CurrentThread.CurrentCulture.DateTimeFormat};
        //    Thread.CurrentThread.CurrentUICulture = culture;
        //}

        protected void Application_Error(object sender, EventArgs e)
        {
            var handleError = Convert.ToBoolean(ConfigurationManager.AppSettings["RedirectToErrorPage"]);

            var exception = Server.GetLastError();

            Utility.WriteToLog("Global.Application_Error() : " + exception, "Error");

            if (!handleError) return;

            Server.ClearError();

            var routeData = new RouteData();
            routeData.Values.Add("controller", "Error");
            routeData.Values.Add("action", "Index");
            routeData.Values.Add("exception", exception);

            if (exception.GetType() == typeof(HttpException))
            {
                routeData.Values.Add("statusCode", ((HttpException)exception).GetHttpCode());
            }
            else
            {
                routeData.Values.Add("statusCode", 500);
            }

            IController controller = new ErrorController();
            controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
            Response.End();
        }
开发者ID:whztt07,项目名称:SmartDb4,代码行数:40,代码来源:Global.asax.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Security.FormsAuthenticationTicket类代码示例发布时间:2022-05-26
下一篇:
C# Routing.RouteBase类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap