这一页
https://docs.microsoft.com/en-us/aspnet/core/client-side/spa-services?view=aspnetcore-3.0
说,Microsoft.AspNetCore.SpaServices与Microsoft.AspNetCore.NodeServices已经过时,“一个简单的SPA框架的集成可用的机制”,在Microsoft.AspNetCore.SpaServices.Extensions。
我根本找不到任何文档Microsoft.AspNetCore.SpaServices.Extensions。似乎没有相应的命名空间,所以我什至无法使用智能感知找到任何东西。
过时公告https://github.com/aspnet/AspNetCore/issues/12890同样含糊不清。
具体来说,我试图找出如何将呼叫升级到 app.UseWebpackDevMiddleware
我正在开发一个需要与现有用户数据库集成的Web应用程序.我仍然想使用这些[Authorize]属性,但我不想使用Identity框架.如果我确实想使用Identity框架,我会在startup.cs文件中添加这样的内容:
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Password.RequireNonLetterOrDigit = false;
}).AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
我假设我必须在那里添加其他东西,然后创建一些实现特定接口的类?有人能指出我正确的方向吗?我正在使用asp.net 5的RC1.
在ASP.NET 4中,这与应用程序routes.LowercaseUrls = true;的RegisterRoutes处理程序一样简单.
我无法在ASP.NET Core中找到实现此目的的等价物.我想它会在这里:
app.UseMvc(configureRoutes =>
{
configureRoutes.MapRoute("Default", "{controller=App}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
但configureRoutes看起来没什么可以允许的......除非在某个地方找到一个我在文档中找不到的扩展方法呢?
尝试使用带有Update 3的Visual Studio 15 Enterprise在ASP.NET Core项目中添加Controller时,出现以下错误:
"The was an error running the selected code generator: No executables found matching command 'dotnet-aspnet-codegenerator'"
要在MVC5中获取当前登录的用户,我们所要做的就是:
using Microsoft.AspNet.Identity;
[Authorize]
public IHttpActionResult DoSomething() {
string currentUserId = User.Identity.GetUserId();
}
Run Code Online (Sandbox Code Playgroud)
现在,使用ASP.NET Core我认为这应该可行,但它会引发错误.
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Http;
private readonly UserManager<ApplicationUser> _userManager;
[HttpPost]
[Authorize]
public async Task<IActionResult> StartSession() {
var curUser = await _userManager.GetUserAsync(HttpContext.User);
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
编辑: Gerardo的回应是正常的,但要获得用户的实际"Id",这似乎工作:
ClaimsPrincipal currentUser = this.User;
var currentUserID = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;
Run Code Online (Sandbox Code Playgroud) 在MVC 5中,您可以使用HTTP代码抛出HttpException,这将设置响应,如下所示:
throw new HttpException((int)HttpStatusCode.BadRequest, "Bad Request.");
Run Code Online (Sandbox Code Playgroud)
ASP.NET 5/MVC 6中不存在HttpException.等效代码是什么?
在Web API 2中,您曾经能够通过中间件设置OAuth授权服务器来创建端点以发出令牌,如下所示:
//Set up our auth server options.
var OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new SimpleAuthorizationServerProvider()
};
// Sets up the token issue endpoint using the options above
app.UseOAuthAuthorizationServer(OAuthServerOptions);
Run Code Online (Sandbox Code Playgroud)
也许我错过了它,但我想弄清楚如何在ASP.NET Core中做到这一点.我查看了源代码(https://github.com/aspnet/Security),但我真的没有看到类似的东西.有没有新的方法来实现这一目标?我是否需要创建一个控制器并自己完成?
我看到如何通过中间件设置OAuth身份验证,但这涉及我从API发出声明的授权部分.
要了解有关新的令人兴奋的Asp.Net-5框架的更多信息,我正在尝试使用新发布的Visual Studio 2015 CTP-6构建Web应用程序.
大多数事情看起来很有希望,但我似乎无法找到Request.IsAjaxRequest() - 我在旧的MVC项目中经常使用的功能.
有没有更好的方法来做到这一点 - 这使他们删除了这个方法 - 还是"隐藏"在其他地方?
感谢您在何处找到它或做什么的建议!
此时我正在轻松地将内容注入到我的控制器中,在某些情况下构建我自己的ResolverServices类.生活很美好.
我无法弄清楚如何做的是让框架自动注入到非控制器类中.框架自动注入我的控制器的工作是什么IOptions,这实际上是我的项目的配置:
public class MessageCenterController : Controller
{
private readonly MyOptions _options;
public MessageCenterController(IOptions<MyOptions> options)
{
_options = options.Value;
}
}
Run Code Online (Sandbox Code Playgroud)
我认为我可以在我自己的类中发生同样的情况,我认为当我模仿控制器时我会接近,就像这样:
public class MyHelper
{
private readonly ProfileOptions _options;
public MyHelper(IOptions<ProfileOptions> options)
{
_options = options.Value;
}
public bool CheckIt()
{
return _options.SomeBoolValue;
}
}
Run Code Online (Sandbox Code Playgroud)
我想我失败的地方就是我这样称呼它:
public void DoSomething()
{
var helper = new MyHelper(??????);
if (helper.CheckIt())
{
// Do Something
}
}
Run Code Online (Sandbox Code Playgroud)
我跟踪它的问题实际上是关于DI的所有内容都是在控制器级别讨论它.我试图找到它在Controller对象源代码中发生的位置,但它在那里变得有点疯狂.
我知道我可以手动创建一个IOptions实例并将其传递给MyHelper构造函数,但似乎我应该能够让框架做到这一点,因为它适用于Controllers.
非常感谢您的帮助.
MVC 6引入了View组件,并表示它比部分视图更强大,更灵活.视图组件是否意味着替换部分视图?有什么区别以及每种实施需要什么样的情况?
asp.net-core-mvc ×10
asp.net-core ×8
c# ×6
asp.net ×3
.net-core ×2
.net ×1
asp.net-mvc ×1
oauth ×1
webpack ×1