我有一个Web API方法,它接受一个JObject
属性的任意json有效负载.因此我不知道将要发生什么,但我仍然需要将其转换为.NET类型.我希望有一个Dictionary<string,object>
能够以任何方式处理它的方式.
我已经搜索了很多,但找不到任何东西,最终开始一个混乱的方法来进行这种转换,按键,值按值.有一个简单的方法吗?
输入 - >
JObject person = new JObject(
new JProperty("Name", "John Smith"),
new JProperty("BirthDate", new DateTime(1983, 3, 20)),
new JProperty("Hobbies", new JArray("Play football", "Programming")),
new JProperty("Extra", new JObject(
new JProperty("Foo", 1),
new JProperty("Bar", new JArray(1, 2, 3))
)
)
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在使用域模型,并且正在思考我们在.NET中实现这两种方法的各种方法.你最喜欢的策略是什么?
这是我目前的实施:
public override bool Equals(object obj)
{
var newObj = obj as MyClass;
if (null != newObj)
{
return this.GetHashCode() == newObj.GetHashCode();
}
else
{
return base.Equals(obj);
}
}
// Since this is an entity I can use its Id
// When I don't have an Id, I usually make a composite key of the properties
public override int GetHashCode()
{
return String.Format("MyClass{0}", this.Id.ToString()).GetHashCode();
}
Run Code Online (Sandbox Code Playgroud) 当我尝试推送时,我的NuGet服务器正在抛出405 Not Allowed.至少,这就是NuGet控制台所说的:
Failed to process request. 'Method Not Allowed'.
The remote server returned an error: (405) Method Not Allowed..
Run Code Online (Sandbox Code Playgroud)
但是当我看到Fiddler的实际HTTP响应时,问题似乎完全不同:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code></code>
<message xml:lang="en-US">The URL representing the root of the service only supports GET requests.</message>
</error>
Run Code Online (Sandbox Code Playgroud)
关于可能发生的事情的任何想法?
谢谢!
有时我的网站上的一些请求开始挂起Session模块的RequestAcquireState状态.当螺旋开始所有请求超时时,我们需要在受影响的服务器上重新启动IIS.
我调查了很多,我得到的唯一结论是,当应用程序试图访问存储在Session中的用户数据时,某种程度上发生了死锁.
我能想到解决此问题的唯一选择是减少或停止在我的应用程序中使用Sessions.这是计划的一部分,但在我们完成之前需要一段时间.
我们使用IIS 7.5运行6台机器,在我们的负载平衡中运行proc StateServer和服务器亲缘关系.
有关如何解决此问题的任何提示或完全修复它而无需完全删除Sessions?
当我偶然发现FormsAuthenticationTicket.Version属性时,我在应用程序中创建了我的身份验证机制.文档没有举例说明任何用例,我没有找到任何其他用途的参考.
有人用过吗?
谢谢
我使用Nhibernate 2.1.2.4000 GA与Nhibernate.Linq 1.0和最新版本的FluentNhibernate从github上的master下载.
我正在做一些测试,每当我尝试删除由linq查询检索的实体时,我收到此错误:
没有持久性:NHibernate.Linq.Query`1 [[Employees.Core.Entities.Employee,Employees.Core,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]
所有其他操作(插入,更新和选择)看起来很好;
我的实体类:
public class Employee
{
public Employee()
{
}
public virtual Int32 Id { get; private set; }
public virtual String Name { get; set; }
public virtual String SayHello()
{
return String.Format("'Hello World!', said {0}.", Name);
}
}
Run Code Online (Sandbox Code Playgroud)
映射类:
public class EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
Id(x => x.Id);
Map(x => x.Name)
.Not.Nullable()
.Length(50);
}
}
Run Code Online (Sandbox Code Playgroud)
组态:
Assembly mappingsAssemly = Assembly.GetExecutingAssembly();
return Fluently.Configure() …
Run Code Online (Sandbox Code Playgroud) 功能标志是我经常使用的东西,但在我正在开发的这个新项目开始之前,从未真正考虑过它.
我通常在我的web.config文件中使用大量键来实现它,但这种方法有两个主要缺点:
克服这些问题的最佳方法是什么?
我使用vue add quasar
.
现在我尝试使用Loading 插件,但无法让它工作。
以下是我与 Quasar/Vue 设置相关的内容:
import { Quasar } from 'quasar'
Vue.use(Quasar, {
config: {},
components: { /* not needed if importStrategy is not 'manual' */ },
directives: { /* not needed if importStrategy is not 'manual' */ },
plugins: {},
cssAddon: true,
extras: [
'ionicons-v4',
'material-icons',
'material-icons-outlined',
'material-icons-round',
'material-icons-sharp',
'mdi-v3',
'eva-icons',
'fontawesome-v5',
'themify'
]
})
Run Code Online (Sandbox Code Playgroud)
我尝试了以下选项但无济于事。有任何想法吗?
import { Quasar } from 'quasar'
Vue.use(Quasar, {
...,
framework: {
plugins: [
'Loading'
]
}, …
Run Code Online (Sandbox Code Playgroud) 我正在构建一系列将由多个应用程序使用的WCF服务.因此,我正在尝试定义一个公共库来访问WCF服务.
知道不同用户发出的每个服务请求应该使用一个不同的Channel我正在考虑缓存Channel per-request(HttpContext.Current.Items
)并缓存ChannelFactory用于创建每个Application(HttpApplication.Items
)的通道,因为我可以创建多个通道相同ChannelFactory
.
但是,在关闭ChannelFactory和Channel时,我对这个缓存机制有疑问.
这是我用来管理这个的代码:
public class ServiceFactory
{
private static Dictionary<string, object> ListOfOpenedChannels
{
get
{
if (null == HttpContext.Current.Items[HttpContext.Current.Session.SessionID + "_ListOfOpenedChannels"])
{
HttpContext.Current.Items[HttpContext.Current.Session.SessionID + "_ListOfOpenedChannels"] = new Dictionary<string, object>();
}
return (Dictionary<string, object>)HttpContext.Current.Items[HttpContext.Current.Session.SessionID + "_ListOfOpenedChannels"];
}
set
{
HttpContext.Current.Items[HttpContext.Current.Session.SessionID + "_ListOfOpenedChannels"] = value;
}
}
public static T CreateServiceChannel<T>()
{
string key = typeof(T).Name;
if (ListOfOpenedChannels.ContainsKey(key))
{
return (T)ListOfOpenedChannels[key];
}
else
{
ChannelFactory<T> channelF = new ChannelFactory<T>("IUsuarioService");
T channel = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试根据应用程序运行的环境在我的 CORS 策略之间“切换”。
我有两个政策声明如下:
services.AddCors(options =>
{
options.AddPolicy(CORSPolicies.PublicApi,
builder => builder
.AllowAnyHeader()
.WithMethods("POST", "GET")
.WithOrigins("https://domain1.com", "https://domain2.com"));
options.AddPolicy(CORSPolicies.Dev,
builder => builder
.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin());
});
Run Code Online (Sandbox Code Playgroud)
这些策略应该只适用于少数控制器,所以我使用属性来应用它们:
[ApiController]
[Route("api/[controller]")]
[Produces("application/json")]
[AllowAnonymous]
[EnableCors(CORSPolicies.PublicApi)]
public class PublicApiControllerBase : ControllerBase
{
}
Run Code Online (Sandbox Code Playgroud)
PublicAPI
策略应该对域将实际受到限制的生产有效。Dev
政策允许任何事情,因为我将在本地使用它。
我试图将默认策略设置为以Dev
应用程序启动为条件,但由于EnableCorsAttribute
覆盖了它定义的内容,app.UseCors()
因此PublicApi
无论什么策略都将被使用,因此它不起作用。这是我天真的尝试:
if (env.IsDevelopment())
{
app.UseCors(CORSPolicies.Dev);
}
else
{
app.UseCors();
}
Run Code Online (Sandbox Code Playgroud)
我如何 a)PublicApi
根据我的应用程序运行的环境使我的策略行为不同或 b)根据环境有条件地应用PublicApi
或Dev
策略?
c# ×4
asp.net ×3
.net ×2
.net-3.0 ×1
architecture ×1
asp.net-core ×1
channel ×1
cors ×1
equals ×1
gethashcode ×1
httprequest ×1
iis-7.5 ×1
javascript ×1
json ×1
json.net ×1
loading ×1
nhibernate ×1
nuget ×1
nuget-server ×1
performance ×1
push ×1
timeout ×1
vue.js ×1
wcf ×1