当我点击IE10中的后退按钮或Win7上的Chrome时,它没有达到我在MVC控制器中的断点.IE开发人员工具中的"网络"选项卡显示其未修改304且Fiddler未捕获请求.
我期待回帖,所以我可以在我的控制器中工作.就我而言,错误是:
我试过把它放在我的控制器中,没有成功:
this.HttpContext.Response.CacheControl = "private";
this.HttpContext.Response.Cache.SetMaxAge(TimeSpan.FromSeconds(0));
public ActionResult Index()
{
// Get: /Home/Index
if (this.User.Identity.IsAuthenticated)
{
// send the user to the GlobalAssetDashboard
return this.RedirectToAction(
"GlobalAssetDashboard",
"Dashboard",
new
{
area = "DashboardArea"
});
}
return this.View("Login");
}
public ActionResult Login()
{
// GET: /Home/Login
if (this.User.Identity.IsAuthenticated)
{
// send the user to the GlobalAssetList
return this.RedirectToAction(
"GlobalAssetDashboard",
"Dashboard",
new
{
area = "DashboardArea"
});
}
return this.View("Login", new LoginModel());
}
Run Code Online (Sandbox Code Playgroud)
有没有办法强制回发或检测到这种情况并导致JavaScript刷新?或者我的控制器方法实现不正确?
问题:我没有太多关于MSTest V2的示例或文档.使用Assert.ThrowsExceptionAsync的正确方法是什么?
public void GetPlaylistByIdAsync_NonExistingPlaylist_ThrowsPlaylistNotFoundException()
{
var playlistId = Guid.NewGuid().ToString();
var manager = PlaylistTargetsFakeFactory.GetPlaylistTargetFusionManager();
Assert.ThrowsException<PlaylistNotFoundException>(async () =>
{
await manager.GetPlaylistByIdAsync(playlistId);
});
}
Run Code Online (Sandbox Code Playgroud)
这也未通过测试:
Assert.ThrowsException<PlaylistNotFoundException>(() =>
{
return manager.GetPlaylistByIdAsync(playlistId);
});
Run Code Online (Sandbox Code Playgroud)
"消息:Assert.ThrowsException失败.没有抛出异常.预计会出现PlaylistNotFoundException异常."
这对我来说是失败的,即使我已经调试它并且确实抛出了异常.
由于这仍然是RC,因此可能存在错误.我在2次测试中有这个我试图转换所以我可以使用VS 2017.
更新:通过.
[TestMethod]
public async Task GetPlaylistByIdAsync_NonExistingPlaylist_ThrowsPlaylistNotFoundException()
{
var playlistId = Guid.NewGuid().ToString();
var manager = PlaylistTargetsFakeFactory.GetPlaylistTargetFusionManager();
//Assert.ThrowsException<PlaylistNotFoundException>(() =>
//{
try
{
await manager.GetPlaylistByIdAsync(playlistId);
Assert.Fail();
}
catch (PlaylistNotFoundException)
{
Assert.IsTrue(true);
}
//});
}
Run Code Online (Sandbox Code Playgroud)
更新2:在Stephen Cleary的回答之后,我做了这个改变.谢谢你指出我的误用.我已经改变了一段时间,因为我得到"消息:测试方法Daktronics.UserPortal.Test.Models.Helpers.PlaylistTargetFusionManagerTests.GetPlaylistByIdAsync_NonExistingPlaylist_ThrowsPlaylistNotFoundException引发异常:System.MissingMethodException:找不到方法:'System.Threading.Tasks.Task 1<!!0> Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsExceptionAsync(System.Func
1)'. " 当我运行测试.
[TestMethod]
[TestCategory(TestCategories.CSharp)]
[TestCategory(TestCategories.PlaylistTargets)] …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我升级的Asp.Net Core RC2应用程序的静态void main中获取配置值.在Startup的构造函数中,我可以注入IHostingEnvironment,但不能在静态方法中执行此操作.我正在关注https://github.com/aspnet/KestrelHttpServer/blob/dev/samples/SampleApp/Startup.cs,但想在appsettings中使用我的pfx密码(是的,它应该在用户机密中并且会到达那里最终).
public Startup(IHostingEnvironment env){}
public static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddJsonFile("hosting.json");
builder.AddEnvironmentVariables();
var configuration = builder.Build();
...
var host = new WebHostBuilder()
.UseKestrel(options =>
{
// options.ThreadCount = 4;
options.NoDelay = true;
options.UseHttps(testCertPath, configuration["pfxPassword"]);
options.UseConnectionLogging();
})
}
Run Code Online (Sandbox Code Playgroud) 我使用Asp.Net Core RC2和Kestrel作为我的Web服务器.我需要确保使用no-cache标头响应请求(在这种情况下所有这些请求),以便浏览器获得最新版本(而不是304).
在Startup中有没有办法配置Kestrel或将此步骤注入管道?
编辑:在我的情况下,no-store可能是更好的选择:https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching "no-store不允许缓存响应并且必须在每次请求时全部取出."
我正在尝试使用XDocument和XPathEvaluate从woot.com提要中获取值.我正在处理其他名称空间,但这个例子给了我一些问题.
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<category text="Comedy" xmlns="http://www.itunes.com/dtds/podcast-1.0.dtd">
</category>
<!-- this is a problem node, notice 'xmlns=' --!>
Run Code Online (Sandbox Code Playgroud)
所以我试试这个:
XmlNamespaceManager man = new XmlNamespaceManager(nt);
man.AddNamespace("ns", "http://www.w3.org/2000/xmlns/");
// i've also tried man.AddNamespace("ns", string.Empty);
xDocument.Namespace = man;
var val = xDocument.XPathEvaluate("/rss/channel/ns:category/@text", xDocument.Namespace);
Run Code Online (Sandbox Code Playgroud)
val始终为null.我正在使用ns:来自VS 2010 XPath Navigator插件的建议.有关如何处理这个问题的任何想法?
我正在使用Silverlight 4.0(所以我需要调用异步并且不能直接使用EF)和WCF数据服务以及EF 4来建模数据库.我想进行一次调用并填充几个级别的属性.
假设我有以下设置(但这可能更深入):帐户 - 拥有零个或多个客户(和其他属性) - 客户拥有零个或多个地址(和其他属性)
我想带回1个有效负载,其中Accounts,Customers和Addresses都是急切加载并包含在那个有效负载中.
我想得到:Accounts.Expand("Customers").其中(a => a.Id == 1); 这将返回帐户和客户填充的有效内容.如何在同一个呼叫中包含地址?
我想在Xamarin的多个设备应用程序中使用相同的图像.
我有一个PCL核心库,并已开始使用MVVMCross.实现这一目标的最佳方法是什么?我可以将它们作为资源嵌入到Core库中并在我的Andriod/iOs项目中访问它,还是使用add作为链接更好?
如果服务器没有响应JSONP,我该如何处理?我已尝试使用$ .ajax的几个选项,但无法使其工作.
//var url = 'https://coinbase.com/api/v1/currencies/exchange_rates';
var url = 'http://blockchain.info/ticker';
$.ajax({
type: 'GET',
url: url,
//jsonpCallback: 'jsonCallback',
contentType: 'application/json',
//async: false,
//dataType: 'jsonp',
//xhrFields: {
// for CORS?
// withCredentials: false
//},
success: function (json) {
debugger;
},
error: function (json) {
debugger;
}
});
Run Code Online (Sandbox Code Playgroud) c# ×2
xpath ×2
.net ×1
ajax ×1
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
cors ×1
jsonp ×1
linq-to-xml ×1
mstest ×1
mvvmcross ×1
postback ×1
silverlight ×1
unit-testing ×1
xamarin ×1
xml ×1