我的HomeController中有以下代码:
public ActionResult Edit(int id)
{
var ArticleToEdit = (from m in _db.ArticleSet where m.storyId == id select m).First();
return View(ArticleToEdit);
}
[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Article ArticleToEdit)
{
var originalArticle = (from m in _db.ArticleSet where m.storyId == ArticleToEdit.storyId select m).First();
if (!ModelState.IsValid)
return View(originalArticle);
_db.ApplyPropertyChanges(originalArticle.EntityKey.EntitySetName, ArticleToEdit);
_db.SaveChanges();
return RedirectToAction("Index");
}
Run Code Online (Sandbox Code Playgroud)
这是Edit方法的视图:
<% using (Html.BeginForm()) {%>
<fieldset>
<legend>Fields</legend>
<p>
<label for="headline">Headline</label>
<%= Html.TextBox("headline") %>
</p>
<p>
<label for="story">Story <span>( HTML Allowed )</span></label>
<%= Html.TextArea("story") %>
</p>
<p>
<label for="image">Image …Run Code Online (Sandbox Code Playgroud) 我正在创建一个Azure AD应用程序,并注意到有两种权限类型,即应用程序权限和委派权限.两者之间有什么区别,在什么情况下我应该使用它们?
I experience an error when trying to create a database using the following code. Note the problem does not happen if the connection string is not passed in. Also the problem happens when I run the program in the IDE. It does not happen if I run the program .exe or if I run the unit tests within the IDE.
However if the database is created by running the unit tests or by running the .EXE then the __MigrationHistory table …
我正在寻找一种非常简单的crypt/decrypt方法.我将始终使用相同的静态密钥.我知道这种方法的风险.目前我正在使用以下代码,但在加密和删除相同的字符串后,它不会生成相同的结果(字符串中间有一些垃圾).
public static string Crypt(this string text)
{
string result = null;
if (!String.IsNullOrEmpty(text))
{
byte[] plaintextBytes = Encoding.Unicode.GetBytes(text);
SymmetricAlgorithm symmetricAlgorithm = DES.Create();
symmetricAlgorithm.Key = new byte[8] {1, 2, 3, 4, 5, 6, 7, 8};
using (MemoryStream memoryStream = new MemoryStream())
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, symmetricAlgorithm.CreateEncryptor(), CryptoStreamMode.Write))
{
cryptoStream.Write(plaintextBytes, 0, plaintextBytes.Length);
}
result = Encoding.Unicode.GetString(memoryStream.ToArray());
}
}
return result;
}
public static string Decrypt(this string text)
{
string result = null;
if (!String.IsNullOrEmpty(text))
{
byte[] …Run Code Online (Sandbox Code Playgroud) 我将映射定义定义为
Mapper.CreateMap<Calculator, CalculatorViewModel>()
.ForMember(dest => dest.TypeIndicator, src => src.ResolveUsing(new TypeIndicatorResolver()));
Run Code Online (Sandbox Code Playgroud)
我应该使用ResolveUsing还是MapFrom(src => SomePrivateMethod())?
ResolveUsing和MapFrom在复杂映射方面有什么区别.
Resolver或Private方法将转到数据库并获取值.
我有以下路由配置,但我收到错误 Invalid configuration of route 'tenant': redirectTo and children cannot be used together
一旦我点击/租户,我想以某种方式显示两个租户的内容,然后审计?这可能吗 ?我的租户网址如下所示http://localhost:8080/#/tenant
{
path: 'tenant',
redirectTo: '/tenant/(view:audit)',
pathMatch: 'full',
component: TenantComponent,
data: {
authorities: ['ROLE_USER', 'ROLE_ADMIN'],
pageTitle: 'tenant.home.title'
},
children: [
{
path: 'audit',
component: PacketDataComponent,
data: {
authorities: ['ROLE_USER', 'ROLE_ADMIN'],
pageTitle: 'tenant.home.title'
},
}
]
}
Run Code Online (Sandbox Code Playgroud) 当我尝试从portal.azure.com运行内置b2c编辑策略时,我刚刚收到以下错误.我打开了2个门户选项卡.为什么我收到此错误?
错误请求 - 请求太长HTTP错误400.请求标头的大小太长.
注意:在测试active-directory-b2c-dotnet-webapp-and-webapi示例项目时,我遇到了同样的错误消息.提供的原因是我发送了太多cookie.是同样的问题吗?
如果是同样的问题,在创建新的cookie之前是否应该删除陈旧的cookie?
我确实为https://login.microsoftonline.com看到了很多cookie
我有一个MVC网络应用程序,我正在使用Simple Injector进行DI.我的几乎所有代码都包含在单元测试中.但是,现在我已经在某些控制器中添加了一些遥测调用,我在设置依赖项时遇到了麻烦.
遥测调用用于将指标发送到Microsoft Azure托管的Application Insights服务.该应用程序未在Azure中运行,只是一个带有ISS的服务器.AI门户网站会告诉您有关应用程序的各种信息,包括使用遥测库发送的任何自定义事件.因此,控制器需要一个Microsoft.ApplicationInsights.TelemetryClient实例,该实例没有接口,并且是一个带有2个构造函数的密封类.我试着像这样注册它(混合生活方式与这个问题无关,我只是为了完整而包含它):
// hybrid lifestyle that gives precedence to web api request scope
var requestOrTransientLifestyle = Lifestyle.CreateHybrid(
() => HttpContext.Current != null,
new WebRequestLifestyle(),
Lifestyle.Transient);
container.Register<TelemetryClient>(requestOrTransientLifestyle);
Run Code Online (Sandbox Code Playgroud)
问题是,由于TelemetryClient有2个构造函数,SI抱怨并且验证失败.我找到了一篇文章,展示了如何覆盖容器的构造函数解析行为,但这似乎相当复杂.首先,我想要备份并提出这个问题:
如果我没有使TelemetryClient成为一个注入的依赖项(只是在类中创建一个新的),那么在每次运行单元测试时是否会将遥测发送到Azure,从而产生大量错误数据?或者Application Insights是否足够聪明,知道它在单元测试中运行,而不是发送数据?
对此问题的任何"见解"将不胜感激!
谢谢
c# unit-testing azure simple-injector azure-application-insights
我在asp.net core 2.0中创建了API,我正在使用混合模式身份验证.对于一些控制器JWT和一些使用Windows身份验证.
我对使用JWT授权的控制器没有任何问题.但对于我想要使用Windows身份验证的控制器,我无限期地提示使用chrome的用户名和密码对话框.
这里是我的示例控制器代码,我想使用Windows身份验证而不是JWT.
[Route("api/[controller]")]
[Authorize(AuthenticationSchemes = "Windows")]
public class TestController : Controller
{
[HttpPost("processUpload")]
public async Task<IActionResult> ProcessUploadAsync(UploadFileModel uploadFileModel)
{
}
}
Run Code Online (Sandbox Code Playgroud)
我的配置服务代码
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = IISDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer("Bearer", options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false,
ValidateIssuer = false,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("blahblahKey")),
ValidateLifetime = true, //validate the expiration and not before values in the token
ClockSkew = TimeSpan.FromMinutes(5) //5 minute …Run Code Online (Sandbox Code Playgroud) 我们如何在.Net Core类库中使用Rijndael加密?(不是.Net Framework类库)我们需要创建一个共享的.Net Core库,用于多个项目,并且需要实现在项目中使用相同Rijndael加密的Encrypt和Decrypt方法.
我们目前正在使用:
似乎.Net Core 1.0版本中缺少Rijndael和AES的实现...它似乎只包括基类.我们如何获得Rijndael或AES加密的.Net Core实现作为新的.Net核心类库项目的参考?
以下是在.Net Framework 4.5.2中使用的Encrypt方法:
public static string Encrypt(string valueToEncrypt, string symmetricKey, string initializationVector)
{
string returnValue = valueToEncrypt;
var aes = new System.Security.Cryptography.RijndaelManaged();
try
{
aes.Key = ASCIIEncoding.ASCII.GetBytes(symmetricKey);
aes.IV = ASCIIEncoding.ASCII.GetBytes(initializationVector);
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.ISO10126;
var desEncrypter = aes.CreateEncryptor();
var buffer = ASCIIEncoding.ASCII.GetBytes(valueToEncrypt);
returnValue = Convert.ToBase64String(desEncrypter.TransformFinalBlock(buffer, 0, buffer.Length));
}
catch (Exception)
{
returnValue = string.Empty;
}
return returnValue;
}
Run Code Online (Sandbox Code Playgroud) c# ×4
azure ×2
.net ×1
.net-core ×1
angular ×1
asp.net-mvc ×1
automapper ×1
azure-ad-b2c ×1
azureportal ×1
cryptography ×1
des ×1
encryption ×1
security ×1
unit-testing ×1