我真的需要我的WebAPI 2项目的API文档,我使用了Swashbuckle 5 NuGet包.开箱即用,我可以点击{myrooturl}/swagger并弹出一个UI,但那里没有控制器,方法或任何东西.只是我的标题:[base url:/EM.Services,api version:v1]
我看了一下Swashbuckle文档,因为我正在使用由IIS托管的OWIN,所以我修改了SwaggerConfig:
c.RootUrl(req => req.RequestUri.GetLeftPart(UriPartial.Authority) + req.GetRequestContext().VirtualPathRoot.TrimEnd('/'));
Run Code Online (Sandbox Code Playgroud)
根据这个文档:https://github.com/domaindrivendev/Swashbuckle/blob/1326e753ce9b3a823b3c156b0b601134692ffc58/README.md#transitioning-to-swashbuckle-50
我还设置了项目的构建以生成XML文档,并将SwaggerConfig指向它:
private static string GetXmlCommentsPath()
{
// tried with an without the \bin
return String.Format(@"{0}\bin\EM.Services.XML", AppDomain.CurrentDomain.BaseDirectory);
}
Run Code Online (Sandbox Code Playgroud)
我不确定XML文档的工作/不工作是否与它有关,因为我在swagger-ui页面上完全没有控制器.
值得一提的是,我的所有控制器都继承自BaseController,而BaseController又继承自ApiController.
我的WebApiConfig有什么东西搞砸了吗?
public static void Register(HttpConfiguration config)
{
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
config.Filters.Add(new ValidateModelAttribute());
config.Filters.Add(new BaseAuthenticationAttribute());
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
}
Run Code Online (Sandbox Code Playgroud)
我的具体控制器看起来都是这样的(我已经尝试为ApiController调试BaseController并且没有变化):
[RoutePrefix("api/whatever")]
public class FooController : …Run Code Online (Sandbox Code Playgroud) 我正在重新设计我当前的项目以使其更易于维护,并尽力遵循良好的设计实践.目前我有一个Silverlight组件的解决方案,用于所述SL应用程序的ASP.Net主机,该应用程序还包含WCF RIA服务和共享类库,因此SL和WCF服务都可以共享对象.业务逻辑遍布各处,所有CRUD操作都在我的WCF服务中手动编码.所以,我正在为一切创建一个新结构,并将这个混乱移植到新格式中.在这样做的过程中,当我不知道自己是否应该这样时,我发现我正在复制课程.
我的新结构如下:
客户端:
Reporting.Silverlight = Silverlight应用程序.这将参考我的DTO课程.
Reporting.Web =持有我的SL应用程序,是人们进入它的主要入口点.
业务:
Reporting.Services =我的WCF服务就在这里.我的SL应用程序将调用此方法来执行操作,这些服务将返回DTO类.
Reporting.Services.Contracts =保存我的WCF服务接口,并包含带有DataContract装饰器的DTO类.
Reporting.Domain =保存我的域对象和业务逻辑
数据:
Reporting.Data.Contract =保存我的存储库和工作单元的接口
Reporting.Data=存储库/ UoW的具体实现.此处定义了Entity Framework 5上下文.
Reporting.Data.Models =保存我的所有Entity对象,以便EF5可以用SQL做它的事情.
我有3个地方,我几乎完全相同的课程,对我来说它闻起来.在Reporting.Services.Contracts内部,我有一个DTO,可以交给SL客户端.这是一个例子:
[DataContract(Name = "ComputerDTO")]
public class ComputerDTO
{
[DataMember(Name = "Hostname")]
public string Hostname { get; set; }
[DataMember(Name = "ServiceTag")]
public string ServiceTag { get; set; }
// ... lots more
}
Run Code Online (Sandbox Code Playgroud)
我认为上面的DTO很好,因为它只是传递给SL客户端的一堆属性.我的DTO属性的绝大多数都映射到我的实体对象1:1的特性,除了ID字段.这是我的Entity对象,与上面的DTO对应:
[Table("Inventory_Base")]
public class ComputerEntity
{
// primary key
[Key]
public int AssetID { get; set; }
// foreign …Run Code Online (Sandbox Code Playgroud) 我遇到了一些我无法弄清楚的最奇怪的事情.我有一个SQL表,其中包含一堆存储在ntext字段中的报告.当我将其中一个的值复制并粘贴到记事本中并保存它时(使用Visual Studio从不同行中的较小报告中获取值),原始txt文件大约为5Mb.当我尝试使用SqlDataReader获取相同的数据并将其转换为字符串时,我得到一个内存不足的异常.以下是我尝试这样做的方法:
string output = "";
string cmdtext = "SELECT ReportData FROM Reporting_Compiled WHERE CompiledReportTimeID = @CompiledReportTimeID";
SqlCommand cmd = new SqlCommand(cmdtext, conn);
cmd.Parameters.Add(new SqlParameter("CompiledReportTimeID", CompiledReportTimeID));
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
output = reader.GetString(0); // <--- exception happens here
}
reader.Close();
Run Code Online (Sandbox Code Playgroud)
我尝试创建一个对象和一个stringbuilder来获取数据,但我仍然得到相同的内存不足异常.我也尝试过使用reader.GetValue(0).ToString()也无济于事.查询只返回1行,当我在SQL Management Studio中运行时,它尽可能快乐.
抛出的异常是:
System.OutOfMemoryException was unhandled by user code
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=mscorlib
StackTrace:
at System.String.CreateStringFromEncoding(Byte* bytes, Int32 byteLength, Encoding encoding)
at System.Text.UnicodeEncoding.GetString(Byte[] bytes, Int32 index, Int32 count)
at System.Data.SqlClient.TdsParserStateObject.ReadString(Int32 length)
at System.Data.SqlClient.TdsParser.ReadSqlStringValue(SqlBuffer …Run Code Online (Sandbox Code Playgroud) 所以我遇到了这个F#之旅:https://docs.microsoft.com/en-us/dotnet/articles/fsharp/tour
...和男孩你好F#有趣!游览的一开始就定义了一个示例函数,它看起来非常简单:
/// You use 'let' to define a function. This one accepts an integer argument and returns an integer.
/// Parentheses are optional for function arguments, except for when you use an explicit type annotation.
let sampleFunction1 x = x*x + 3
Run Code Online (Sandbox Code Playgroud)
所以这对我来说很有意义.它定义了函数是什么,所以如果我将一些数字传递给这个东西,它会对它进行平方并为该结果增加3,如巡视中的下一行所示:
/// Apply the function, naming the function return result using 'let'.
/// The variable type is inferred from the function return type.
let result1 = sampleFunction1 4573
Run Code Online (Sandbox Code Playgroud)
经过几分钟的思考后,我得出结论,C#也可以做到这一点!我确实非常喜欢C#.就我所知,这就是上面在C#中的样子:
Func<int, int> sampleFunction1 = x …Run Code Online (Sandbox Code Playgroud) 所以我正在阅读我在/ r/netsec上找到的一篇简洁的文章:
https://paragonie.com/blog/2015/05/using-encryption-and-authentication-correctly
真正让我陷入循环的一件事是,人们可以在加密的cookie中翻转一下,实际上对所包含的数据进行了有意义的改变.
确保所有流量都通过SSL很容易(这不是关于安全传输的问题),但这让我真正考虑了消息的完整性以及如何查看原始cookie是否被篡改.通常,我只会在cookie中存储经过身份验证的用户ID,并处理防火墙后面的所有其他内容.如果我可以篡改该cookie以从客户端更改用户ID,该怎么办?上述文章表明这是可能的,并且提供了使用优选的libsodium来解决该问题的建议.我知道这个库(我自己没有使用它),但是我认为需要ASP内置安全机制以外的东西,这让我进一步深入兔子洞.
特别是关于内置ASP安全性,我是否需要做一些尚未以标准方式处理cookie安全性的特殊方法(让OWIN做其事或使用FormsAuthentication.Encrypt)?如果没有,如何在引擎盖下处理消息完整性?
进一步阅读让我参与了这个代码项目的HttpSecureCookie课程:http: //www.codeproject.com/Articles/13665/HttpSecureCookie-A-Way-to-Encrypt-Cookies-with-ASP
以上表示使用机器密钥进行cookie防篡改,但我不清楚它是如何使其防篡改.这将如何防止恶意用户将原始文章中指示的位翻转到加密的cookie?
我正在组建一个技术分析库,我希望其他人最终可以使用它,所以我想确保我验证数据进入我的方法并返回适当的东西.现在,如果验证失败,我会返回一个空值.抛出异常会更合适吗?如果其他开发人员可以使用此库,那么更好的做法是什么?以下是我目前的验证方式:
/// <summary>
/// Calculates the MACD (Moving Average Convergence Divergence) over n periods, where n is the number of elements in the input prices.
/// </summary>
/// <param name="InputValues">The numbers used for the MACD calculation. Index 0 must be the oldest, with each index afterwards one unit of time forward. There must more values present than what the SlowEMA calls for.</param>
/// <param name="FastEMA">Optional: The smaller (faster) EMA line used in MACD. Default value is 12. Must be less …Run Code Online (Sandbox Code Playgroud) 我正在开始我的ASP.Net Core 1.0托管的Angular 2(RC4)之旅.我一直在关注这个网站的hello world教程,到目前为止它运行良好:http:
//geekswithblogs.net/HumpreyCogay/Default.aspx
每当我对位于$ project/app/app.component.ts的app.component.ts文件进行更改时,我都会看到我的更改会反映在$ project/wwwroot/app/app.component.js文件中.万岁.据我所知,Visual Studio 2015非常智能,知道我修改了一个打字稿文件,知道它必须将其转换,然后根据我的tsconfig将其转储到wwwroot中.FWIW,我的tsconfig.json看起来像这样:
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "wwwroot/app/"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
Run Code Online (Sandbox Code Playgroud)
因此,app.component.ts将模板列为内联html.如果我改变它:
template: '<h1>My First Angular 2 App</h1>'
Run Code Online (Sandbox Code Playgroud)
至
templateUrl: './app/app.component.html'
Run Code Online (Sandbox Code Playgroud)
然后ts文件以js格式转换为wwwroot,但我创建的html文件($ project/app/app.component.html)却没有.如果我手动将其复制到那里,测试应用程序将按预期工作.
因此,每当我更改/添加一个html文件时,手动将html文件复制到wwwroot是行不通的.推荐的做法是什么让这种东西自动翻过来?我已经使用我的.scss文件(很高兴生成了compilerconfig.json)得到了一些东西,所以我想我可以使用一些可用于.html文件的机制.
我还有一个gulpfile.js来清理/复制node_modules到$ project/wwwroot/libs,但是我不确定这是否是复制.html文件的正确位置,也不确定自动魔法是什么它.对于我的node_module东西,我会在需要时手动触发清理和复制任务.
作为前言,我是使用SQL Server 2005的新手; 我知道如何使用SELECT,UPDATE,DELETE和INSERT命令以及它的相关信息.我也在我的本地PC上使用Express Edition(在RAID 1中使用E8400处理器,8GB DDR2-800,2 x 640GB SATA-II HDD)
我有一个表,我设置了8列,都是NVARCHAR(最大),我允许Null.我在概念上知道什么是主键,但我没有主键(我也不知道如何设置一个).
我正在研究的我的VB.NET程序是从雅虎下载历史股票价格图表,用于存在的每个股票代码.我添加的前50,000行是超快的.然后我去睡觉了,当我醒来的时候它还在运行 - 但是增加行的速度已经减缓了waaaaaay的速度; 我注意到这一行在300,000左右.我总是期望行添加的速率随着时间的推移而保持不变,但显然不是这样!
从浏览其他Stack Overflow问题开始,我怀疑我的减速与我的贫困表设置有关.如果是这种情况,我应该从哪里开始解决这个问题,是否有任何好的资源我可以开始阅读?我希望这很简单,我可以解决:)
如果重要,这就是我添加行的方式:
cmdtext = "IF NOT EXISTS(SELECT DateStamp FROM DailyPrice WHERE (DateStamp = '" + datestamp + "' AND Ticker = '" + ticker + "')) INSERT INTO DailyPrice (Ticker,OpenPrice,ClosePrice,HighPrice,LowPrice,AdjustedClose,Volume,DateStamp) VALUES('" + ticker + "','" + openprice + "','" + closeprice + "','" + highprice + "','" + lowprice + "','" + adjustedclose + "','" + volume + "','" + datestamp + "')" …Run Code Online (Sandbox Code Playgroud) c# ×5
performance ×2
angular ×1
asp.net ×1
asp.net-core ×1
cookies ×1
encryption ×1
exception ×1
f# ×1
iis ×1
memory ×1
methods ×1
security ×1
sql ×1
sql-server ×1
swashbuckle ×1
validation ×1
vb.net ×1
wcf ×1