我使用Win 10 Pro N(版本1709)作为开发机器,使用Windows Server 2016 Standard(版本1607)作为生产服务器.
我目前正在使用MongoDb作为数据库开发ASP.NET Core 2应用程序.
几天前,我首先偶然发现了想法,将MongoDb作为Docker镜像运行.
到目前为止,我对Docker没有任何经验,但我设法在Windows机器上从Linux容器(默认)切换到Windows容器.
这是一个好的决定吗?或者我有什么理由在我的场景中使用Linux容器而不是Windows容器?
例如,如果我决定将我的应用程序部署到Linux服务器一段时间?在这种情况下,从一开始就开始使用Linux容器会更明智吗?
我正在使用MailKit/MimeKit 1.2.7(最新的NuGet版本).
我尝试通过API文档中的示例("使用BodyBuilder"部分)将图像嵌入到我的电子邮件的HTML正文中.
我当前的代码如下所示:
var builder = new BodyBuilder();
builder.HtmlBody = @"<p>Hey!</p><img src=""Image.png"">";
var pathImage = Path.Combine(Misc.GetPathOfExecutingAssembly(), "Image.png");
builder.LinkedResources.Add(pathLogoFile);
message.Body = builder.ToMessageBody();
Run Code Online (Sandbox Code Playgroud)
我可以发送此电子邮件,实际上图像已附加到电子邮件中.但它没有嵌入.
我错过了什么吗?或者这是Apple Mail的错(这是我用来接收电子邮件的电子邮件客户端)?
我很感激任何想法(非常感谢Jeffrey Stedfast提供这么棒的工具集!!).
英格玛
以下代码无法编译,因为SingleOrDefaultAsync()不是GetAppointments()的合适扩展.我只是想知道为什么......
public IQueryable<Appointment> GetAppointments()
{
return Context.Appointments;
}
public async Task<Appointment> GetAppointmentAsync(int appointmentId)
{
return await GetAppointments().SingleOrDefaultAsync(a => a.ID == appointmentId);
}
Run Code Online (Sandbox Code Playgroud)
我使用的是EF 6.0.0.请忽略我在这里做的事情.我只是想让事情变得比他们在我的项目中更容易.
我正在将ASP.NET Core 2与Razor页面一起使用,并且试图在一页上使用两种具有单独属性(BindProperty)的表单。
@page
@model mfa.Web.Pages.TwoFormsModel
@{
Layout = null;
}
<form method="post">
<input asp-for="ProductName" />
<span asp-validation-for="ProductName" class="text-danger"></span>
<button type="submit" asp-page-handler="Product">Save product</button>
</form>
<form method="post">
<input asp-for="MakerName" />
<span asp-validation-for="MakerName" class="text-danger"></span>
<button type="submit" asp-page-handler="Maker">Save maker</button>
</form>
Run Code Online (Sandbox Code Playgroud)
和对应的PageModel:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
namespace mfa.Web.Pages
{
public class TwoFormsModel : PageModel
{
[BindProperty]
[Required]
public string ProductName { get; set; }
[BindProperty]
[Required]
public string MakerName { get; set; }
public async Task<IActionResult> …Run Code Online (Sandbox Code Playgroud) 在视图的样式标记中使用Razor语法的正确语法是什么?我尝试了两种不同的方式:
<style scoped>
.test1
{
background-color: @Model.bgColor;
}
.test2
{
background-color: @(Model.bgColor);
}
</style>
Run Code Online (Sandbox Code Playgroud)
这两个版本都将破坏Visual Studio 2012(版本11.0.60610.01更新3)的语法突出显示和代码缩进.
任何的想法?谢谢!
我试图用EF 6.1.2 Code First实现一个简单的自引用关系.
public class Branch
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
public int? ParentId { get; set; }
[ForeignKey("ParentId")]
public virtual Branch Parent { get; set; }
public ICollection<Branch> Children { get; set; } // direct successors
}
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我只有一个根分支.除了这个单根分支外,每个分支只有一个父分支(根分支的parentId为NULL).除此之外,每个分支都可以有[0..n]个子分支.
我有两个问题:
modelBuilder.Entity<Branch>().HasOptional<Branch>(b => b.Parent).WithMany(b => b.Children).HasForeignKey(b => b.ParentId);但我不确定我是否需要这个..
public IEnumerable<Branch> GetBranches(Branch anyBranch)
{
return anyBranch.Flatten(b => b.Children);
}
Run Code Online (Sandbox Code Playgroud)
和
public static IEnumerable<T> Flatten<T>(this T …Run Code Online (Sandbox Code Playgroud) 我正在使用ASP.NET MVC(最新版本).
想象一下有两页:
第1页:"输入数据">>第2页:"谢谢"
提交Page-1后,您将被重定向到Page-2.
我的目标:当你进入Page-2后,当你点击浏览器的后退按钮时,我想确保你不能回到Page-1.相反,我希望你留在Page-2(或每次按下后退按钮时被推到Page-2).
我尝试过各种各样的事情.以下只是一些简化的伪代码......
[NoBrowserCache]
public ActionResult Page1(int userId)
{
var user = GetUserFromDb(userId);
if (user.HasAlreadySubmittedPage1InThePast)
{
// forward to page 2
return RedirectToAction("Page2", routeValues: new { userId = userId });
}
var model = new Page1Model();
return View("Page1", model);
}
[NoBrowserCache]
[HttpPost]
public ActionResult Page1(Page1Model model)
{
var user = GetUserFromDb(model.UserId);
if (user.HasAlreadySubmittedPage1InThePast)
{
// forward to page 2
return RedirectToAction("Page2", routeValues: new { userId = model.UserId });
}
// Save posted data to the …Run Code Online (Sandbox Code Playgroud) 我在我的Web API(MVC 4)中使用AttributeRouting.
为什么这样做?
[AcceptVerbs("PUT")]
[PUT("api/v1/tokens/current")]
public MemoryToken UpdateToken([FromBody] DeviceTokenViewModel viewModel)
{...}
Run Code Online (Sandbox Code Playgroud)
这一个不是吗?
[PUT("api/v1/tokens/current")]
public MemoryToken UpdateToken([FromBody] DeviceTokenViewModel viewModel)
{...}
Run Code Online (Sandbox Code Playgroud)
错误消息:请求的资源不支持http方法"PUT".为什么我必须明确接受PUT动词?
我只是感到困惑,因为与POST类似的东西工作正常(我不必指定接受的动词):
[POST("api/v1/tokens")]
public MemoryToken CreateToken()
{...}
Run Code Online (Sandbox Code Playgroud)
从其他各种帖子我相信它与我的web.config中的设置有关.Web服务器部分目前看起来像这样:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="AttributeRouting" path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web" />
</handlers>
Run Code Online (Sandbox Code Playgroud)
我尝试过删除WebDav和其他东西.但到目前为止没有任何工作(除非在注释中明确允许PUT动词).
哦,我正在使用Visual …
我正在使用MailKit/MimeKit 1.2.7(最新的NuGet版本).
使用ImapClient删除电子邮件非常简单......
client.Inbox.AddFlags(uniqueId, MessageFlags.Deleted, silent: true);
Run Code Online (Sandbox Code Playgroud)
...如果您知道电子邮件UniqueId或其索引.
就我而言,我不知道其中任何一方.我所拥有的只是消息本身(MimeMessage)和它的MessageId.
我希望MessageId == UniqueId,但显然事实并非如此.
我是否有机会通过拥有相应的MimeMessage/MessageId来删除电子邮件?
我在我的 ASP.NET Core 3.1 应用程序 (MVC) 中使用了区域。
现在我希望所有没有明确区域的请求默认转到“主要”区域。这是我目前设置端点路由的方式:
app.UseEndpoints(endpoints =>
{
// 1
endpoints.MapControllerRoute(
name: "area",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
// 2
endpoints.MapAreaControllerRoute(
name: "default",
areaName: "Main",
pattern: "{area=Main}/{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
我的目标是:
如果请求 URL 包含现有区域名称,请使用路由 [1]。如果没有区域名称,则使用路由[2](默认为“Main”区域)。
我的问题:
如何设置默认区域?
好的,解决了。最后,这对我有用:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapAreaControllerRoute(
name: "default",
areaName: "Main",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud) c# ×4
asp.net-mvc ×2
mimekit ×2
asp.net ×1
asp.net-core ×1
async-await ×1
docker ×1
razor ×1
razor-pages ×1