我有一个需求,至少现在是,基于 .NET Core 网站的用户名创建一个子目录。哪里是最好的地方?
我尝试添加 ApplicationUser ,但不确定如何正确添加它。我所拥有的,我知道是完全错误的,如下。
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace BRSCRM.Models
{
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser
{
private IHostingEnvironment hostingEnvironment;
public string HomeDir { get; set; }
HomeDir=HostingEnvironment.WebRootPath + UserName;
string path = this.hostingEnvironment.WebRootPath + "\\uploads\\" + UserName;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
}
Run Code Online (Sandbox Code Playgroud)
我希望文档更好。似乎他们有很多入门资料,但是当您尝试做一些未涵盖的内容时,很难找到帮助。
我正在尝试做的是支持成员的文件上传。
我想我越来越近了,但我现在收到此错误:>“Microsoft.AspNetCore.Hosting.IHostingEnvironment”。模型绑定复杂类型不能是抽象类型或值类型,并且必须具有无参数构造函数 Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexTypeModelBinder.CreateModel(ModelBindingContext
我似乎无法读取 IHostingEnvironment webrootpath。这太令人沮丧了!!
我将代码移到文件AccountController.cs 中的 Register 操作中...
这是我到目前为止..
if (result.Succeeded)
{
await _userManager.AddToRoleAsync(user, …Run Code Online (Sandbox Code Playgroud)