在Javascript中从路径中删除查询字符串的简单方法是什么?我见过一个使用window.location.search的Jquery插件.我不能这样做:在我的情况下,URL是一个从AJAX设置的变量.
var testURL = '/Products/List?SortDirection=dsc&Sort=price&Page=3&Page2=3&SortOrder=dsc'
Run Code Online (Sandbox Code Playgroud) 我的一些版本中有这个恼人的错误.
项目中没有错误,因为如果我再次构建,那么问题就会消失.仅当站点部署到Windows 2008 Server时,才会显示该消息.
我首先想到的可能是临时文件的问题,但事实并非如此.我将构建部署到不同的Web,但仍然出现错误.
该错误出现在网站的随机操作上.大多数时间构建都没问题,但每个第3或第4个构建都会产生运行时错误.
我在发布模式下使用WebdeploymentProject构建.视图已预编译.
它不是在ASP.NET MVC中,当使用正确的类型化对象呈现页面时遇到错误的类型错误,因为视图具有完全不同的名称.
我如何调试此问题或如何为此获得帮助?
这是我的WebDeploymentProject
<!--
Microsoft Visual Studio 2008 Web Deployment Project
http://go.microsoft.com/fwlink/?LinkID=104956
-->
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E5E14CEB-0BCD-4203-9A5A-34ABA9C717EA}</ProjectGuid>
<SourceWebPhysicalPath>..\B2CWeb</SourceWebPhysicalPath>
<SourceWebProject>{3E632DB6-6DB3-4BD0-8CCA-12DE67165B48}|B2CWeb\B2CWeb.csproj</SourceWebProject>
<SourceWebVirtualPath>/B2CWeb.csproj</SourceWebVirtualPath>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>.\Debug</OutputPath>
<EnableUpdateable>false</EnableUpdateable>
<UseMerge>true</UseMerge>
<SingleAssemblyName>B2CWeb_Build</SingleAssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<OutputPath>..\B2CWeb_Deploy\</OutputPath>
<EnableUpdateable>false</EnableUpdateable>
<UseMerge>true</UseMerge>
<SingleAssemblyName>B2C_Web</SingleAssemblyName>
<ContentAssemblyName>
</ContentAssemblyName>
<DeleteAppCodeCompiledFiles>false</DeleteAppCodeCompiledFiles>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.targets" /> …
Run Code Online (Sandbox Code Playgroud) 我的地图是:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with params
new { controller = "Home", action = "Index", id = "" } // Param defaults
);
Run Code Online (Sandbox Code Playgroud)
如果我使用URL http://localhost:5000/Home/About/100%2f200
,则没有匹配的路由.我将URL更改为http://localhost:5000/Home/About/100
然后再次匹配路由.
有没有简单的方法来处理包含斜杠的参数?其他转义值(空格%20
)似乎有效.
编辑:
编码Base64对我有用.它使URL变得丑陋,但现在还可以.
public class UrlEncoder
{
public string URLDecode(string decode)
{
if (decode == null) return null;
if (decode.StartsWith("="))
{
return FromBase64(decode.TrimStart('='));
}
else
{
return HttpUtility.UrlDecode( decode) ;
}
}
public string UrlEncode(string encode)
{
if (encode == null) return null;
string encoded = …
Run Code Online (Sandbox Code Playgroud) 我有一个需要删除所有文件和文件夹的文件,除了一小部分文件和文件夹.
我已经可以排除文件列表,但是没有找到排除文件夹的方法.
这是文件夹结构:
|-C:\temp
\-C:\temp\somefile.txt
\-C:\temp\someotherfile.txt
| |-C:\temp\foldertodelete
\-C:\temp\foldertodelete\file1.txt
| |-C:\temp\foldertokeep
| \-C:\temp\foldertokeep\file2.txt
Run Code Online (Sandbox Code Playgroud)
我想保留somefile.txt和文件夹foldertokeep及其内容.
这就是我现在所拥有的:
Get-ChildItem -Path 'C:\temp' -Recurse -exclude somefile.txt | Remove-Item -force -recurse
Run Code Online (Sandbox Code Playgroud)
这真的不删除somefile.txt.有没有办法从删除列表中排除文件夹foldertokeep及其内容?
我使用了接受routeValues的Begin.Form重载
<%
RouteValueDictionary routeValues = ViewContext.RouteData.Values;
routeValues.Add("TestRoute1", "test");
using (Html.BeginForm(
"Category",
"Home",
routeValues,
FormMethod.Post
))
{ %>
<input type="submit" value="submit" name="subform" />
<% }%>
Run Code Online (Sandbox Code Playgroud)
这很好用,并将formtag呈现为:
<form method="post" action="/Home/Category?TestRoute1=test">
Run Code Online (Sandbox Code Playgroud)
我需要更改htmlAttributes,这就是我使用的原因:
<%
RouteValueDictionary routeValues = ViewContext.RouteData.Values;
routeValues.Add("TestRoute1", "test");
using (Html.BeginForm(
"Category",
"Home",
routeValues,
FormMethod.Post,
new {id="frmCategory"}
))
{ %>
<input type="submit" value="submit" name="subform" />
<% }%>
Run Code Online (Sandbox Code Playgroud)
结果完全错了:
<form method="post" id="frmTyreBySizeCar" action="/de/TyreSize.mvc/List?Count=12&Keys=System.Collections.Generic.Dictionary%....
Run Code Online (Sandbox Code Playgroud)
我可以在Formhelper的源代码中看到原因是什么.
有两个重载适用于我给定的参数:
public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method, object htmlAttributes)
public static MvcForm …
Run Code Online (Sandbox Code Playgroud) 我试着播放一个mp3文件.如果我在本地网络服务器上更改文件的路径,则此方法有效,但如果我在Android设备上运行此操作,则不会播放声音并且不会显示错误.
我很害羞找不到mp3文件,但我仍然不知道如何修复它.
这是Html
<body>
<audio id="successSound" src="/android_asset/www/sound/successSound.mp3" type="audio/mpeg" ></audio>
<audio id="errorSound" src="/android_asset/www/sound/errorSound.mp3" type="audio/mpeg" ></audio>
<!-- some more UI -->
</body>
Run Code Online (Sandbox Code Playgroud)
这是Javascript
document.getElementById('errorSound').play();
Run Code Online (Sandbox Code Playgroud)
这是文件结构
phonyapp
`-- www
`-- index.html
|-- sound
| |-- errorSound.mp3
| `-- successSound.mp3
|-- res
`-- spec
Run Code Online (Sandbox Code Playgroud)
编辑1
我试过了
<audio id="successSound" src="sound/successSound.mp3" type="audio/mpeg" ></audio>
Run Code Online (Sandbox Code Playgroud)
这在我的本地网络服务器上使用chrome,但在Android上没有.
我试过了
<audio id="successSound" src="http://html5multimedia.com/media/sayHello.mp3" type="audio/mpeg" ></audio>
Run Code Online (Sandbox Code Playgroud)
这很有效,但我需要播放本地文件
我有一个ActionFilter来检查URL中的参数是否有效.如果它无效,我必须渲染一个视图.我不想重定向,因为我仍然需要ActionExecutingContext.可以这样做吗?
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Guid processIdentifier = (Guid)filterContext.RouteData.Values["processIdentifier"];
//if processIdentifier not found render a view with message and some other objects in ViewData
filterContext.Controller.ViewData.ModelState.AddModelError("WrongProcessIdentifier", "The process-id you supplied is not valid");
base.OnActionExecuting(filterContext);
}
Run Code Online (Sandbox Code Playgroud) 我的目标行动需要https.我已经有一个过滤器,如果请求通过http进入,重定向到https,但我更喜欢从一开始就通过https发送请求.
编辑
Darin得到了一个答案(现在更新到其他地方),他问我为什么称之为http的第一个动作.他在那里有一个很好的观点,我刚刚更新了几个链接.这是解决我的问题最简单,最安全的方法.
一旦我找到时间来评估çağdaş答案,我会用这个作为正确的答案,因为我猜这对其他人感兴趣(...包括我在将来)
我使用以下ViewModel
<script type='text/javascript'>
$(function () {
var dropdownCtor = function (text, value, defaultValue) {
this.text = text;
this.value = value;
this.defaultValue = defaultValue;
};
var productsViewCtor = function () {
var self = this;
this.productType = ko.observable();
this.productTypes = ko.observableArray(['Summer', 'Winter']);
this.products = ko.observableArray();
this.product = ko.observable();
this.productType.subscribe(function (newProductType) {
$.post(
'/Home/GetProducts',
{ productType: newProductType },
function (resultProducts) {
self.products(resultProducts);
self.product(resultProducts[2]);
});
} .bind(this));
}
var productViewModel = new productsViewCtor();
ko.applyBindings(productViewModel);
});
Run Code Online (Sandbox Code Playgroud)
以下Html
<h3> Your Products:</h3>
<p>
<span><select data-bind="options: productTypes, …
Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×5
c# ×2
.net ×1
android ×1
asp.net ×1
cordova ×1
html-encode ×1
https ×1
javascript ×1
jquery ×1
knockout.js ×1
php ×1
powershell ×1
urlencode ×1