Redirect with CodeIgniter

redirect() URL Helper The redirect statement in code igniter sends the user to the specified web page using a redirect header statement. This statement resides in the URL helper which is loaded in the following way: $this->load->helper(‘url’); The redirect function loads a local URI specified in the first parameter of the function call and built … Read more

Call UrlHelper in models in ASP.NET MVC

Helpful tip, in any ASP.NET application, you can get a reference of the current HttpContext HttpContext.Current which is derived from System.Web. Therefore, the following will work anywhere in an ASP.NET MVC application: UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext); url.Action(“ContactUs”); // Will output the proper link according to routing info Example: public class MyModel { public int … Read more

ASP.NET MVC: Unit testing controllers that use UrlHelper

Here is one of my tests (xUnit + Moq) just for similar case (using Url.RouteUrl in controller) Hope this helps: var routes = new RouteCollection(); MvcApplication.RegisterRoutes(routes); var request = new Mock<HttpRequestBase>(MockBehavior.Strict); request.SetupGet(x => x.ApplicationPath).Returns(“https://stackoverflow.com/”); request.SetupGet(x => x.Url).Returns(new Uri(“http://localhost/a”, UriKind.Absolute)); request.SetupGet(x => x.ServerVariables).Returns(new System.Collections.Specialized.NameValueCollection()); var response = new Mock<HttpResponseBase>(MockBehavior.Strict); response.Setup(x => x.ApplyAppPathModifier(“/post1”)).Returns(“http://localhost/post1”); var context = new … Read more