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


C# Routing.RouteData类代码示例

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


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


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