Permalink
Browse files

Redirect to site based on ID

  • Loading branch information...
1 parent ecd1a3e commit 4ae2ec1944c37f4b9281530ad5e54fcf6f8023d4 @robertgreiner committed Apr 6, 2011
@@ -3,18 +3,21 @@
using System.Linq;
using System.Web;
using System.Web.Mvc;
+using uURL.Models;
namespace uURL.Controllers
{
public class HomeController : Controller
{
- //
- // GET: /Home/
+ public ActionResult Index(string id) {
+ UrlRepository repo = new UrlRepository();
+ string url = repo.GetUrl(id);
- public ActionResult Index()
- {
- return View();
- }
+ if (string.IsNullOrEmpty(url)) {
+ return View();
+ }
+ return Redirect(@"http://" + url);
+ }
}
}
View
@@ -17,6 +17,12 @@ public class MvcApplication : System.Web.HttpApplication {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
+ routes.MapRoute(
+ "Redirect", // Route name
+ "{id}", // URL with parameters
+ new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
+ );
+
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?><Database Name="uURL" Class="UrlDataDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
+ <Connection Mode="WebSettings" ConnectionString="Data Source=localhost;Initial Catalog=uURL;Persist Security Info=True;User ID=testuser" SettingsObjectName="System.Configuration.ConfigurationManager.ConnectionStrings" SettingsPropertyName="uURLConnectionString" Provider="System.Data.SqlClient" />
+ <Table Name="dbo.url" Member="uURLs">
+ <Type Name="uURL">
+ <Column Name="id" Member="ID" Type="System.String" DbType="VarChar(50) NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
+ <Column Name="url" Member="URL" Type="System.String" DbType="VarChar(50) NOT NULL" CanBeNull="false" />
+ </Type>
+ </Table>
+</Database>
Oops, something went wrong.

0 comments on commit 4ae2ec1

Please sign in to comment.