我正在使用Microsoft提供的SPA模板和JavaScript服务构建一个Angular2应用程序(https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net -core-with-javascriptservices /).
我想使用Angular Material而不是Bootstrap来进行样式/主题化,但是我无法让它工作.
遵循设置指南(https://material.angular.io/guide/getting-started)非常简单,但是当涉及到包含主题资源(@ angular/material/prebuilt-themes/...)时在wwwroot dist输出中的npm包使它们可用于应用程序我完全失去了.
我认为这只是修改WebPack配置的一种情况,但是经过一两个小时的修补和谷歌搜索之后,我就无法理解该怎么做了.
任何人都能指出我正确的方向吗?
NB.请不要建议将我需要的文件复制到wwwroot或链接到CDN等.
我的Web应用程序(http://www.something.com/social/competition/)当前正在请求WebResource.axd文件,如下所示:
<script src="/WebResource.axd?d=xxx" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
当我们在Netscaler中使用urlrewiting将"/ social"文件夹的所有请求转发到包含此应用程序的单独服务器场时,"/"根路径将无法正确解析,因为它将从某些内容请求资源.com app.
因此,我需要更改所请求脚本的URL以显式请求它:
<script src="/social/WebResource.axd?d=xxx" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
或使用相对路径请求它:
<script src="WebResource.axd?d=xxx" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经看过覆盖渲染方法,使用控制适配器和其他各种东西,但还没有到目前为止.请帮忙.
是的,我在这里有一些非常特别的东西......
ASP.NET 4页面具有以下属性:
protected QuickShopBag QuickShopBagInstance
{
get { return (QuickShopBag)ViewState["QuickShopBag"]; }
set { ViewState["QuickShopBag"] = value; }
}
Run Code Online (Sandbox Code Playgroud)
在初始Page_Load()
in(!Page.IsPostBack
)期间,QuickShopBagInstance
填充并ViewState
保存.
但是,当您在页面上执行回发时,从回发Button_OnClick()
事件访问时ViewState为空!
我已经检查了Request.Form,确定该_Viewstate
值已存在且已填充.我也通过解析器运行了这个值,它确实包含了预期的数据,页面ViewStateEnabled="true"
和新的.NET 4 ViewStateMode="Enabled"
.
我已经继续覆盖LoadViewState方法以检查它是否正在触发,它似乎不是.
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
}
Run Code Online (Sandbox Code Playgroud)
我真的很遗憾可能是什么问题.有任何想法吗?
我正在尝试使用NSubstitute来模拟 HttpClient。这是代码:
public static HttpClient GetHttpClient(bool isSucess = true, string methodType = "GET")
{
var mockIHttpMessageHandler = Substitute.For<IMockHttpMessageHandler>();
var mockHttpMessageHandler = Substitute.For<MockHttpMessageHandler>(mockIHttpMessageHandler);
var httpResponse = Substitute.For<HttpResponseMessage>();
httpResponse.Content = new StringContent("\"test\"");
if (isSucess)
httpResponse.StatusCode = HttpStatusCode.OK;
else
httpResponse.StatusCode = HttpStatusCode.NotFound;
var mockHttpClient = Substitute.For<HttpClient>(mockHttpMessageHandler);
mockHttpClient.BaseAddress = new Uri("http://localhost");
if(methodType != "POST"){
mockHttpClient.GetAsync(Arg.Any<Uri>()).ReturnsForAnyArgs(httpResponse);
}
return mockHttpClient;
}
Run Code Online (Sandbox Code Playgroud)
但是,我在这一行遇到错误:
mockHttpClient.GetAsync(Arg.Any<Uri>()).ReturnsForAnyArgs(httpResponse);
Run Code Online (Sandbox Code Playgroud)
错误是
NSubstitute.Exceptions.RedundantArgumentMatcherException:'上次调用后留下了一些参数规范(例如 Arg.Is、Arg.Any)。
这通常是由于使用参数规范来调用 NSubstitute 无法处理的成员(例如非虚拟成员或对非替代实例的调用),或者出于指定调用以外的目的(例如使用 arg 规范作为返回值)。例如:
Run Code Online (Sandbox Code Playgroud)var sub = Substitute.For<SomeClass>(); var realType = new MyRealType(sub); // INCORRECT, arg spec …
我正在尝试实现一个大型对象缓存(最多500000),并且需要能够以两种不同的方式访问它们......
每个项目的关键由三个不同的字符串组成; ItemNumber,PubCode和SizeCode.在某些情况下,我将调用所有这三个值的匹配来返回单个对象.在其他情况下,我将仅在ItemNumber和PubCode上调用匹配,以便返回一组对象.
什么是最好的收藏品?
我考虑过只使用一个通用的对象列表(其中所有三个键值都是属性)并使用LINQ来查询它,但是我不相信这将是最有效的方法当你考虑集合的大小.
任何帮助将一如既往地受到赞赏!
我们使用以下模式来处理asp.net应用程序的通用对象的缓存.
private object SystemConfigurationCacheLock = new object();
public SystemConfiguration SystemConfiguration
{
get
{
if (HttpContext.Current.Cache["SystemConfiguration"] == null)
lock (SystemConfigurationCacheLock)
{
if (HttpContext.Current.Cache["SystemConfiguration"] == null)
HttpContext.Current.Cache.Insert("SystemConfiguration", GetSystemConfiguration(), null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration, new CacheItemUpdateCallback(SystemConfigurationCacheItemUpdateCallback));
}
return HttpContext.Current.Cache["SystemConfiguration"] as SystemConfiguration;
}
}
private void SystemConfigurationCacheItemUpdateCallback(string key, CacheItemUpdateReason reason, out object expensiveObject, out CacheDependency dependency, out DateTime absoluteExpiration, out TimeSpan slidingExpiration)
{
dependency = null;
absoluteExpiration = DateTime.Now.AddMinutes(1);
slidingExpiration = Cache.NoSlidingExpiration;
expensiveObject = GetSystemConfiguration();
}
private SystemConfiguration GetSystemConfiguration()
{
//Load system configuration
}
Run Code Online (Sandbox Code Playgroud)
问题是当负载不足(~100,000个用户)时,我们看到TTFB出现大幅跳跃,因为CacheItemUpdateCallback阻止所有其他线程执行,直到它完成从数据库刷新缓存.
所以我认为我们需要的是解决方案,当缓存到期后的第一个线程试图访问它时,会触发异步线程来更新缓存,但仍允许所有其他执行线程从旧缓存中读取,直到它具有成功更新. …
一个相当明星的前瞻性问题,或者我认为......
select="../Store"
返回包含我需要的所有节点的节点集.然后,我需要计算附加到Store节点的name属性的字符串长度.
我本以为会这样:
select="string-length(../Store/@name)"
但这只返回第一个节点的字符串长度.
有任何想法吗?
我有一个相当基本的 Azure 搜索索引,其中包含多个可搜索字符串数据的字段,例如 [abridged]...
"fields": [
{
"name": "Field1",
"type": "Edm.String",
"facetable": false,
"filterable": true,
"key": true,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": null,
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
{
"name": "Field2",
"type": "Edm.String",
"facetable": false,
"filterable": true,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": "en.microsoft",
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
}
]
Run Code Online (Sandbox Code Playgroud)
Field1
加载了字母数字 id 数据并Field2
加载了英语字符串数据,特别是记录的名称/标题。searchMode=all
还用于确保结果的准确性。
假设被索引的记录之一具有以下Field2
数据:BA (Hons) in Business, Organisational Behaviour and Coaching …
我的网站有多个域:
在生产中,我希望主域为http://www.example.com,并且所有其他关联域都自动重定向到主域。
从历史上看,我会使用 URLRewrite 来完成此操作,但我相信 DotNetCore 中不存在这种情况。
那么...我该怎么做呢?
另外,我不希望这影响开发环境。
c# ×6
asp.net ×3
.net ×1
.net-core ×1
angular ×1
asp.net-core ×1
asp.net-mvc ×1
azure ×1
httpclient ×1
javascript ×1
lucene ×1
nsubstitute ×1
recaptcha ×1
unit-testing ×1
virtual ×1
webforms ×1
webpack ×1
xml ×1
xpath ×1
xslt ×1