{"id":176021,"date":"2013-04-09T22:56:06","date_gmt":"2013-04-09T18:56:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=176021"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=176021","title":{"rendered":"<span class=\"post_title\">ASP NET.MVC \u0423\u0440\u043e\u043a 4. Routing \u0438 Bundles<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<b>\u0426\u0435\u043b\u044c \u0443\u0440\u043e\u043a\u0430:<\/b> \u0418\u0437\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438. \u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 Areas \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u041f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h5>Controller \u0438 Action.<\/h5>\n<p>  \u0412\u0435\u0431-\u0441\u0430\u0439\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u0442\u0440\u0430\u043d\u0438\u0446. \u0412\u043e\u043e\u0431\u0449\u0435, \u0432\u0435\u0431-\u0441\u0430\u0439\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u043d\u0435 \u0438\u0437 \u0441\u0442\u0440\u0430\u043d\u0438\u0446, \u0430 \u0438\u0437 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043d\u043e \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u043c\u0435\u0442\u044c. <\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0443 \u043a\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432\u044b\u0437\u0432\u0430\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u044d\u0442\u043e controller \u0438 action. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0432 App_Start\/RouteConfig.cs:   <\/p>\n<pre><code class=\"cs\">routes.MapRoute(                 name: &quot;Default&quot;,                 url: &quot;{controller}\/{action}\/{id}&quot;,                 defaults: new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }             ); <\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a> \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c,<code> url = \u00ab\/Role\/Create\/2\u00bb<\/code> \u0431\u0443\u0434\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <b>RoleController<\/b>, \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043c <b>Create <\/b>\u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c (\u0430 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c) \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <b>id<\/b>. \u0418 \u0435\u0441\u043b\u0438 \u043e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 id, \u0442\u043e id = 2 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 id = \u201c2\u201d, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u0437\u0430 \u0442\u0438\u043f \u0431\u0443\u0434\u0435\u0442.<\/p>\n<p>  Defaults \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442<b> \u201c\/Role\/Create\u201d<\/b> \u2013 \u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0447\u0442\u043e Create \u043c\u0435\u0442\u043e\u0434 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c id \u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0438\u043b\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043e default(), \u0442\u043e \u043f\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 (\u043c\u044b \u0436\u0435 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b). \u0418\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430: \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d \u043c\u0435\u0442\u043e\u0434, \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<pre><code class=\"cs\"> public ActionResult Index(int? id)         {             \/\/ok             return View();         } \u2026         public ActionResult Index(int id = 0)         {             \/\/ok             return View();         } \u2026         public ActionResult Index(int id)         {             \/\/fail             return View();         } <\/code><\/pre>\n<p>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 url = \u201c\/Role\u201d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u043c\u0435\u0442\u043e\u0434 Index \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 RoleController.<\/p>\n<p>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 url = \u201c\/\u201d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u043c\u0435\u0442\u043e\u0434 Index \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 HomeController.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445.<\/p>\n<h5>BaseController<\/h5>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432, \u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044e, \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 BaseController:  <\/p>\n<pre><code class=\"cs\">public abstract class BaseController : Controller     {         [Inject]         public IRepository Repository { get; set; }     } <\/code><\/pre>\n<p>  \u0418   <\/p>\n<pre><code class=\"cs\">  public class HomeController : BaseController     {         public ActionResult Index()         {             return View();         }     } <\/code><\/pre>\n<p>  View Home\/Index.cshtml:  <\/p>\n<pre><code class=\"html\">@{     ViewBag.Title = &quot;LessonProject&quot;;     Layout = &quot;~\/Views\/Shared\/_Layout.cshtml&quot;; }  &lt;h2&gt;LessonProject&lt;\/h2&gt;  &lt;p&gt;     &lt;div class=&quot;menu&quot;&gt;     &lt;a href=&quot;@Url.Action(&quot;Index&quot;, &quot;Role&quot;)&quot;&gt;\u0420\u043e\u043b\u0438&lt;\/a&gt;     @Html.ActionLink(&quot;\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438&quot;,  &quot;Index&quot;, &quot;User&quot;)     &lt;\/div&gt;      &lt;\/p&gt;  <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 RoleController:  <\/p>\n<pre><code class=\"cs\">    public class RoleController : BaseController     {         public ActionResult Index()         {             var roles = Repository.Roles.ToList();             return View(roles);         }     } <\/code><\/pre>\n<p>  \u0418   <\/p>\n<pre><code class=\"html\">@model IList&lt;LessonProject.Model.Role&gt;  @{     ViewBag.Title = &quot;Roles&quot;;     Layout = &quot;~\/Views\/Shared\/_Layout.cshtml&quot;; }  &lt;h2&gt;Roles&lt;\/h2&gt;  &lt;p&gt;     @foreach (var role in Model)     {         &lt;div class=&quot;item&quot;&gt;             &lt;span class=&quot;id&quot;&gt;                 @role.ID             &lt;\/span&gt;             &lt;span class=&quot;name&quot;&gt;                 @role.Name             &lt;\/span&gt;             &lt;span class=&quot;Code&quot;&gt;                 @role.Code             &lt;\/span&gt;         &lt;\/div&gt;     } &lt;\/p&gt;  <\/code><\/pre>\n<p>  \u0418 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 UserController, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0434\u0435\u043b\u0430\u0435\u043c.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Url.Action() \u0438 Html.ActionLink().<\/p>\n<p>  <b>Url.Action()<\/b> \u2013 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043f\u0435\u0440\u0432\u044b\u043c \u2013 action, \u043f\u043e\u0442\u043e\u043c \u2013 controller, \u043f\u043e\u0442\u043e\u043c \u0447\u0435\u0440\u0435\u0437 new {} \u2013 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435.<br \/>  <b>Html.ActionLink()<\/b> \u2013 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u0433 <code>&lt;a&gt;<\/code>, \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2013 \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438, \u0432\u0442\u043e\u0440\u043e\u0439 \u2013 action, \u0442\u0440\u0435\u0442\u0438\u0439 \u2013 controller, \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u043c(\u0438\u043b\u0438 \u043f\u044f\u0442\u044b\u043c) \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0438\u0434\u0443\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u0442\u0435\u0433\u0430, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u2013 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u044f\u0442\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c null. \u0422.\u0435.:<br \/>  <code>@Html.ActionLink(\u201c\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 1\u201d, \u201cItem\u201d, \u201cUser\u201d, new {id = 1}, &lt;b&gt;null&lt;\/b&gt;)<\/code><br \/>  \u0415\u0441\u043b\u0438 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c null:<br \/>  <code>@Html.ActionLink(\u201c\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 1\u201d, \u201cItem\u201d, \u201cUser\u201d, new {id = 1})<\/code><br \/>   \u0442\u043e \u0441\u0441\u044b\u043b\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<br \/>  <code>&lt;a href=\u201d\/User\/Item?length=4\u201d&gt;\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c 1&lt;\/a&gt;<\/code><\/p>\n<h5>\u041f\u043e\u0440\u044f\u0434\u043e\u043a \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432<\/h5>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u0440\u0430\u043d\u0435\u0435 \u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a RoleController:  <\/p>\n<pre><code class=\"cs\">routes.MapRoute(                 name: &quot;Role&quot;,                 url: &quot;roli\/{action}\/{id}&quot;,                 defaults: new { controller = &quot;Role&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }             ); <\/code><\/pre>\n<p>  \u0421\u0442\u0440\u043e\u043a\u0430 \u201croli\/{action}\/{id}\u201d \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u0437\u0430\u0434\u0430\u0435\u0442 \u0438\u043c\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 defaults. \u0410 action \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c.<br \/>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0421\u0441\u044b\u043b\u043a\u0430 \u0441\u0442\u0430\u043b\u0430:<br \/>  <code>&lt;a href=&quot;\/roli&quot;&gt;\u0420\u043e\u043b\u0438&lt;\/a&gt;<\/code><br \/>  \u0423\u0431\u0435\u0440\u0435\u043c \u0438\u0437 defaults action=\u201dIndex\u201d:<br \/>  <code>&lt;a href=&quot;\/roli\/Index&quot;&gt;\u0420\u043e\u043b\u0438&lt;\/a&gt;<\/code><br \/>  \u041f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u201cDefaults\u201d:<br \/>  <code>&lt;a href=&quot;\/Role&quot;&gt;\u0420\u043e\u043b\u0438&lt;\/a&gt; <\/code><\/p>\n<p>  \u0422\u0430\u043a\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0438\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u043e\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u201cdefault\u201d \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a Role\/Index:  <\/p>\n<pre><code class=\"cs\">  context.MapRoute(                 name : &quot;default&quot;,                 url : &quot;{controller}\/{action}\/{id}&quot;,                 defaults : new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional },             ); <\/code><\/pre>\n<p>  \u0415\u0449\u0435 \u043d\u0430\u0434\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>IgnoreRoute<\/code>, \u043e\u043d \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0442\u043e\u0440\u0443, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 url \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0434 \u0448\u0430\u0431\u043b\u043e\u043d, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043f\u043e \u0442\u043e\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0443, \u0430 \u043d\u0435 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. <\/p>\n<h5>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f (Constrains)<\/h5>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0441\u043e\u0431\u043e\u043c\u0443 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, id \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c:  <\/p>\n<pre><code class=\"cs\">routes.MapRoute(                 name: &quot;Role&quot;,                 url: &quot;roli\/{action}\/{id}&quot;,                 defaults: new { controller = &quot;Role&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional },                 constraints : new {id = @&quot;\\d+&quot;}             ); <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 id, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e, \u0431\u0443\u0434\u0435\u0442 \u0438\u043b\u0438 \u0432\u044b\u0431\u0440\u0430\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0439\u0434\u0435\u043d \u0438 \u0441\u0441\u044b\u043b\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0431\u0438\u0442\u043e\u0439:<br \/>  \u0414\u043b\u044f:<br \/>  <code>&lt;a href=&quot;@Url.Action(&quot;Index&quot;, &quot;Role&quot;, new { id = &quot;privet&quot; })&quot;&gt;\u0420\u043e\u043b\u0438&lt;\/a&gt;<\/code><br \/>  \u0411\u0443\u0434\u0435\u0442:<br \/>  <code>&lt;a href=&quot;\/Role\/Index\/privet&quot;&gt;\u0420\u043e\u043b\u0438&lt;\/a&gt;<\/code><br \/>  \u0410 \u0434\u043b\u044f:<br \/>  <code>&lt;a href=&quot;@Url.Action(&quot;Index&quot;, &quot;Role&quot;, new { id = &quot;1&quot; })&quot;&gt;\u0420\u043e\u043b\u0438&lt;\/a&gt;<\/code><br \/>  \u0411\u0443\u0434\u0435\u0442:<br \/>  <code>&lt;a href=&quot;\/roli\/Index\/1&quot;&gt;\u0420\u043e\u043b\u0438&lt;\/a&gt;<\/code><br \/>  <i>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u0445 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0442\u0443\u0442: <a href=\"http:\/\/stephenwalther.com\/archive\/2008\/08\/07\/asp-net-mvc-tip-30-create-custom-route-constraints.aspx\">http:\/\/stephenwalther.com\/archive\/2008\/08\/07\/asp-net-mvc-tip-30-create-custom-route-constraints.aspx<\/a><\/i><\/p>\n<h5>Areas <\/h5>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0444\u043e\u0440\u0443\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u0442 \u0432\u0441\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430. \u041c\u044b \u0436\u0435 \u043f\u043e\u0434\u0435\u043b\u0438\u043c \u043d\u0430 \u0447\u0430\u0441\u0442\u044c Admin \u2013 \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0430\u0434\u043c\u0438\u043d\u043a\u0430, \u0438 \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f Default.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/fe0\/b74\/d97\/fe0b74d97287a4fc2164403ad743b9f3.jpg\"\/><\/p>\n<p>  \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:  <\/p>\n<ul>\n<li>\u041f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u0443\u0435\u043c _Default \u0432 Default \u0432\u0435\u0437\u0434\u0435.<\/li>\n<li>\u041f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043c \u0441\u0432\u043e\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b (\u043a\u0440\u043e\u043c\u0435 <code>BaseController<\/code>) \u0432 \u043f\u0430\u043f\u043a\u0443 Areas\/Default\/Controllers <\/li>\n<li>\u041f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u0443\u0435\u043c namespace \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0432 <code>LessonProject.Areas.Default.Controllers<\/code> <\/li>\n<li>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c <code>DefaultAreaRegistration<\/code>.\n<p>  \u0417\u0434\u0435\u0441\u044c \u0432\u0430\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432: namespaces, \u043e\u043d \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0438\u0437 \u043a\u0430\u043a\u0438\u0445 namespace \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430:   <\/p>\n<pre><code class=\"cs\">  public class DefaultAreaRegistration : AreaRegistration     {         public override string AreaName         {             get             {                 return &quot;Default&quot;;             }         }          public override void RegisterArea(AreaRegistrationContext context)         {             context.MapRoute(                 name : &quot;default&quot;,                 url : &quot;{controller}\/{action}\/{id}&quot;,                 defaults : new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional },                 namespaces : new [] { &quot;LessonProject.Areas.Default.Controllers&quot; }             );         }     } <\/code><\/pre>\n<p>  <\/li>\n<li>\u0412 Global.asax \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0430 <code>AreaRegistration.RegisterAllAreas();<\/code> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f area, \u043d\u043e \u043e\u043d\u0430 \u043d\u0430\u043c \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0441\u043b\u0438 DefaultArea \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u043d\u044c\u0448\u0435 AdminArea, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u044f Default, \u0430 \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0443 \u043c\u044b \u0443\u0436\u0435 \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u0430\u0441\u0442\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c:<br \/> \n<pre><code class=\"cs\">  var adminArea = new AdminAreaRegistration();             var adminAreaContext = new AreaRegistrationContext(adminArea.AreaName, RouteTable.Routes);             adminArea.RegisterArea(adminAreaContext);              var defaultArea = new DefaultAreaRegistration();             var defaultAreaContext = new AreaRegistrationContext(defaultArea.AreaName, RouteTable.Routes);             defaultArea.RegisterArea(defaultAreaContext); <\/code><\/pre>\n<p>  <\/li>\n<li>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0443\u0431\u0438\u0440\u0430\u0435\u043c (\u043d\u0435 api).<\/li>\n<\/ul>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c.<\/p>\n<p>  \u0412\u0441\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"https:\/\/bitbucket.org\/chernikov\/lessons\">https:\/\/bitbucket.org\/chernikov\/lessons<\/a>    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/176021\/\"> http:\/\/habrahabr.ru\/post\/176021\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<b>\u0426\u0435\u043b\u044c \u0443\u0440\u043e\u043a\u0430:<\/b> \u0418\u0437\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438. \u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 Areas \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u041f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h5>Controller \u0438 Action.<\/h5>\n<p>  \u0412\u0435\u0431-\u0441\u0430\u0439\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u0442\u0440\u0430\u043d\u0438\u0446. \u0412\u043e\u043e\u0431\u0449\u0435, \u0432\u0435\u0431-\u0441\u0430\u0439\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u043d\u0435 \u0438\u0437 \u0441\u0442\u0440\u0430\u043d\u0438\u0446, \u0430 \u0438\u0437 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043d\u043e \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u043c\u0435\u0442\u044c. <\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0443 \u043a\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432\u044b\u0437\u0432\u0430\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u044d\u0442\u043e controller \u0438 action. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0432 App_Start\/RouteConfig.cs:   <\/p>\n<pre><code class=\"cs\">routes.MapRoute(                 name: &quot;Default&quot;,                 url: &quot;{controller}\/{action}\/{id}&quot;,                 defaults: new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }             ); <\/code><\/pre>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-176021","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/176021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176021"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/176021\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}