我正在将WebApi2项目迁移到MVC6.由于我们在.NET 4.6.1中编写了其他依赖项,因此我们需要针对相同的版本.
"frameworks": {
"net461": {}}
Run Code Online (Sandbox Code Playgroud)
我添加了依赖项:
"Swashbuckle": "5.3.2",
Run Code Online (Sandbox Code Playgroud)
但问题是没有办法将它连接/注册到ASP.NET Core MVC.
有什么办法吗?
如果我做:
var organisationList = _context.OrganisationCategory.ToList();
Run Code Online (Sandbox Code Playgroud)
它只返回没有组织和类别的列表.它没有回馈组织和类别模型,而是我得到一个列表:
1, null, null
2, null, null
3, null, null
Run Code Online (Sandbox Code Playgroud)
我想我弄错了?在数据库中是组织的ID和正确设置的类别.
OrganisationCategory模型:
public class OrganisationCategory
{
public int ID { get; set; }
public Organisation Organisation { get; set; }
public Category Category { get; set; }
public OrganisationCategory() { }
public OrganisationCategory(Organisation Organisation, Category Category)
{
this.Organisation = Organisation;
this.Category = Category;
}
}
Run Code Online (Sandbox Code Playgroud)
ApplicationDbContextMOdelSnapshot.cs:
modelBuilder.Entity("Implicietmeten.Models.Organisations.Categories.OrganisationCategory", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<int?>("CategoryID");
b.Property<int?>("OrganisationID");
b.HasKey("ID");
});
Run Code Online (Sandbox Code Playgroud) 当我使用Individual User Accounts身份验证创建ASP.NET Core Web项目时,我注意到VS2015创建了AccountController具有许多操作方法的。这些动作方法大多数都包含输入可选参数string returnUrl = null,在这些方法ViewData["ReturnUrl"] = returnUrl;中,如下面的一个示例所示。
问题:
ViewData["ReturnUrl"] = returnUrl;在这些操作方法中,此可选输入参数和语句的用途是什么?2.什么时候应该在动作方法中使用它们,什么时候应该避免使用它们?获取方法:
[HttpGet]
[AllowAnonymous]
public IActionResult Login(string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
return View();
}
Run Code Online (Sandbox Code Playgroud)
发布方式:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
if (ModelState.IsValid)
{
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, …Run Code Online (Sandbox Code Playgroud) 我试图在我的Windows 7开发框中安装ASP.NET Core 1.0.1,该框已经在Visual Studio社区2015 Update 3中使用了ASP.NET Core 1.0.
为了实现这一点,我.NET Core 1.0.1 - VS 2015 Tooling Preview 2从https://blogs.msdn.microsoft.com/dotnet/2016/09/13/announcing-september-2016-所示的https://www.microsoft.com/net/core#windows安装.更新换网核心-1-0 /
然后我将现有project.json文件中的几个版本号从1.0.0更新到1.0.1,以便我的Web应用程序将使用新的1.0.1组件.
正如预期的那样,这会触发包恢复,但不幸的是它失败了.我无法弄清楚包恢复失败的原因.任何帮助将不胜感激.
以下是输出窗口中的错误:
C:\ Users\Ron Clabo\Documents\Visual Studio 2015\Projects\wwwGiftOasisResponsive\src\wwwGiftOasisResponsive\wwwGiftOasisResponsive.xproj中的错误无法为'.NETFramework解析'Microsoft.AspNetCore.Server.IISIntegration(> = 1.0.1)' ,版本= v4.5.2' .PATH =.\node_modules.bin; C:\ Program Files(x86)\ Microsoft Visual Studio 14.0\Web\External;%PATH%; C:\ Program Files(x86)\ Microsoft Visual Studio 14.0\Web\External\git C :\ Program Files\dotnet\dotnet.exe恢复"C:\ Users\Ron Clabo\Documents\Visual Studio 2015\Projects\wwwGiftOasisResponsive.vs\restore.dg"日志:恢复C:\ Users\Ron Clabo\Documents的包\ Visual Studio 2015\Projects\wwwGiftOasisResponsive\src\wwwGiftOasisResponsive\project.json ...错误:无法为'.NETFramework,Version = v4.5.2解析'Microsoft.AspNetCore.Server.IISIntegration(> = 1.0.1)' ".日志:在C:\ Users\Ron Clabo\Documents\Visual Studio 2015\Projects\wwwGiftOasisResponsive\src\wwwGiftOasisResponsive\project.json ... log中恢复工具'Microsoft.AspNetCore.Server.IISIntegration.Tools'的包:写入锁定文件到磁盘.路径:C:\ Users\Ron …
当我请求[授权]装饰的控制器操作而不是重定向到登录页面时,我收到401错误.
这是一个使用IIS Express上运行的身份模板的.net核心mvc应用程序.
当我从program.cs运行应用程序时,重定向到登录工作正常.我已经为cookie身份验证添加了明确的指示,以便在配置和服务部分使用/ Account/Login重定向,以及配置Identity来执行此重定向.
我无法让它发挥作用.下面是我的StartUp类,我应该更改什么才能使它在IIS express中运行?:
public class Startup
{
private MapperConfiguration _mapperConfiguration { get; set; }
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
_mapperConfiguration = new MapperConfiguration(cfg =>
{
cfg.AddProfile(new AutoMapperProfileConfiguration());
});
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the …Run Code Online (Sandbox Code Playgroud) redirect http-status-code-401 iis-express asp.net-identity asp.net-core-mvc
我正在通过asp.net核心构建一个mvc web api.但发现在请求中不能反序列化json体是很奇怪的.
目标对象如下
public class Status
{
public string Content {get; set;}
public string Publisher {get; set;}
public List<string> Tags {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
在请求中发布的json是这样的:
{
"content":"this is my baby dog",
"publisher":"someone"
"tags":[ "tag1", "tag2" ]
}
Run Code Online (Sandbox Code Playgroud)
控制器中的api方法是:
[HttpPost]
public IActionResult Publish([FromBody] Status status)
{
// status should be deserialized now
}
Run Code Online (Sandbox Code Playgroud)
测试时,状态始终为null.但是如果我发布没有标签列表的json,则可以成功地反序列化状态.所以这里的失败原因似乎是由List引起的.但它应该能够在没有任何特殊配置的情况下进行反序列化,对吧?
我有一个跟踪我们用户迁移状态的应用程序的这个模型.如果尚未迁移,则没有迁移日期.那么他们怎么能把这个领域留空呢?它没有按要求注释,但验证失败,就好像它是必需的.我似乎无法将其设置为null.如何解决这个问题?
[Display(Name = "Migrated?")]
public bool migrated { get; set; }
[Display(Name = "Date Migrated")]
public DateTime migrationdate { get; set; }
Run Code Online (Sandbox Code Playgroud) 我对这个问题有一个非常非常类似的问题.
你好.
我有一个针对.NET 4.61的应用程序(服务),并尝试使用WebListener转移到AspNetCore自托管主机.
我试图通过在控制台应用程序中测试它来调查这些要求.
我装箱该项目是一个正常的Windows控制台应用程序,我引用的所有的NuGet需要的软件包,并创建所需的启动类,并创建和启动与WebHostBuilder主机.
(我没有正常的Windows控制台应用程序,但是我的ubuntu笔记本电脑上有一个dotnet控制台应用程序)
我们之前尝试和测试的内容有所不同.
到现在为止,我只是做了HomeController ,不得不Index返回一个string用"Hello world".跑完应用程序,转到localhost并得到响应.完善.
现在,我添加的是Index返回IActionResult View().然后我创建了一个Index.cshtml文件/Views/Home/,现在我得到了这个:
失败:Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware [0]已发生了未处理的异常:一个或多个编译错误发生:
其次是150行,如下所示:
gee1fd0w.wuj(4,11):错误CS0246:找不到类型或命名空间名称'System'(您是否缺少using指令或程序集引用?)
gee1fd0w.wuj(5,11):错误CS0246:无法找到类型或命名空间名称'System'(您是否缺少using指令或程序集引用?)
gee1fd0w.wuj(6,11):error CS0246:找不到类型或命名空间名称'System'(是你错过了using指令或程序集引用吗?)
...
gee1fd0w.wuj(37,13):错误CS0518:未定义或导入预定义类型'System.Object'gee1fd0w.wuj
(37,13):错误CS0518:未定义或导入预定义类型"System.Void"
结束于:
gee1fd0w.wuj(33,36):错误CS0161:'_ Views_Home_Index_cshtml.ExecuteAsync()':并非所有代码路径都返回
Microsoft.AspNetCore.Mvc上的Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationResult.EnsureSuccessful()的值
. Razor.Internal.CompilerCache.CreateCacheEntry(String relativePath,String normalizedPath,Func'2 compile)
---从抛出异常的上一个位置开始的堆栈跟踪结束---
其次是:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.GetOrAdd(String relativePath,Func'2 compile)
at at Microsoft.AspNetCore.Mvc.Razor上的Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath),
位于Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet`1 expirationTokens,String relativePath,Boolean isMainPage)
. Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context,String viewName )
中的Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext,String pageName,Boolean isMainPage)
中的RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext …
我正在尝试使用Runspace Factory在C#中作为另一个用户运行powershell命令.在每个例子中,我发现有使用的建议,WSManConnectionInfo并且PSCredential需要密码的"SecureString".这是我第一次听说过SecureString.用法示例包括:
var con = new WSManConnectionInfo();
con.Credential = new PSCredential(strDomain + "\\" + strUser, strPW.ToSecureString());
Run Code Online (Sandbox Code Playgroud)
没有名为"ToSecureString"的字符串扩展方法,所以我在这里不知道如何添加它.如何向字符串添加ToSecureString方法?
我是.net核心的新手,所以我所做的是创建标题,日期,描述,图像的文章
这是我的模特
public class Article
{
[Key]
public int Id { get; set; }
[StringLength(200)]
[Required(ErrorMessage = "Required")]
public string ArticleTitle { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime ArticleDate { get; set; }
[DataType(DataType.MultilineText)]
public string ArticleDescriotion { get; set; }
public string ArticleImage { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是控制器
public IActionResult CreateArticle()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult CreateArticle(Article article)
{
if (ModelState.IsValid)
{
context.Articales.Add(article);
context.SaveChanges();
return RedirectToAction("Index");
}
return View(article);
} …Run Code Online (Sandbox Code Playgroud) asp.net-core-mvc ×10
asp.net-core ×6
c# ×6
.net ×1
iis-express ×1
json ×1
powershell ×1
razor ×1
redirect ×1
swagger ×1
swashbuckle ×1