C# 如何解决;ASPx未定义“ASPx”;变成“的错误”;潜在危险的请求。路径“;例外?
背景 我对MVC站点中的绑定和重定向有问题。站点项目包括默认路由中的桌面版本和单独区域中的移动友好主题。两个主题都使用捆绑配置,如下所示C# 如何解决;ASPx未定义“ASPx”;变成“的错误”;潜在危险的请求。路径“;例外?,c#,jquery,asp.net-mvc,jquery-mobile,devexpress,C#,Jquery,Asp.net Mvc,Jquery Mobile,Devexpress,背景 我对MVC站点中的绑定和重定向有问题。站点项目包括默认路由中的桌面版本和单独区域中的移动友好主题。两个主题都使用捆绑配置,如下所示 // BundleConfig.cs using System.Web.Optimization; public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptB
// BundleConfig.cs
using System.Web.Optimization;
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/jquerymobile").Include(
"~/Scripts/jquery-1.*", "~/Scripts/jquery-ui-1.*", "~/Scripts/jquery.mobile-{version}.js"));
bundles.Add(new StyleBundle("~/Content/jquerymobile/css").Include(
"~/Content/jquery.mobile-{version}.css"));
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/Site.css"));
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
}
在Global.asax中注册的捆绑包如下:
// Global.asax
protected void Application_Start()
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
注意,由于jQuery.mobile-1.4.5
中的“bind not a function”错误,我对桌面(当前为3.1.1)和移动主题(当前为1.12.4)使用了不同的jQuery版本(如果使用版本3)()
两个主题的布局视图如下所示:
桌面(带有DevExpress主题)
但是,如果我单击console中提供的右侧的错误链接(参见上图),它将显示一个查看源页面,其中包含一些错误详细信息:
System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (>).
[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (>).]
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9560004
at System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53
如何解决此区域重定向问题
注意:我搜索了异常详细信息()中给出的消息,并怀疑在重定向到根站点时提交了非法字符,但我无法找出移动布局页面的哪个部分导致了问题。在jQuery mobile framework中,要启用动画页面转换,所有指向外部页面的链接都将通过Ajax加载。该框架解析链接的href以形成Ajax请求。所有这些都是由jquerymobile自动完成的。我认为这种机制可能是您的问题的原因。
您可以尝试将属性数据ajax=“false”添加到“桌面”链接。它将导致整个页面刷新,没有动画转换
@Html.ActionLink(“桌面视图”、“索引”、“主页”、新{area=”“、}、新{id=“button”、数据_ajax=“false”})
好吧,通过在按钮链接上添加数据ajax
属性,它现在可以正常工作了,但我很好奇,为什么即使我在移动布局()中有$.mobile.ajaxEnabled=false
?我想原因是你在实际加载jQuery mobile之前就绑定到了mobileinit。您应该尝试将其绑定到$(document).ready事件
@using System.Web.Optimization
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@{
@Scripts.Render("~/bundles/jquerymobile");
@Scripts.Render("~/bundles/jqueryval");
@Styles.Render("~/Content/themes/base/css");
@Styles.Render("~/Content/jquerymobile/css");
}
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
</head>
<body>
<div data-role="page" data-theme="b" style="overflow:scroll">
<div data-role="header">
<h1>Mobile HRM</h1>
</div>
<div data-role="header" style="text-align:center">
@if (IsSectionDefined("Title"))
{
@RenderSection("Title")
}
</div>
<div data-role="content" style="overflow:scroll">
@RenderBody()
</div>
<div data-role="footer" style="text-align:center">
@* this link redirects to Desktop theme as root site *@
@Html.ActionLink("Desktop View", "Index", "Home", new { area = "" }, new { id = "button" })
</div>
</div>
<script type="text/javascript">
$(document).on('mobileinit', function () {
$.mobile.ajaxEnabled = false;
});
$(document).on('pageshow', '[data-role=page]', function () {
$(window).resize();
});
</script>
@RenderSection("Scripts", required: false)
</body>
</html>
( window.execScript || function( data ) {
window[ "eval" ].call( window, data ); // jscs:ignore requireDotNotation
})( data );
System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (>).
[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (>).]
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9560004
at System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53