如何使用C#代码从Windows Active Directory获取当前用户的登录名?
我正在使用Visual Studio 2012中的MVC4进行项目,并在表中添加了一列.
现在,当我想调试我的项目时,错误说使用迁移来更新我的数据库.
我该怎么办?
我一直在搜索,发现了一些方法,如:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer<ResTabelaIndex>(null);
}
Run Code Online (Sandbox Code Playgroud)
但不知道如何和在哪里实施这个......曾试图app_start,global.asax等...
我发现的是,从nuget直接在控制台中启用迁移.
但我无法做到这一点.
我使用的命令:
Enable-Migrations -EnableAutomaticMigrations
Run Code Online (Sandbox Code Playgroud)
==>控制台说找到了多个上下文.为了能够使用,Enable-Migrations -ContextTypeName NameOfTheNamespace.Models.DefaultConnection
但我不知道是什么-ContextTypeName,已经尝试了很多但无法理解.
My Model Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.Migrations;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.Infrastructure;
namespace Vista.Models
{
public class TabelaIndex
{
public int ID { get; set; }
public string n_empresa { get; set; }
public string titulo{ get; set; }
public …Run Code Online (Sandbox Code Playgroud) 目前,我ApiController正在返回XML作为响应,但对于单个方法,我想返回JSON.即我无法进行全局更改以强制响应为JSON.
public class CarController : ApiController
{
[System.Web.Mvc.Route("api/Player/videos")]
public HttpResponseMessage GetVideoMappings()
{
var model = new MyCarModel();
return model;
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试这样做,但似乎无法正确地将我的模型转换为JSON字符串:
var jsonString = Json(model).ToString();
var response = this.Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");
return response;
Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc asp.net-web-api asp.net-apicontroller asp.net-web-api2
我正在开发一个页面,显示休假类型选项的所有值的网络网格(这是一个包含 id、LeaveType 和状态的模型)。在我的控制器中,我写了下面的内容。
运行代码后,出现运行时错误
InvalidOperationException:属性“JsonResult.SerializerSettings”必须是类型“System.Text.Json.JsonSerializerOptions”的实例
我尝试用谷歌搜索,但我不明白这个问题,我想寻求有关如何解决这个问题的建议。
谢谢。
public class OptLeaveTypeController : Controller
{
private readonly theManagerContext _context;
public OptLeaveTypeController(theManagerContext context)
{
_context = context;
}
public IActionResult Index()
{
return View();
}
public IActionResult GetLeaveTypes()
{
var leaveTypes = _context.OptLeaveType.OrderBy(a => a.LeaveTypeId).ToList();
return Json(new { data = leaveTypes }, System.Web.Mvc.JsonRequestBehavior.AllowGet);
}
}
Run Code Online (Sandbox Code Playgroud) 我想检索使用MemoryCache添加的所有缓存对象.
我尝试了以下但它没有检索它们
System.Web.HttpContext.Current.Cache.GetEnumerator(); System.Web.HttpRuntime.Cache.GetEnumerator();
注意:Retreive all不仅仅意味着我所知道和创建的,我的意思是在应用程序中创建的每个缓存对象.
我最近开了一个Asp .Net Core应用程序.后来我想将它与角整合,但首先我需要一个机制,将"替换" cshtml用html.
如果我改变扩展名cshtml,html我就得到这个
'InvalidOperationException:找不到'索引'视图'.
我也尝试过Startup
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
但它也没有用.
可选的是将cshtml布局内容与html页面集成,但我认为这是不可能的.
所以,我的问题是,我可以简单地用html替换所有的cshtml吗?
我正在尝试验证必须具有九位数代码且不能以四个零或四个九结尾且必须输入的不带特殊字符的属性。
我尝试了以下代码-
[RegularExpression(@"(^(?i:([a-z])(?!\1{2,}))*$)|(^[A-Ya-y1-8]*$)", ErrorMessage = "You can not have that")]
public string Test{ get; set; }
Run Code Online (Sandbox Code Playgroud)
但这不起作用。
例如: exasdea0000,asdea9999,exasde@0000或as_ea9999不能被输入。
我该如何实现?
最近我安装了 Visual Studio 2017 Enterprise,当我打开任何文件(如 .cs、.cshtml)时,每次光标变为灰色矩形时,编辑器就好像处于 Over-strike 模式,即使底部的指示器窗口上写着“INS”。
所以我点击了几次插入按钮,然后在“OVR”和“INS”之间循环,光标又回到“|” 我开始编码。然后,当我突出显示某些文本时,它会再次发生。这是非常令人沮丧和痛苦的。
双击指示器具有与插入按钮相同的临时结果。
那么我怎样才能永久解决我的问题呢?
c# insert visual-studio mouse-cursor vim-syntax-highlighting
c# ×7
asp.net-mvc ×6
asp.net ×3
.net ×2
.net-core ×1
asp.net-core ×1
insert ×1
json ×1
memorycache ×1
migration ×1
mouse-cursor ×1
razor ×1
regex ×1