2016-07-19 20 views
0

私のプロジェクトでは、Areasプロジェクト管理者を作成しました。ASP.NET MVC 5の角度html5mode

html5modeがfalseの場合、url localhost:xxxx/Adminがうまくいきます。
しかし、html5modeがtrueの場合、それは動作しておらず、自宅にリダイレクトされます。

$locationProvider.html5Mode({ 
     enabled: true, 
     requireBase: false 
    }); 

のweb.config

<rewrite> 
      <rules> 
       <rule name="angularjs routes" stopProcessing="true"> 
        <match url=".*" /> 
        <conditions logicalGrouping="MatchAll"> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
         <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> 
        </conditions> 
        <action type="Rewrite" url="/" /> 
       </rule> 
      </rules> 
     </rewrite> 

HomeController.cs

using System.Web.Mvc; 

namespace SuperPaint.Areas.Admin.Controllers 
{ 
    public class HomeController : Controller 
    { 
     // GET: Admin/Home 
     public ActionResult Index() 
     { 
      return View(); 
     } 
    } 
} 

AdminAreaRegistration.cs

using System.Web.Mvc; 
using System.Web.Optimization; 

namespace SuperPaint.Areas.Admin 
{ 
    public class AdminAreaRegistration : AreaRegistration 
    { 
     public override string AreaName => "Admin"; 

     public override void RegisterArea(AreaRegistrationContext context) 
     { 
      RegisterRoutes(context); 
      RegisterBundles(); 
     } 

     private void RegisterRoutes(AreaRegistrationContext context) 
     { 
      RouteConfig.RegisterRoutes(context); 
     } 

     private void RegisterBundles() 
     { 
      BundleConfig.RegisterBundles(BundleTable.Bundles); 
     } 
    } 
} 

RouteConfig.cs

using System.Web.Mvc; 

namespace Project.Areas.Admin 
{ 
    internal static class RouteConfig 
    { 
     internal static void RegisterRoutes(AreaRegistrationContext context) 
     { 
      context.MapRoute(
       "Admin_default", 
       "Admin/{controller}/{action}/{id}", 
       new { action = "Index", controller = "Home", id = UrlParameter.Optional }, 
       new[] { "Project.Areas.Admin.Controllers" } 
      ); 
     } 
    } 
} 
+0

はあなたにも、管理者ページのコードを与えることができますか? – Nzall

答えて

0
にあなたのweb.configファイルのルールを変更し

<rules> 
      <rule name="IgnoreAdminURLs" stopProcessing="true"> 
       <match url ="(admin\/)" ignoreCase="true" /> 
       <action type="None" /> 
      </rule> 
      <rule name="angularjs routes" stopProcessing="true"> 
       <match url=".*" /> 
       <conditions logicalGrouping="MatchAll"> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="/" /> 
      </rule> 
</rules> 
+0

ご協力ありがとうございます。それは働いている。 –