Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Redirect to site based on ID

  • Loading branch information...
commit 4ae2ec1944c37f4b9281530ad5e54fcf6f8023d4 1 parent ecd1a3e
@robertgreiner authored
View
15 uURL/Controllers/HomeController.cs
@@ -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
6 uURL/Global.asax.cs
@@ -18,6 +18,12 @@ public class MvcApplication : System.Web.HttpApplication {
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
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
View
329 uURL/Models/UrlData.Designer.cs
@@ -1,186 +1,163 @@
-//------------------------------------------------------------------------------
+#pragma warning disable 1591
+//------------------------------------------------------------------------------
// <auto-generated>
-// This code was generated from a template.
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.225
//
-// Manual changes to this file may cause unexpected behavior in your application.
-// Manual changes to this file will be overwritten if the code is regenerated.
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
-using System;
-using System.Data.Objects;
-using System.Data.Objects.DataClasses;
-using System.Data.EntityClient;
-using System.ComponentModel;
-using System.Xml.Serialization;
-using System.Runtime.Serialization;
-
-[assembly: EdmSchemaAttribute()]
-
namespace uURL.Models
{
- #region Contexts
-
- /// <summary>
- /// No Metadata Documentation available.
- /// </summary>
- public partial class uURLEntities : ObjectContext
- {
- #region Constructors
-
- /// <summary>
- /// Initializes a new uURLEntities object using the connection string found in the 'uURLEntities' section of the application configuration file.
- /// </summary>
- public uURLEntities() : base("name=uURLEntities", "uURLEntities")
- {
- this.ContextOptions.LazyLoadingEnabled = true;
- OnContextCreated();
- }
-
- /// <summary>
- /// Initialize a new uURLEntities object.
- /// </summary>
- public uURLEntities(string connectionString) : base(connectionString, "uURLEntities")
- {
- this.ContextOptions.LazyLoadingEnabled = true;
- OnContextCreated();
- }
-
- /// <summary>
- /// Initialize a new uURLEntities object.
- /// </summary>
- public uURLEntities(EntityConnection connection) : base(connection, "uURLEntities")
- {
- this.ContextOptions.LazyLoadingEnabled = true;
- OnContextCreated();
- }
-
- #endregion
-
- #region Partial Methods
-
- partial void OnContextCreated();
-
- #endregion
-
- #region ObjectSet Properties
-
- /// <summary>
- /// No Metadata Documentation available.
- /// </summary>
- public ObjectSet<uUrl> uUrls
- {
- get
- {
- if ((_uUrls == null))
- {
- _uUrls = base.CreateObjectSet<uUrl>("uUrls");
- }
- return _uUrls;
- }
- }
- private ObjectSet<uUrl> _uUrls;
-
- #endregion
- #region AddTo Methods
-
- /// <summary>
- /// Deprecated Method for adding a new object to the uUrls EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
- /// </summary>
- public void AddTouUrls(uUrl uUrl)
- {
- base.AddObject("uUrls", uUrl);
- }
-
- #endregion
- }
-
-
+ using System.Data.Linq;
+ using System.Data.Linq.Mapping;
+ using System.Data;
+ using System.Collections.Generic;
+ using System.Reflection;
+ using System.Linq;
+ using System.Linq.Expressions;
+ using System.ComponentModel;
+ using System;
+
+
+ [global::System.Data.Linq.Mapping.DatabaseAttribute(Name="uURL")]
+ public partial class UrlDataDataContext : System.Data.Linq.DataContext
+ {
+
+ private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
+
+ #region Extensibility Method Definitions
+ partial void OnCreated();
+ partial void InsertuURL(uURL instance);
+ partial void UpdateuURL(uURL instance);
+ partial void DeleteuURL(uURL instance);
#endregion
-
- #region Entities
-
- /// <summary>
- /// No Metadata Documentation available.
- /// </summary>
- [EdmEntityTypeAttribute(NamespaceName="uURLModel", Name="uUrl")]
- [Serializable()]
- [DataContractAttribute(IsReference=true)]
- public partial class uUrl : EntityObject
- {
- #region Factory Method
-
- /// <summary>
- /// Create a new uUrl object.
- /// </summary>
- /// <param name="id">Initial value of the ID property.</param>
- /// <param name="url">Initial value of the Url property.</param>
- public static uUrl CreateuUrl(global::System.String id, global::System.String url)
- {
- uUrl uUrl = new uUrl();
- uUrl.ID = id;
- uUrl.Url = url;
- return uUrl;
- }
-
- #endregion
- #region Primitive Properties
-
- /// <summary>
- /// No Metadata Documentation available.
- /// </summary>
- [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
- [DataMemberAttribute()]
- public global::System.String ID
- {
- get
- {
- return _ID;
- }
- set
- {
- if (_ID != value)
- {
- OnIDChanging(value);
- ReportPropertyChanging("ID");
- _ID = StructuralObject.SetValidValue(value, false);
- ReportPropertyChanged("ID");
- OnIDChanged();
- }
- }
- }
- private global::System.String _ID;
- partial void OnIDChanging(global::System.String value);
- partial void OnIDChanged();
-
- /// <summary>
- /// No Metadata Documentation available.
- /// </summary>
- [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
- [DataMemberAttribute()]
- public global::System.String Url
- {
- get
- {
- return _Url;
- }
- set
- {
- OnUrlChanging(value);
- ReportPropertyChanging("Url");
- _Url = StructuralObject.SetValidValue(value, false);
- ReportPropertyChanged("Url");
- OnUrlChanged();
- }
- }
- private global::System.String _Url;
- partial void OnUrlChanging(global::System.String value);
- partial void OnUrlChanged();
-
- #endregion
-
- }
-
+
+ public UrlDataDataContext() :
+ base(global::System.Configuration.ConfigurationManager.ConnectionStrings["uURLConnectionString"].ConnectionString, mappingSource)
+ {
+ OnCreated();
+ }
+
+ public UrlDataDataContext(string connection) :
+ base(connection, mappingSource)
+ {
+ OnCreated();
+ }
+
+ public UrlDataDataContext(System.Data.IDbConnection connection) :
+ base(connection, mappingSource)
+ {
+ OnCreated();
+ }
+
+ public UrlDataDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
+ base(connection, mappingSource)
+ {
+ OnCreated();
+ }
+
+ public UrlDataDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
+ base(connection, mappingSource)
+ {
+ OnCreated();
+ }
+
+ public System.Data.Linq.Table<uURL> uURLs
+ {
+ get
+ {
+ return this.GetTable<uURL>();
+ }
+ }
+ }
+
+ [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.url")]
+ public partial class uURL : INotifyPropertyChanging, INotifyPropertyChanged
+ {
+
+ private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
+
+ private string _ID;
+
+ private string _URL;
+
+ #region Extensibility Method Definitions
+ partial void OnLoaded();
+ partial void OnValidate(System.Data.Linq.ChangeAction action);
+ partial void OnCreated();
+ partial void OnIDChanging(string value);
+ partial void OnIDChanged();
+ partial void OnURLChanging(string value);
+ partial void OnURLChanged();
#endregion
-
+
+ public uURL()
+ {
+ OnCreated();
+ }
+
+ [global::System.Data.Linq.Mapping.ColumnAttribute(Name="id", Storage="_ID", DbType="VarChar(50) NOT NULL", CanBeNull=false, IsPrimaryKey=true)]
+ public string ID
+ {
+ get
+ {
+ return this._ID;
+ }
+ set
+ {
+ if ((this._ID != value))
+ {
+ this.OnIDChanging(value);
+ this.SendPropertyChanging();
+ this._ID = value;
+ this.SendPropertyChanged("ID");
+ this.OnIDChanged();
+ }
+ }
+ }
+
+ [global::System.Data.Linq.Mapping.ColumnAttribute(Name="url", Storage="_URL", DbType="VarChar(50) NOT NULL", CanBeNull=false)]
+ public string URL
+ {
+ get
+ {
+ return this._URL;
+ }
+ set
+ {
+ if ((this._URL != value))
+ {
+ this.OnURLChanging(value);
+ this.SendPropertyChanging();
+ this._URL = value;
+ this.SendPropertyChanged("URL");
+ this.OnURLChanged();
+ }
+ }
+ }
+
+ public event PropertyChangingEventHandler PropertyChanging;
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ protected virtual void SendPropertyChanging()
+ {
+ if ((this.PropertyChanging != null))
+ {
+ this.PropertyChanging(this, emptyChangingEventArgs);
+ }
+ }
+
+ protected virtual void SendPropertyChanged(String propertyName)
+ {
+ if ((this.PropertyChanged != null))
+ {
+ this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+ }
}
+#pragma warning restore 1591
View
9 uURL/Models/UrlData.dbml
@@ -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>
View
12 uURL/Models/UrlData.dbml.layout
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ordesignerObjectsDiagram dslVersion="1.0.0.0" absoluteBounds="0, 0, 11, 8.5" name="UrlData">
+ <DataContextMoniker Name="/UrlDataDataContext" />
+ <nestedChildShapes>
+ <classShape Id="64311ea6-df45-48d3-92d8-96215680dda9" absoluteBounds="2.75, 1.125, 2, 1.1939925130208333">
+ <DataClassMoniker Name="/UrlDataDataContext/uURL" />
+ <nestedChildShapes>
+ <elementListCompartment Id="876734ed-7367-4517-bebe-6472f35d69f3" absoluteBounds="2.765, 1.585, 1.9700000000000002, 0.63399251302083326" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
+ </nestedChildShapes>
+ </classShape>
+ </nestedChildShapes>
+</ordesignerObjectsDiagram>
View
68 uURL/Models/UrlData.edmx
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
- <!-- EF Runtime content -->
- <edmx:Runtime>
- <!-- SSDL content -->
- <edmx:StorageModels>
- <Schema Namespace="uURLModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
- <EntityContainer Name="uURLModelStoreContainer">
- <EntitySet Name="url" EntityType="uURLModel.Store.url" store:Type="Tables" Schema="dbo" />
- </EntityContainer>
- <EntityType Name="url">
- <Key>
- <PropertyRef Name="id" />
- </Key>
- <Property Name="id" Type="varchar" Nullable="false" MaxLength="50" />
- <Property Name="url" Type="varchar" Nullable="false" MaxLength="50" />
- </EntityType>
- </Schema>
- </edmx:StorageModels>
- <!-- CSDL content -->
- <edmx:ConceptualModels>
- <Schema Namespace="uURLModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
- <EntityContainer Name="uURLEntities" annotation:LazyLoadingEnabled="true">
- <EntitySet Name="uUrls" EntityType="uURLModel.uUrl" />
- </EntityContainer>
- <EntityType Name="uUrl">
- <Key>
- <PropertyRef Name="ID" />
- </Key>
- <Property Name="ID" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false" />
- <Property Name="Url" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false" />
- </EntityType>
- </Schema>
- </edmx:ConceptualModels>
- <!-- C-S mapping content -->
- <edmx:Mappings>
- <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
- <EntityContainerMapping StorageEntityContainer="uURLModelStoreContainer" CdmEntityContainer="uURLEntities">
- <EntitySetMapping Name="uUrls"><EntityTypeMapping TypeName="uURLModel.uUrl"><MappingFragment StoreEntitySet="url">
- <ScalarProperty Name="ID" ColumnName="id" />
- <ScalarProperty Name="Url" ColumnName="url" />
- </MappingFragment></EntityTypeMapping></EntitySetMapping>
- </EntityContainerMapping>
- </Mapping>
- </edmx:Mappings>
- </edmx:Runtime>
- <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
- <Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
- <Connection>
- <DesignerInfoPropertySet>
- <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
- </DesignerInfoPropertySet>
- </Connection>
- <Options>
- <DesignerInfoPropertySet>
- <DesignerProperty Name="ValidateOnBuild" Value="true" />
- <DesignerProperty Name="EnablePluralization" Value="True" />
- <DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
- </DesignerInfoPropertySet>
- </Options>
- <!-- Diagram content (shape and connector positions) -->
- <Diagrams>
- <Diagram Name="UrlData">
- <EntityTypeShape EntityType="uURLModel.uUrl" Width="1.5" PointX="0.75" PointY="0.75" Height="1.4033821614583331" IsExpanded="true" />
- </Diagram>
- </Diagrams>
- </Designer>
-</edmx:Edmx>
View
20 uURL/Models/UrlRepository.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace uURL.Models {
+ public class UrlRepository {
+
+ public string GetUrl(string id) {
+ string url = string.Empty;
+ using (var ctx = new UrlDataDataContext()) {
+ url = (from row in ctx.uURLs
+ where row.ID == id
+ select row.URL).FirstOrDefault();
+ }
+ return url;
+ }
+
+ }
+}
View
6 uURL/Views/Home/Index.cshtml
@@ -1,6 +1,8 @@
@{
- ViewBag.Title = "Index";
+ ViewBag.Title = "uURL - URL Shortener";
}
-<h2>Index</h2>
+<h2>uURL</h2>
+Short ID: @ViewBag.ID
+Redirecting to: @ViewBag.URL
View
7 uURL/Web.config
@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
@@ -50,4 +50,7 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
-<connectionStrings><add name="uURLEntities" connectionString="metadata=res://*/Models.UrlData.csdl|res://*/Models.UrlData.ssdl|res://*/Models.UrlData.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=uURL;persist security info=True;user id=testuser;password=test;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>
+<connectionStrings>
+ <add name="uURLConnectionString" connectionString="Data Source=localhost;Initial Catalog=uURL;Persist Security Info=True;User ID=testuser;Password=test"
+ providerName="System.Data.SqlClient" />
+</connectionStrings></configuration>
View
26 uURL/uURL.csproj
@@ -35,6 +35,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Data.Entity" />
+ <Reference Include="System.Data.Linq" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
@@ -65,11 +66,12 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
- <Compile Include="Models\UrlData.Designer.cs">
+ <Compile Include="Models\UrlData.designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
- <DependentUpon>UrlData.edmx</DependentUpon>
+ <DependentUpon>UrlData.dbml</DependentUpon>
</Compile>
+ <Compile Include="Models\UrlRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@@ -105,15 +107,23 @@
<Content Include="Views\Shared\Error.cshtml" />
<Content Include="Views\Shared\_Layout.cshtml" />
</ItemGroup>
- <ItemGroup />
<ItemGroup>
- <EntityDeploy Include="Models\UrlData.edmx">
- <Generator>EntityModelCodeGenerator</Generator>
- <LastGenOutput>UrlData.Designer.cs</LastGenOutput>
- </EntityDeploy>
+ <Content Include="Views\Home\Index.cshtml" />
</ItemGroup>
<ItemGroup>
- <Content Include="Views\Home\Index.cshtml" />
+ <None Include="Models\UrlData.dbml">
+ <Generator>MSLinqToSQLGenerator</Generator>
+ <LastGenOutput>UrlData.designer.cs</LastGenOutput>
+ <SubType>Designer</SubType>
+ </None>
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{3259AA49-8AA1-44D3-9025-A0B520596A8C}" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Models\UrlData.dbml.layout">
+ <DependentUpon>UrlData.dbml</DependentUpon>
+ </None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
Please sign in to comment.
Something went wrong with that request. Please try again.