2015-09-12 13 views
5

Aşağıdaki rotayı kullanıyorum ve oyun başlıklarını bunlardaki herhangi bir karakterle ele alabilmesi gerekiyor. URL'deki özel karakterlere izin vermek için web.config sayfamda uygun şekilde etkinleştirilmiş şeyler var ve URL'lerimin yalnızca özel MVC Routes yerine temel sorgu dizelerini kullanırken çalıştığını doğruladı. Ancak, Html.Action üzerinden bir çocuk eylem yükü eklediğimde aşağıdaki yığın izini alıyorum. İşte Özel Karakterler ve Çocuk Eylemiyle MVC Yönlendirme Parametreleri

routes.MapRoute("Game", "Game/Game/{id}", new { controller = "Game", action = "Game", id = ""}, new { id = @"[^\.]*" }); 

sonra benim Kontrolör yöntemi ve görünümü (ben çok onları dumbed, ancak hata oluşmaya devam eder), bu yolla çağrılan ve görünümünün kendi içinde bile jilet çağrılan ama ben aşağıdaki hata/yığın izini edinin.

Denetleyici:

public ActionResult Game(string id) 
    { 
    { 
     Game currentGame = _ugdb.Games.FirstOrDefault(g => g.GameName.Equals(id)); 
     return View(currentGame); 

    } 

Görünüm:

@model UltimateGameDB.Domain.Entities.Game 
@Html.Action("SearchBar", "Search") 
<span>@Model.GameName</span> 

Çocuk Eylem Kontrolörü Yöntemi (çağrılmadığı): Burada

[ChildActionOnly] 
    public ActionResult SearchBar() 
    { 
    ViewBag.TotalGames = _ugdb.Game_Platform.Count() + _ugdb.Games.Count(g => g.Game_Platform.Count == 0); 
    return PartialView("_SearchBar"); 
    } 

bir kaç yollarının bazı örnekler çalışmıyor:

http://localhost:58386/Game/Game/Sid%20Meier%27s%20Civilization%3a%20Beyond%20Earth

http://localhost:58386/Game/Game/Starcraft%20II%3a%20Heart%20of%20the%20Swarm

temelde özel bir karaktere sahiptir benim veritabanında herhangi bir oyun aynı hatayı veriyor rağmen. Bunun bir demet googled var ve bu rota işe yaramaz neden anlamaya gibi olamaz

System.NotSupportedException: The given path's format is not supported.

at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path) at System.Web.InternalSecurityPermissions.PathDiscovery(String path) at System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) at System.Web.HttpRequest.MapPath(VirtualPath virtualPath) at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, Object routeValues) at ASP._Page_Views_Game_Game_cshtml.Execute() in d:\TFS Workspace\UltimateGameDB\Dev\Source\ULTIMATEGAMEDB\UltimateGameDB.WebUI\Views\Game\Game.cshtml:line 257 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.StartPage.RunPage() at System.Web.WebPages.StartPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList 1 filters, ActionResult actionResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.b__1c() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) at System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.End() at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.End() at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.End() at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)

şu şekildedir: gerçek hata mesajıdır.

Şimdiden teşekkürler!

+1

Kısıtlama parametresine mi ihtiyacınız var? Bu son parametreyi kapatmayı denediniz mi? – drneel

+1

Rota tanımınız bana iyi görünüyor. Karşılaşılmayan bir URL örneği verebilir misiniz? – Peter

+1

Lütfen daha fazla bilgi verin. Sadece örnek mvc uygulaması oluşturmayı ve rotanızı eklemeyi denedim. http: // localhost/oyun/oyun/gameid benim için iyi çalışıyor. –

cevap

5

öğenizde relaxedUrlToFileSystemMapping="true" ayarını deneyin. HttpRuntimeSection.RelaxedUrlToFileSystemMapping özellik için Dokümanlar

<httpRuntime targetFramework="4.5" 
    requestPathInvalidCharacters="" 
    requestValidationMode="2.0" 
    relaxedUrlToFileSystemMapping="true" /> 

: Daha önce eklediğiniz nitelikler ile, muhtemelen böyle bir şey olacaktır

Gets or sets a value that indicates whether the URL in an HTTP request is required to be a valid Windows file path.

Somewhere ASP.NET çalışma zamanı derinliklerinde o istekte bulunmadan önce istenen URL'yi fiziksel bir yola çevirmeye çalışır. Bu ayar, fiziksel yolun geçerli olmaması durumunda havaya uçmasını engelliyor gibi görünüyor.

+0

Bir cankurtaran, sonsuza kadar bunu anlamaya çalıştım, bu kadar çok işe yaradı, teşekkürler! –