當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。