mirror of
https://github.com/rudollee/LearningMVC.git
synced 2025-06-07 07:56:14 +00:00
Ch. 16 Routing Adv (until 16-5)
This commit is contained in:
parent
f219a8df27
commit
2fea7ffb5e
@ -61,6 +61,7 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="app.config" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||||
|
11
UrlsAndRoutes.Tests/app.config
Normal file
11
UrlsAndRoutes.Tests/app.config
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
|
</configuration>
|
@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Web;
|
|
||||||
using System.Web.Mvc;
|
|
||||||
|
|
||||||
namespace UrlsAndRoutes.AdditionalControllers
|
|
||||||
{
|
|
||||||
public class HomeController : Controller
|
|
||||||
{
|
|
||||||
public ActionResult Index()
|
|
||||||
{
|
|
||||||
ViewBag.Controller = "Addtional COntrollers - Home";
|
|
||||||
ViewBag.Action = "Index";
|
|
||||||
return View("ActionName");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -63,11 +63,18 @@ namespace UrlsAndRoutes
|
|||||||
// new { controller = "^H.*", action = "^Index|About", httpMethod = new HttpMethodConstraint("GET"), id = new RangeRouteConstraint(10, 20) },
|
// new { controller = "^H.*", action = "^Index|About", httpMethod = new HttpMethodConstraint("GET"), id = new RangeRouteConstraint(10, 20) },
|
||||||
// new[] { "URLsAndROutes.Controllers" });
|
// new[] { "URLsAndROutes.Controllers" });
|
||||||
|
|
||||||
routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}",
|
//routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}",
|
||||||
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
|
// new { controller = "Home", action = "Index", id = UrlParameter.Optional },
|
||||||
new { controller = "^H.*", action = "^Index|About", httpMethod = new HttpMethodConstraint("GET"),
|
// new { controller = "^H.*", action = "^Index|About", httpMethod = new HttpMethodConstraint("GET"),
|
||||||
id = new CompoundRouteConstraint(new IRouteConstraint[] { new AlphaRouteConstraint(), new MinLengthRouteConstraint(6) }) },
|
// id = new CompoundRouteConstraint(new IRouteConstraint[] { new AlphaRouteConstraint(), new MinLengthRouteConstraint(6) }) },
|
||||||
new[] { "URLsAndROutes.Controllers" });
|
// new[] { "URLsAndROutes.Controllers" });
|
||||||
|
|
||||||
|
routes.MapMvcAttributeRoutes();
|
||||||
|
|
||||||
|
routes.MapRoute("NewRoute", "App/Do{action}", new { controller = "Home" });
|
||||||
|
|
||||||
|
routes.MapRoute("MyRoute", "{controller}/{action}/{id}",
|
||||||
|
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,10 @@ using System.Web.Mvc;
|
|||||||
|
|
||||||
namespace UrlsAndRoutes.Controllers
|
namespace UrlsAndRoutes.Controllers
|
||||||
{
|
{
|
||||||
|
[RoutePrefix("Users")]
|
||||||
public class CustomerController : Controller
|
public class CustomerController : Controller
|
||||||
{
|
{
|
||||||
|
[Route("~/Test")]
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
ViewBag.Controller = "Customer";
|
ViewBag.Controller = "Customer";
|
||||||
@ -15,6 +17,18 @@ namespace UrlsAndRoutes.Controllers
|
|||||||
return View("ActionName");
|
return View("ActionName");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("Add/{user}/{id:int}")]
|
||||||
|
public string Create(string user, int id)
|
||||||
|
{
|
||||||
|
return string.Format("User: {0}, ID: {1}", user, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("Add/{user}/{password:alpha:length(6)}")]
|
||||||
|
public string ChangePass(string user, string password)
|
||||||
|
{
|
||||||
|
return string.Format("ChangePas Method - User: {0}, Pass: {1}", user, password);
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult List()
|
public ActionResult List()
|
||||||
{
|
{
|
||||||
ViewBag.Controller = "Customer";
|
ViewBag.Controller = "Customer";
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
<UseGlobalApplicationHostFile />
|
<UseGlobalApplicationHostFile />
|
||||||
<NuGetPackageImportStamp>
|
<NuGetPackageImportStamp>
|
||||||
</NuGetPackageImportStamp>
|
</NuGetPackageImportStamp>
|
||||||
|
<WebGreaseLibPath>..\packages\WebGrease.1.5.2\lib</WebGreaseLibPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@ -43,10 +44,16 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Antlr3.Runtime, Version=3.4.1.9004, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
|
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.5.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Web.DynamicData" />
|
<Reference Include="System.Web.DynamicData" />
|
||||||
<Reference Include="System.Web.Entity" />
|
<Reference Include="System.Web.Entity" />
|
||||||
<Reference Include="System.Web.ApplicationServices" />
|
<Reference Include="System.Web.ApplicationServices" />
|
||||||
@ -56,6 +63,9 @@
|
|||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="System.Web.Extensions" />
|
<Reference Include="System.Web.Extensions" />
|
||||||
|
<Reference Include="System.Web.Optimization, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Web" />
|
<Reference Include="System.Web" />
|
||||||
@ -63,6 +73,9 @@
|
|||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Web.Services" />
|
<Reference Include="System.Web.Services" />
|
||||||
<Reference Include="System.EnterpriseServices" />
|
<Reference Include="System.EnterpriseServices" />
|
||||||
|
<Reference Include="WebGrease, Version=1.5.2.14234, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System.Web.Razor">
|
<Reference Include="System.Web.Razor">
|
||||||
@ -92,7 +105,6 @@
|
|||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AdditionalControllers\HomeController.cs" />
|
|
||||||
<Compile Include="App_Start\RouteConfig.cs" />
|
<Compile Include="App_Start\RouteConfig.cs" />
|
||||||
<Compile Include="Controllers\AdminController.cs" />
|
<Compile Include="Controllers\AdminController.cs" />
|
||||||
<Compile Include="Controllers\CustomerController.cs" />
|
<Compile Include="Controllers\CustomerController.cs" />
|
||||||
|
@ -12,5 +12,11 @@
|
|||||||
<body>
|
<body>
|
||||||
<div>The controller is: @ViewBag.Controller</div>
|
<div>The controller is: @ViewBag.Controller</div>
|
||||||
<div>The action is: @ViewBag.Action</div>
|
<div>The action is: @ViewBag.Action</div>
|
||||||
|
<div>
|
||||||
|
@Html.ActionLink("This is an outgoing URL", "CustomVariable")
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
@Html.ActionLink("This targets another controller", "Index", "Customer")
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -5,39 +5,39 @@
|
|||||||
-->
|
-->
|
||||||
<configuration>
|
<configuration>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="webpages:Version" value="3.0.0.0"/>
|
<add key="webpages:Version" value="3.0.0.0" />
|
||||||
<add key="webpages:Enabled" value="false"/>
|
<add key="webpages:Enabled" value="false" />
|
||||||
<add key="ClientValidationEnabled" value="true"/>
|
<add key="ClientValidationEnabled" value="true" />
|
||||||
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
|
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
<system.web>
|
<system.web>
|
||||||
<compilation debug="true" targetFramework="4.5.2"/>
|
<compilation debug="true" targetFramework="4.5.2" />
|
||||||
<httpRuntime targetFramework="4.5.2"/>
|
<httpRuntime targetFramework="4.5.2" />
|
||||||
</system.web>
|
</system.web>
|
||||||
<runtime>
|
<runtime>
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
|
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
|
||||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
|
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
|
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
|
||||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
|
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
|
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
|
||||||
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
|
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
<system.codedom>
|
<system.codedom>
|
||||||
<compilers>
|
<compilers>
|
||||||
<compiler language="c#;cs;csharp" extension=".cs"
|
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
|
||||||
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
|
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
|
||||||
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
|
|
||||||
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
|
|
||||||
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
|
|
||||||
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
|
|
||||||
</compilers>
|
</compilers>
|
||||||
</system.codedom>
|
</system.codedom>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="Antlr" version="3.4.1.9004" targetFramework="net452" />
|
||||||
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net452" />
|
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net452" />
|
||||||
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net452" />
|
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net452" />
|
||||||
|
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net452" />
|
||||||
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net452" />
|
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net452" />
|
||||||
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.3" targetFramework="net452" />
|
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.3" targetFramework="net452" />
|
||||||
<package id="Microsoft.Net.Compilers" version="1.3.2" targetFramework="net452" developmentDependency="true" />
|
<package id="Microsoft.Net.Compilers" version="1.3.2" targetFramework="net452" developmentDependency="true" />
|
||||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
|
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
|
||||||
|
<package id="Newtonsoft.Json" version="5.0.4" targetFramework="net452" />
|
||||||
|
<package id="WebGrease" version="1.5.2" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
Loading…
x
Reference in New Issue
Block a user