我通过ASP.NET MVC使用服务组件.我想以异步方式发送电子邮件,让用户做其他事情,而不必等待发送.
当我发送没有附件的邮件时,它工作正常.当我发送带有至少一个内存附件的消息时,它会失败.
所以,我想知道是否可以使用异步方法与内存中的附件.
这是发送方法
public static void Send() {
MailMessage message = new MailMessage("from@foo.com", "too@foo.com");
using (MemoryStream stream = new MemoryStream(new byte[64000])) {
Attachment attachment = new Attachment(stream, "my attachment");
message.Attachments.Add(attachment);
message.Body = "This is an async test.";
SmtpClient smtp = new SmtpClient("localhost");
smtp.Credentials = new NetworkCredential("foo", "bar");
smtp.SendAsync(message, null);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我目前的错误
System.Net.Mail.SmtpException: Failure sending mail.
---> System.NotSupportedException: Stream does not support reading.
at System.Net.Mime.MimeBasePart.EndSend(IAsyncResult asyncResult)
at System.Net.Mail.Message.EndSend(IAsyncResult asyncResult)
at System.Net.Mail.SmtpClient.SendMessageCallback(IAsyncResult result)
--- End of inner exception stack …Run Code Online (Sandbox Code Playgroud) 我正在使用这样的路线:
routes.MapRoute("Invoice-New-NewCustomer",
"Invoice/New/Customer/New/{*name}",
new { controller = "Customer", action = "NewInvoice" },
new { name = @"[^\.]*" });
Run Code Online (Sandbox Code Playgroud)
有一个动作可以处理这条路线:
public ActionResult NewInvoice(string name)
{
AddClientSideValidation();
CustomerViewData viewData = GetNewViewData();
viewData.InvoiceId = "0";
viewData.Customer.Name = name;
return View("New", viewData);
}
Run Code Online (Sandbox Code Playgroud)
当我调用return RedirectToAction("NewInvoice", "Customer", new {name});并且name等于"C#Guy"时,"name"参数被截断为"The C".
所以我的问题是:使用ASP.NET MVC处理这种特殊字符的最佳方法是什么?
谢谢!
ER Diagrams和Database Schema有什么区别?MySQL Workbench具有绘制ER图的功能,但ER图的符号在其他绘图工具中与MySQL Workbench方法不同.
我基本上有一个测试场景,我在那里
SQL Server 是否仅支持内存中的类似内容,以便我可以通过删除 #1 和 #5 来加快速度?显然我不需要坚持。
sql-server integration-testing database-testing in-memory-database
提供以下ServiceStack控制器
public class MyController : ServiceStackController
{
public ActionResult Index()
{
return View(Cache.GetAllKeys());
}
}
Run Code Online (Sandbox Code Playgroud)
和以下测试类
[TestFixture]
public class MyControllerTests
{
[Test]
public void Should_call_cache()
{
var controller = new MyController();
// Mock here to access Cache, otherwise throws NullReferenceException
var result = controller.Index();
Assert.IsNotNull(result);
var model = result.Model as IEnumerable<string>;
Assert.IsNotNull(model);
}
}
Run Code Online (Sandbox Code Playgroud)
模拟ICacheClientCache属性以验证测试方法的正确方法是什么?
我已经四处寻找这个bug的解决方案但是还没找到,甚至在SO上.我得到的警告是这样的:
(0,0): warning CS1702: Assuming assembly reference 'Microsoft.Owin.Security.OAuth,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' matches
'Microsoft.Owin.Security.OAuth, Version=2.0.2.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35', you may need to supply runtime policy
Validation Complete
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)
这是我的Bin目录:

这是packages.config文件:
<packages>
<package id="EntityFramework" version="6.0.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Owin.Security" version="2.0.2" targetFramework="net45" />
<package id="Microsoft.Owin.Security.Cookies" version="2.0.2" …Run Code Online (Sandbox Code Playgroud) 我对会话文档有点困惑,所以让我说我已经从客户端发送身份验证数据并检索ss-id和ss-pid,如下所示:
var client = new JsonServiceClient("http://somewhere/theAPI/");
var response = client.Post(new Auth() {UserName = "myuser", Password = "password123"});
var myCookie= client.CookieContainer.GetCookies(new Uri("http://somewhere/theAPI"));
Run Code Online (Sandbox Code Playgroud)
我如何从服务栈中检索姓氏,电子邮件等的AuthSession信息?我需要它存储在其他地方,如在memcache服务器,并从中检索?
或者我需要在客户端构建我的身份验证?并只是使用API来检索数据?
我读过当 aDbContext.SaveChanges()运行时,所有操作都会在幕后自动包装在一个事务中。也就是说,如果内部的任何操作SaveChanges()失败,一切都会回滚以保持一致的状态。
但是,我多次遇到的一个术语是更改可以作为环境事务的一部分运行。这到底是什么意思呢?
我的具体问题是:我有一个多线程应用程序,其中每个操作都有一个上下文。我的 DbContext 对象都没有跨不同线程共享。我能保证每个操作都DbContext.SaveChanges()在单独的事务中运行吗?
我正在尝试使用ServiceStack的Funq连接ElasticClient,但是在尝试调用它时我得到一个空引用异常.
这是我的设置:
在AppHost.cs中:
var elasticSettings = new ConnectionSettings(new Uri("http://localhost:9200"), "listings");
var elasticClient = new ElasticClient(elasticSettings);
container.Register(elasticClient);
Run Code Online (Sandbox Code Playgroud)
然后在我的ServiceInterface项目中,在ListingServices.cs类中:
private ElasticClient Elastic; // also tried IElasticClient Elastic;
public object Post(CreateListing request)
{
Listing newAd = new Listing();
newAd = request.ConvertTo<Listing>();
using (IDbConnection db = DbFactory.Open())
{
db.Save(newAd);
Elastic.Index(newAd); // NULL REFERENCE EXCEPTION
}
return new CreateListingResponse { Result = true };
}
Run Code Online (Sandbox Code Playgroud)
但是,Elastic仍设置为Null并提供空引用异常.
关于如何解决的任何想法.
有谁知道为什么使用法语单词for byte application/octet-stream?也许有一个历史原因,或者这可能不是法语单词本身,而是来自另一种语言的同义词.
asp.net-mvc ×4
servicestack ×3
asp.net ×2
c# ×2
.net ×1
caching ×1
database ×1
email ×1
funq ×1
mime-types ×1
mocking ×1
sql-server ×1
terminology ×1
unit-testing ×1