我不知道如何在抽象类中使用依赖注入。让我通过一个简单的例子向您展示我的问题:
public abstract class Animal {
public abstract void Move();
public void Sleep()
{
restService.StartSleeping(1000); //how to get this service here?
}
}
public class Cat : Animal
{
public readonly IMotionService _motionService;
public Cat(IMotionService motionService)
{
_motionService = motionService;
}
public override void Move()
{
_motionService.Run();
}
}
public class Bird : Animal
{
public readonly IMotionService _motionService;
public Bird(IMotionService motionService)
{
_motionService = motionService;
}
public override void Move()
{
_motionService.Fly();
}
}
Run Code Online (Sandbox Code Playgroud)
每只动物以不同的方式移动,因此该Move()函数在每个派生类中单独实现。正如您可能注意到的那样,整个实现都来自motionService. …
我在 ASP.NET MVC 5 项目中使用compression-webpack-plugin将 javascript 文件压缩为 gz 格式。
\n\n我的webpack.config.js的一部分,带有压缩 webpack-plugin设置:
\n\nconst CompressionPlugin = require(\'compression-webpack-plugin\');\n\nmodule.exports = {\n//...\n plugins: [\n //...\n new CompressionPlugin({\n test: /\\.(js|css)$/,\n filename: \'[path].gz[query]\',\n algorithm: \'gzip\',\n deleteOriginalAssets: true\n }),\n ],\n//...\n};\nRun Code Online (Sandbox Code Playgroud)\n\n它工作正常:
\n\n\n\n下一步是在 IIS 中启用 GZIP 压缩,因此首先我确保Windows 功能中具有必要的功能:
\n\n\n\n...并直接在 IIS 中为我的应用程序启用压缩,如下图所示。
\n\n\n\n另外,我已将这段代码添加到我的Web.config中:
\n\n<system.webServer>\n <urlCompression doStaticCompression="true" doDynamicCompression="true" />\n</system.webServer>\nRun Code Online (Sandbox Code Playgroud)\n\n构建脚本后,网络浏览器不会加载 - 我在控制台中收到每个脚本文件的警告:
\n\n\n\n\n源\n \xe2\x80\x9e http://192.168.100.100:8088/Scripts/dist/runtime.7b9bc97b36a783fd7495.js \xe2\x80\x9d的“脚本”加载失败。
\n
我做错了什么?我应该在后端设置其他东西吗?请注意,我包含带有 …
我有一些 Web 服务(用 Java 编写),我需要在 .NET 中为它创建客户端。WebService 具有 WS-Security 并且需要 PasswordDigest。首先,我已经在 SoapUI 中对其进行了测试,它适用于:
POST http://192.168.100.101:8181/services/ws/SomeService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="someMethod"
Content-Length: 971
Host: 192.168.100.101:8181
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soap:Envelope xmlns:not="http://existing-domain.com/op/integration/services" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-2C1E2DE2B61EBB94E115572099598331">
<wsse:Username>SOME_LOGIN</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">rcSb6Hd8btcI9g6JvO7dGdiTBTI=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">PCoVwJm9oEXtusx6gkMb7w==</wsse:Nonce>
<wsu:Created>2019-05-07T06:19:19.824Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<not:someMethod/>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
在下一步中,我在 .NET 中准备了简单的客户端,并使用 Wireshark 检查它发送的内容:
POST /services/ws/SomeService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="someMethod"
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Host: 192.168.100.101:8181
Content-Length: 1124
Expect: 100-continue
Connection: Keep-Alive
<soap:Envelope xmlns:not="http://existing-domain.com/op/integration/services" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header> …Run Code Online (Sandbox Code Playgroud) 我需要返回一个带有描述的 HttpStatusCodeResult 对象,其中包含特殊(变音符号)字符。我不知道如何设置正确的编码。
\n\nreturn new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Za\xc5\xbc\xc3\xb3\xc5\x82\xc4\x87 g\xc4\x99si\xc4\x85 ja\xc5\xba\xc5\x84.");\nRun Code Online (Sandbox Code Playgroud)\n\n应该返回:
\n\n\n\n\nZa\xc5\xbc\xc3\xb3\xc5\x82\xc4\x87 g\xc4\x99si\xc4\x85 ja\xc5\xba\xc5\x84。
\n
但我得到:
\n\n\n\n\nZa\xc2\xbf\xc3\xb3\xc2\xb3\xc3\xa6 g\xc3\xaasi\xc2\xb9 ja\xc3\xb1。
\n
我尝试过Response.Charset = System.Text.Encoding.UTF8.WebName;等等,但仍然一无所获。
我在bootstrap导航栏下面有一个奇怪的边缘,我不知道如何删除它.任何带边距或填充操作的解决方案都不起作用.
HTML
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><span class="glyphicon glyphicon-home"></span></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Active example <span class="sr-only">(current)</span></a></li>
<li><a href="#">Example 3</a></li>
<li><a href="#">Example 2</a> </li>
</ul>
</div>
</div>
</nav>
<!-- …Run Code Online (Sandbox Code Playgroud) 我需要重新发送激活链接给用户,如果他丢失以前的电子邮件与此链接.
所以,我在Login方法中检查了用户状态:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
bool isConfirmed = (model == null) ? false : WebSecurity.IsConfirmed(model.UserName);
string errorMsg = "Login or password is incorrect.";
if (isConfirmed)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
}
else
{
if (WebSecurity.UserExists(model.UserName))
{
errorMsg = "Your account is not activated. Click <a href=\"" + Url.Content("~/Account/ResendConfirmationLink") + "?id=" + model.UserName +"\" class=\"alert-link\">here</a> for resend email with activation link.";
}
}
// If we got …Run Code Online (Sandbox Code Playgroud) c# ×2
.net ×1
.net-core ×1
asp.net ×1
asp.net-mvc ×1
compression ×1
css ×1
gzip ×1
html ×1
iis ×1
razor ×1
soap ×1
web-services ×1
webpack-4 ×1
ws-security ×1