我有Code First MVC 4应用程序.
我尝试安装NuGet软件包来记录Elmah - 一切似乎都运行正常 - 错误报告很好 http://myapp/elmah.axd
然后我注意到有一个Elmah.MVC包 - 所以我删除了原来的一个,并安装了它.它不再在这里工作:http://myapp/elmah.axd
我在一些地方读过,对于MVC应用程序,你应该使用'Elmah.MVC'软件包 - 而不是'Elmah'软件包 - 但为什么会这样呢?实际差异是什么?MVC 4网站仍然如此吗?
奇怪的是原始包装开箱即用,而MVC则没有.
我应该使用哪个以及为什么?
我有一个ASP.NET Core应用程序,将被多个用户用作客户端.换句话说,它不会托管在中央服务器上,只要需要使用应用程序,它们就会运行已发布的可执行文件.
在Program.cs文件中有以下内容:
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
Run Code Online (Sandbox Code Playgroud)
我希望默认的Web浏览器能够自动打开,以避免用户必须打开浏览器并手动输入http://localhost:5000地址的冗余步骤.
实现这一目标的最佳方法是什么?调用Program.Start后调用Run()将无效,因为Run阻塞了线程.
我正在尝试使用PHPmailer类发送电子邮件,但我发送的html是空的,或者字符是未配置的,没有重音符号.
<?php
header("Content-Type: text/html; charset=ISO-8859-1", true);
require_once('class.phpmailer.php');
include "config.php";
$nome = trim($_POST['nome']);
$email = trim($_POST['Imail']);
$usuario = trim($_POST['usuario']);
$senha = trim($_POST['senha']);
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->AddAddress($email, $nome);
$mail->SetFrom('editora@conectfarma.net', 'Conectfarma');
$mail->AddReplyTo('editora@conectfarma.net', 'Conectarma');
$subject = 'Guia Rápido de Interações Medicamentosas';
$sendsubject= "=?utf-8?b?".base64_encode($subject)."?=";
$mail->Subject = $sendsubject;
$mensagem = "<!DOCTYPE html>
<html>
<body>
Bem vindo ao Guia Rápido …Run Code Online (Sandbox Code Playgroud) 我不确定是什么改变了,但是,在我的解决方案是Visual Studio的目录中创建调试文件夹.
以下是一些正在创建的文件夹和文件:
System.Web.Http.pdb/EA80649BB72046E989099D4826726FH83/System.Web.Http.pdb
System.Web.pdb/CG58649BB72046E989099D4826726BHEWL/System.Web.Http.pdb
System.Transactions.pdb/FD28649BB72046E989099D4826726BV8F/System.Web.Http.pdb
System.Xml.pdb/5NIL649BB72046E989099D48267267CD1/System.Web.Http.pdb
Run Code Online (Sandbox Code Playgroud)
是否有一个设置我可以更改以阻止创建这些文件夹?它使我的解决方案目录变得混乱.
debugging visual-studio visual-studio-debugging visual-studio-2012
我刚刚将一些应用程序升级到ASP.NET MVC 5.我已经使用ASP.NET Membership几年了,并且正在探索切换到ASP.NET Identity的可能性.
我正在构建一个小的测试应用程序,我已经进行了身份验证(针对活动目录和自定义SQL Server架构,具体取决于用户),甚至通过ClaimsIdentity在签署用户之前添加角色声明进行授权(显然是box Authorize属性实际上将违反所提供的任何索赔信息).
声明默认存储在身份验证cookie中很酷.但是,当有关用户的信息发生更改(即,从角色中添加或删除它们)时,这会产生问题.
显然,我可以Authorize像往常一样完成自己的属性.如果我这样做,我只会一起跳过索赔,只需按照请求检查数据库中的角色.
有没有办法在ASP.NET身份中使用声明并知道它们何时不再有效?框架是否提供了解决此问题的任何选项?
asp.net asp.net-mvc claims-based-identity asp.net-mvc-5 asp.net-identity
我正在处理如下响应:
{"id":"https://login.salesforce.com/id/00Dx0000000BV7z/005x00000012Q9P",
"issued_at":"1278448832702","instance_url":"https://na1.salesforce.com",
"signature":"0CmxinZir53Yex7nE0TD+zMpvIWYGb/bdJh6XfOH6EQ=","access_token":
"00Dx0000000BV7z!AR8AQAxo9UfVkh8AlV0Gomt9Czx9LjHnSSpwBMmbRcgKFmxOtvxjTrKW1
9ye6PE3Ds1eQz3z8jr3W7_VbWmEu4Q8TVGSTHxs"}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将其反序列化为类似于以下内容的类:
public class TokenResponse {
public string Id { get; set; }
[JsonProperty(PropertyName = "issued_at")]
public DateTime IssuedAt { get; set; }
public string Signature { get; set; }
[JsonProperty(PropertyName = "instance_url")]
public string InstanceUrl { get; set; }
[JsonProperty(PropertyName = "access_token")]
public string AccessToken { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
反序列化的调用非常简单:
JsonConvert.DeserializeObject<TokenResponse>(response.Content);
Run Code Online (Sandbox Code Playgroud)
这会导致异常:
Could not convert string to DateTime: 1278448832702.
有没有办法让JSON.NET正确地反序列化这个日期?
我不确定我是否有线程问题.在页面加载时,我正在执行两个Ajax请求,以从第三方API加载一些其他数据.以下是每种方法被调用的内容:
private List<CaseCommentModel> GetCaseCommentModels(string caseId) {
var comments = CaseService.GetAllCaseCommentsByCaseId(caseId);
Mapper.Reset();
Mapper.CreateMap<CrmCaseComment, CaseCommentModel>();
var caseCommentModels = Mapper.Map<List<CrmCaseComment>, List<CaseCommentModel>>(comments);
return caseCommentModels;
}
private List<CaseAttachmentModel> GetCaseAttachmentModels(string caseId) {
var attachments = AttachmentService.GetAttachmentsByParentId(caseId);
Mapper.Reset();
Mapper.CreateMap<CrmAttachment, CaseAttachmentModel>();
var caseAttachmentModels = Mapper.Map<List<CrmAttachment>, List<CaseAttachmentModel>>(attachments);
return caseAttachmentModels;
}
Run Code Online (Sandbox Code Playgroud)
有时两种反应都会成功 但是,如果我刷新页面,有时会因以下异常而失败:
Missing type map configuration or unsupported mapping
我可以从成功失败的两个请求转到不进行任何代码更改; 只需刷新页面即可.这是一个线程问题还是我错误地使用了映射器?
我想查看 HTTP 请求的请求正文包含哪些内容以进行调试。这是我现在所拥有的:
var httpResponseMessage = await _httpClient.PostAsync(uri, objectToInsert, jsonFormatter);
//This throws an exception
var thisDoesntWork = await httpResponseMessage.RequestMessage.Content.ReadAsStringAsync();
Run Code Online (Sandbox Code Playgroud)
这会抛出一个ObjectDisposedException. 如何查看请求正文以确保发送的 JSON 正确?
我正在尝试从活动目录组中获取用户列表和有关用户的一些属性.
更新:
以下是我目前拥有的两种方法:
Dim adGroup As New DirectoryEntry("LDAP://CN=MyGroup,OU=Groups,OU=Accounts,OU=All,DC=domain,DC=com")
Dim adMembers As Object
Dim objUser As ActiveDirectoryUser
Dim objUserList As New List(Of ActiveDirectoryUser)
Dim directoryEntry As DirectoryEntry
adMembers = adGroup.Invoke("Members", Nothing)
For Each adMember As Object In CType(adMembers, IEnumerable)
directoryEntry = New DirectoryEntry(adMember)
objUser = New ActiveDirectoryUser
objUser.UserId = directoryEntry.Properties.Item("sAMAccountName").Value.ToString()
objUser.Contract = directoryEntry.Properties.Item("ou").Value.ToString()
objUser.LastName = directoryEntry.Properties.Item("sn").Value.ToString()
objUser.FirstName = directoryEntry.Properties.Item("givenName").Value.ToString()
objUser.Email = directoryEntry.Properties.Item("mail").Value.ToString()
objUserList.Add(objUser)
Next
Run Code Online (Sandbox Code Playgroud)
第一部分有效,但看起来效率很低.我的内存使用率随着执行而攀升和爬升,我得到了这个错误,虽然它看起来可以修复.第二种方法:
Dim results As SearchResultCollection
Dim directoryEntry2 As New DirectoryEntry("LDAP://DC=domain,DC=com")
Dim directorySearcher As New DirectorySearcher(directoryEntry2) …Run Code Online (Sandbox Code Playgroud) 据我所知(并且我知道相对较少),例如秒针滴答时没有发出本机事件.我想出的最好的方法是反复检查Date对象(例如,每隔333ms;较短的间隔会导致更高的精度,但也会占用更多的资源).不知何故,如果我反复使用相同的Date对象,则时间不会更新
Date.prototype.getSeconds()
Run Code Online (Sandbox Code Playgroud)
记录'NaN'虽然typeof是'number'.
function clock(interval) {
var d = new Date();
var secondsOld = d.getSeconds();
d = null;
setInterval(function() {
var d = new Date();
var secondsNew = d.getSeconds();
if ( secondsNew !== secondsOld ) {
secondsOld = secondsNew;
// trigger something
console.log(secondsOld);
}
d = null;
}, interval);
}
Run Code Online (Sandbox Code Playgroud) .net ×3
c# ×3
asp.net ×2
asp.net-mvc ×2
.net-core ×1
asp.net-core ×1
automapper ×1
debugging ×1
elmah ×1
elmah.mvc ×1
email ×1
events ×1
html ×1
http ×1
javascript ×1
json.net ×1
php ×1
phpmailer ×1
time ×1