我对ASP.NET MVC 1-5有很多经验.现在我学习ASP.NET Core MVC并且必须将参数传递给页面中的链接.例如,我有以下Action
[HttpGet]
public ActionResult GetProduct(string id)
{
ViewBag.CaseId = id;
return View();
}
Run Code Online (Sandbox Code Playgroud)
如何使用标记帮助程序实现此操作的链接?
<a asp-controller="Product" asp-action="GetProduct">ProductName</a>
Run Code Online (Sandbox Code Playgroud) 我正在使用ASP.NET Core.我想使用,HttpClient但我注意到有两个NuGet包提供.我用哪一个?
能告诉我如何获取客户端在MVC 6,asp.net 5中使用的浏览器的名称吗?
我有一个ASP.NET MVC核心应用程序,我正在编写单元测试.其中一个操作方法使用用户名来实现某些功能:
SettingsViewModel svm = _context.MySettings(User.Identity.Name);
Run Code Online (Sandbox Code Playgroud)
这显然在单元测试中失败了.我环顾四周,所有建议都是从.NET 4.5到模拟HttpContext.我相信有更好的方法可以做到这一点.我试图注入IPrincipal,但它引发了一个错误; 我甚至试过这个(出于绝望,我想):
public IActionResult Index(IPrincipal principal = null) {
IPrincipal user = principal ?? User;
SettingsViewModel svm = _context.MySettings(user.Identity.Name);
return View(svm);
}
Run Code Online (Sandbox Code Playgroud)
但这也引发了一个错误.无法在文档中找到任何内容......
我需要在.NET Core(MVC6)中解码HTML字符.看起来.NET Core没有WebUtility.HtmlDecode函数,之前每个人都用它..NET Core中是否存在替代品?
我正在尝试将ASP.NET MVC webform迁移到ASP.NET Core MVC.目前,我在Request.UrlReferrer上课时遇到了麻烦.
原来的行是:
[HttpPost]
public async Task<ActionResult> ContactUsFormSubmit(ContactUs request)
{
var siteUrl = Request.UrlReferrer.ToString().ToLower();
....
}
Run Code Online (Sandbox Code Playgroud)
但是,使用ASP.NET Core时,UrlReferrer不可用.我发现了以下内容:
Request.Headers["Referer"]
Run Code Online (Sandbox Code Playgroud)
返回StringValues而不是String.我不确定我是否应该尝试使用这个或者是否有任何其他解决方案.Request.ServerVariables也不可用或者我没有命名空间.我的命名空间如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Run Code Online (Sandbox Code Playgroud)
如果有人能指引我朝着正确的方向前进,我真的很感激.
默认情况下,ASP.NET 5中提供的默认身份提供程序具有非常严格的密码规则,需要小写字符,大写字符,非字母数字字符和数字.我正在寻找一种方法来改变提供商的密码要求.
以前在ASP.NET 4中,可以通过Web.config XML文件配置提供程序,如前所述.但是,ASP.NET 5使用基于新代码的配置模式,并且不清楚如何配置身份.
如何更改应用程序的密码要求?
假设我们有这个模型:
public class Tiers
{
public List<Contact> Contacts { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和
public class Contact
{
public int Id { get; set; }
public Tiers Tiers { get; set; }
public Titre Titre { get; set; }
public TypeContact TypeContact { get; set; }
public Langue Langue { get; set; }
public Fonction Fonction { get; set; }
public Service Service { get; set; }
public StatutMail StatutMail { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
使用EF7,我想从Tiers表中检索所有数据,包括Contact表中的数据,Titre表中的数据,TypeContact表中的数据等等......只需一条指令.使用Include/ThenInclude API,我可以编写如下内容:
_dbSet
.Include(tiers => …Run Code Online (Sandbox Code Playgroud) 我想知道是否有替换System.Web.HttpUtility.UrlEncode和UrlDecode.
正如我发现Encode它应该是: Microsoft.Framework.WebEncoders.UrlEncoder.Default.UrlEncode.
但我没有找到UrlDecode.有吗?
是否可以IOptions<AppSettings>从ConfigureServicesStartup中的方法解析实例?通常,您可以使用IServiceProvider初始化实例,但在注册服务时此阶段没有实例.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(
configuration.GetConfigurationSection(nameof(AppSettings)));
// How can I resolve IOptions<AppSettings> here?
}
Run Code Online (Sandbox Code Playgroud) asp.net-core-mvc ×10
c# ×8
asp.net-core ×7
asp.net ×2
asp.net-mvc ×2
.net ×1
httpclient ×1
nuget ×1
tag-helpers ×1
unit-testing ×1
xunit.net ×1