我想要实现dependency injection
在Asp.Net Core
.因此,在将此代码添加到ConfigureServices
方法之后,两种方式都有效.
services.AddTransient
和service.AddScoped
方法有Asp.Net Core
什么区别?
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddScoped<IEmailSender, AuthMessageSender>();
}
Run Code Online (Sandbox Code Playgroud) 我对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 MVC4中有Web应用程序,我想使用cookie进行用户登录和注销.所以我的行动如下:
登录操作
[HttpPost]
public ActionResult Login(string username, string pass)
{
if (ModelState.IsValid)
{
var newUser = _userRepository.GetUserByNameAndPassword(username, pass);
if (newUser != null)
{
var json = JsonConvert.SerializeObject(newUser);
var userCookie = new HttpCookie("user", json);
userCookie.Expires.AddDays(365);
HttpContext.Response.Cookies.Add(userCookie);
return RedirectToActionPermanent("Index");
}
}
return View("UserLog");
}
Run Code Online (Sandbox Code Playgroud)
LogOut Action
public ActionResult UserOut()
{
if (Request.Cookies["user"] != null)
{
var user = new HttpCookie("user")
{
Expires = DateTime.Now.AddDays(-1),
Value = null
};
Response.Cookies.Add(user);
}
return RedirectToActionPermanent("UserLog");
}
Run Code Online (Sandbox Code Playgroud)
我在_Loyout中使用此cookie如下:
@using EShop.Core
@using …
Run Code Online (Sandbox Code Playgroud) 我想在ASP.NET CORE 1中实现依赖注入.我知道一切都与.Net Core中的DI有关.例如
public void ConfigureServices(IServiceCollection services)
{
// Add application services.
services.AddTransient<IDateTime, SystemDateTime>();
}
Run Code Online (Sandbox Code Playgroud)
但对于拥有20多个实体和服务的Big项目,在ConfigureServices中编写所有这些代码行是如此困难和难以理解.我想知道这是否可能在Startup.cs之外实现依赖注入,然后将其添加到服务中.
谢谢你的回答.
如何在Asp.net MVC3 Razor中将具有类型电子邮件的输入应用于HTML Helper.例如:
<input type="email" name="name" value=" " placeholder="example@mail.ru" />
Run Code Online (Sandbox Code Playgroud)
Razor有替代品吗?
我想知道,在MVC 4中创建下拉列表的最佳方法是什么?使用ViewBag或其他方法?
viewdata html-select html.dropdownlistfor viewbag asp.net-mvc-4
我的项目与run dev命令运行良好,但是当我尝试npm start 时,除了 Index.js 之外,其他页面(pages/...)出现 404 page not found 错误。
我尝试了几种从表单(gthub 问题和博客)中找到的方法,但没有任何效果。
任何的想法?实际上为什么 run dev 和 start 之间应该有区别?我认为我们应该在开发过程中看到我们的应用程序出了什么问题
package.json 中的脚本
"scripts": {
"dev": "next",
"start": "next start",
"build": "next build"
Run Code Online (Sandbox Code Playgroud)
},
和 next.config.js
const withCSS = require("@zeit/next-css");
module.exports = withCSS({
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: "[local]___[hash:base64:5]"
}});
Run Code Online (Sandbox Code Playgroud)
如您所见,安装 nextJS 后我没有进行任何更改。
我尝试通过POST调用从AJAX中删除一个项目.
///// DELETE INDIVIDUAL ROW IN A TABLE /////
jQuery('.stdtable .delete').live('click', function (e) {
//var newsId1 = $(this).attr("title");
e.preventDefault();
var p = jQuery(this).parents('tr');
if (p.next().hasClass('togglerow'))
p.next().remove();
p.fadeOut(function () {
jQuery(this).remove();
});
$.ajax({
URL: "/AdminPanel/News/DeleteNews",
data: { "newsId": 1 },
dataType: "json",
type: "POST",
success: function (msg) {
alert(msg);
}
});
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我得到了Uncaught TypeError:无法读取未定义的属性'ajax'.
我创建WPF应用程序。用户以某种形式将Richtextbox的选定文本更改为超链接。我搜索了一个多小时,然后寻找解决方案。但是不能。我的动态超链接创建如下:
var textRange = RichTextBox.Selection;
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);
var hyperlink = new Hyperlink(textRange.Start, textRange.End)
{
IsEnabled = true,
Foreground = Brushes.Blue
};
hyperlink.NavigateUri = new Uri("http://search.msn.com/" + firstOrDefault.WordId);
var main = new WordMain();
hyperlink.Click += new RoutedEventHandler(main.hyperLink_Click);
RichTextBox.IsDocumentEnabled = true;
RichTextBox.IsReadOnly = false;
Run Code Online (Sandbox Code Playgroud)
如何删除动态超链接的下划线。我想使用textdecoration,但是不能通过代码来实现。
我有一个"类别"实体如下:
public class Category
{
//<Summary>
//Fields...
//</Summary>
public Guid CategoryId { get; set; }
public string CategoryName { get; set; }
public bool IsDelete { get; set; }
// Fields for relationships
public Guid MainCategoryId { get; set; }
public Category MainCategory { get; set; }
public virtual ICollection<Category> ChildCategories { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如上所示,我想在同一个表中创建0-one-to-many关系.我使用Fluent API如下:
HasRequired(category => category.MainCategory)
.WithMany(category => category.ChildCategories)
.HasForeignKey(category => category.MainCategoryId);
Run Code Online (Sandbox Code Playgroud)
但它是一对多的,不是0-1对多.我使用HasOptional,但它给了我一个错误.
如何使用Fluent API执行此操作?
谢谢你的答复
c# entity-framework one-to-many fluent-nhibernate ef-code-first
大家好我拥有_layout
以下内容
<div id="primary_nav">
<ul>
<li class="left active" id="nav_discussion" runat="server">
<a title="Go to Forums" href="@Url.Action("Index", "Home")">Forums</a>
</li>
<li class="left" id="nav_members" runat="server">
<atitle="Go to Member List" href="@Url.Action("Members", "Home")">Members</a>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
这个我用作layout or master page
我创建的每个视图,现在我需要的是当我移动到...Home/Members
我想将Members选项卡设置为活动状态时
请解释我如何在ASP.NET MVC4应用程序中创建更新面板.我寻找了很多博客......但找不到任何有用的方法.这是我的观点
我如何在同一视图中分离这些行为?
我使用ASP.NET CORE Identity创建ASP.NET CORE应用程序.我创建了种子类,用于为第一个启动应用程序保存新用户和角色.在这个种子类中,当我向用户添加角色时,我会收到以下错误.
INSERT语句与FOREIGN KEY约束"FK_AspNetUserRoles_AspNetUsers_UserId"冲突.冲突发生在数据库"DB_A14695_Elvinm",表"dbo.AspNetUsers",列"Id"中.该语句已终止.
我使用以下类来识别身份
public class ApplicationUser : IdentityUser
{
public int Type { get; set; }
public int Flags { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime LastModifiedDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
还有我的种子班
public class DbSeeder
{
#region Private Members
private RvMusicalDbContext DbContext;
private RoleManager<IdentityRole> RoleManager;
private UserManager<ApplicationUser> UserManager;
#endregion Private Members
#region Constructor
public DbSeeder(RvMusicalDbContext dbContext, RoleManager<IdentityRole> roleManager, UserManager<ApplicationUser> userManager)
{
DbContext = dbContext;
RoleManager = roleManager;
UserManager = …
Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc seeding asp.net-identity entity-framework-core
c# ×7
asp.net-core ×3
.net-core ×2
asp.net-mvc ×2
action ×1
ajax ×1
cookies ×1
html-email ×1
html-select ×1
httpcookie ×1
hyperlink ×1
javascript ×1
jquery ×1
json ×1
next.js ×1
npm-start ×1
one-to-many ×1
post ×1
razor ×1
reactjs ×1
richtextbox ×1
seeding ×1
tag-helpers ×1
updatepanel ×1
viewbag ×1
viewdata ×1
wpf ×1