我正在研究一个将"嵌入"Windows 7系统的项目,这将通过禁用任务管理器并将Windows shell更改为应用程序以及其他内容来实现.
我在这里要做的是以编程方式更改应用程序和explorer.exe之间的Windows shell,我想知道是否有任何方法可以在C#中执行此操作.
目前我有几行代码尝试更改Windows Shell的注册表项,但刷新注册表编辑器后似乎没有任何内容,代码如下所示:
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", true).OpenSubKey("Microsoft", true).OpenSubKey("Windows NT", true).OpenSubKey("CurrentVersion", true).OpenSubKey("Winlogon", true);
regKey.DeleteValue("Shell");
regKey.SetValue("Shell", shell);
regKey.Close();
Run Code Online (Sandbox Code Playgroud)
我已经尝试重新启动Windows以查看是否允许shell更改完成,但无济于事.
如果有人能告诉我是否有可能以编程方式进行,以及我在哪里出错,我将不胜感激.
此外,我很高兴知道是否有一种方法来编写程序,以便它始终以管理员权限运行,以便注册表编辑工作.
非常感谢,
理查德
我正在尝试确定如何将/ News/5的路由映射到我的新闻控制器.
这是我的NewsController:
public class NewsController : BaseController
{
//
// GET: /News
public ActionResult Index(int id)
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Global.asax.cs规则:
routes.MapRoute(
"News", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "News", action = "Index", id = -1 } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud)
我尝试去/ News/5但是我收到了资源未找到错误,但是当进入/ News/Index/5时它有效吗?
我尝试过,{controller}/{id}但这只是产生了同样的问题.
谢谢!
我有一个简单的类,我想在构造函数启动的方法中为只读属性赋值,但它说[ts] Cannot assign to 'readOnlyProperty' because it is a constant or a read-only property.
为什么即使我process从构造函数调用,我也不能为属性赋值?
示例代码:
class C {
readonly readOnlyProperty: string;
constructor(raw: string) {
this.process(raw);
}
process(raw: string) {
this.readOnlyProperty = raw; // [ts] Cannot assign to 'readOnlyProperty' because it is a constant or a read-only property.
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个部分Left,其中包含我的特定页面的导航内容.
现在我想在其中显示一个TreeView,因此我创建了一个局部视图来将特定模型传递给该视图.现在我正在尝试将该特定视图呈现到我的部分中 - 但该部分保持为空.
这不起作用:
@section Left {
@Html.Partial("PartialNavigationView")
}
Run Code Online (Sandbox Code Playgroud)
渲染该东西会返回一个错误Expression must return a value to render:
@section Left {
@Html.RenderPartial("PartialNavigationView")
}
Run Code Online (Sandbox Code Playgroud)
如何将部分视图渲染到我的部分?
我通过html帮助器和TagBuilder生成HTML文本框.
我们有方法TagBuilder.Attributes.Add("key","value")
但是对于HTML5,必需属性不需要传递值,所以如果我传递空字符串,则输出值为required =""
那么如何在不传递值的情况下添加必需属性呢?
public static IHtmlString AppTextBox(this HtmlHelper helper, string model)
{
var input = new TagBuilder("input");
input.Attributes.Add("class", "form-control");
input.Attributes.Add("ng-model", model);
input.Attributes.Add("required","");
return new MvcHtmlString(input.ToString(TagRenderMode.Normal));
}
Run Code Online (Sandbox Code Playgroud) 我正在按照John Papa在其最新的PluralSight课程中概述的方法,使用Angular,Breeze和Web API 2构建SPA.
一切运作良好,我可以拉取信息,更新,插入,删除回服务器.但是我正在使用空间类型,当我尝试更新具有空间类型的实体时,我收到以下错误
Newtonsoft.Json.dll中出现"Newtonsoft.Json.JsonSerializationException"类型的异常,但未在用户代码中处理
附加信息:从'System.Data.Entity.Spatial.DbGeometry'上的'WellKnownValue'获取值时出错.
内部异常似乎指向WellKnownValue为空的事实,但它不是,因为我检查了发送到服务器的JSON,然后将其发送到Breeze ContextProvider并使用SaveChanges方法保存.
{
"entities": [
{
"TableKey": 2,
"CaseName": "Mikhail Lermontov",
"StartDate": "2013-06-11T00:00:00Z",
"EndDate": null,
"IsCurrent": true,
"SRID": 109,
"Shape": {
"$id": "2",
"$type": "System.Data.Entity.Spatial.DbGeometry, EntityFramework",
"Geometry": {
"$id": "3",
"$type": "System.Data.Entity.Spatial.DbGeometryWellKnownValue, EntityFramework",
"CoordinateSystemId": 2193,
"WellKnownText": "POLYGON ((1695943 5462665, 1713098 5462665, 1713098 5449659, 1695943 5449659, 1695943 5462665))"
}
},
"SpillLocation": "Marlborough Sounds",
"Image": "http://www.nzmaritime.co.nz/images/lm5.jpg\r\n",
"DefaultBaseMapKey": 2,
"__unmapped": {
"isPartial": false
},
"entityAspect": {
"entityTypeName": "DatSpillCase:#Osiris.Model",
"defaultResourceName": "DatSpillCases",
"entityState": "Modified",
"originalValuesMap": {
"CaseName": "Mikhail …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Azure SQL中托管的数据库和Entity Framework 6上的Effort框架编写测试.
执行以下代码时,抛出异常:
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
EffortProviderConfiguration.RegisterProvider();
}
[TestMethod]
public void TestMethod1()
{
const string connectionString = "Data Source=***;Initial Catalog=my_catalog;User ID=user;Password=password;provider=System.Data.SqlClient";
IDataLoader loader = new EntityDataLoader(connectionString);
using (var ctx = new UsersDbContext(Effort.DbConnectionFactory.CreatePersistent("cool", loader)))
{
var usersCount = ctx.Users.Count();
}
}
Run Code Online (Sandbox Code Playgroud)
Count()执行中抛出异常:
Effort.Exceptions.EffortException:尝试初始化'Table'表的内容时出现未处理的异常---> System.ArgumentException:不支持关键字:'data source'.
EffortProviderConfiguration.RegisterProvider()使用app.config设置替换时会抛出相同的异常.
当使用完全相同的连接字符串创建UsersDbContext它时,它成功并且可以访问数据.此外,使用Effort持久或临时模式创建上下文,没有连接字符串,也可以很好地工作.
如何使用真实数据库中的现有数据初始化连接?
我一直在尝试重新创建ValidateAntiForgeryToken的Ajax版本 - 有许多关于如何为以前版本的MVC执行此操作的博客文章,但是对于最新的MVC 6,没有任何代码是相关的.不过,我要追求的核心原则是验证Cookie和Header __RequestVerificationToken,而不是将Cookie与表单值进行比较.我使用的是MVC 6.0.0-rc1-final,dnx451框架,所有的Microsoft.Extensions库都是1.0.0-rc1-final.
我最初的想法是继承ValidateAntiForgeryTokenAttribute,但是看一下源代码,我需要返回自己的授权过滤器实现来让它看看标题.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class ValidateAjaxAntiForgeryTokenAttribute : Attribute, IFilterFactory, IFilterMetadata, IOrderedFilter
{
public int Order { get; set; }
public bool IsReusable => true;
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
{
return serviceProvider.GetRequiredService<ValidateAjaxAntiforgeryTokenAuthorizationFilter>();
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我随后制作了自己的ValidateAntiforgeryTokenAuthorizationFilter版本
public class ValidateAjaxAntiforgeryTokenAuthorizationFilter : IAsyncAuthorizationFilter, IAntiforgeryPolicy
{
private readonly IAntiforgery _antiforgery;
private readonly ILogger _logger;
public ValidateAjaxAntiforgeryTokenAuthorizationFilter(IAntiforgery antiforgery, ILoggerFactory loggerFactory)
{
if (antiforgery == null)
{
throw new ArgumentNullException(nameof(antiforgery));
} …Run Code Online (Sandbox Code Playgroud) 我很难用键入我的Map对象typescript 1.8.10.以下是core-js定义Map接口的摘录:
interface Map<K, V> {
clear(): void;
delete(key: K): boolean;
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
get(key: K): V;
has(key: K): boolean;
set(key: K, value?: V): Map<K, V>;
size: number;
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个使用字符串键的地图,并且只存储具有该形状的值{name:string,price:number}.我尝试用以下方式声明我的对象:
let oMap:Map<string,{name:string,price:number}> = new Map();
Run Code Online (Sandbox Code Playgroud)
但是,编译器会抛出错误TS2322: Type 'Map<{}, {}>' is not assignable to type 'Map<string, { name: string; price: number; }>'.Map在打字稿中使用ES6 对象时,有没有办法利用强类型?
我有一个List<Fruit>,
public class Fruit
{
public string Name { get; set; }
public string Type { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并且上面的列表包含两种类型的30个Fruit对象:Apple和Orange.20个苹果和10个橙子.
List<Fruit> fruits = new List<Fruit>();
fruits.Add(new Fruit(){ Name = "Red Delicious", Type = "Apple" });
fruits.Add(new Fruit(){ Name = "Granny Smith", Type = "Apple" });
fruits.Add(new Fruit(){ Name = "Sour Granny", Type = "Orange" });
fruits.Add(new Fruit(){ Name = "Delicious Yummy", Type = "Orange" });
.....
Run Code Online (Sandbox Code Playgroud)
我如何获得10个随机水果的清单(来自30个水果的篮子),但应该有3个橙子和7个苹果?
c# ×6
asp.net-mvc ×3
razor ×2
typescript ×2
ajax ×1
asp.net ×1
breeze ×1
class ×1
constructor ×1
dnx ×1
ecmascript-6 ×1
effort ×1
javascript ×1
json ×1
linq ×1
registry ×1
routes ×1
shell ×1
unit-testing ×1
windows ×1