小编dav*_*v_i的帖子

如何使用.htaccess进行多次重写?

我正在尝试使用Drupal构建一个多语言网站.

我喜欢以下网址格式

http://domain/[language]/[node id]

所以我将以下规则添加到.htaccess中以进行测试

RewriteRule ^jpn/[0-9]$ jpn.html

问题是该规则被以下规则覆盖

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

我如何有多个重写规则?

.htaccess mod-rewrite

5
推荐指数
1
解决办法
2万
查看次数

INotifyCollectionChanged的NewItems - 不能使用OfType <T>来获取数据

我试图从CollectionChanged实现的集合事件中获取一些自定义对象INotifyCollectionChanged.

MyControl_MyCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
  if(e.Action == NotifyCollectionChangedAction.Add)
  {
    lock(e.NewItems.SyncRoot)
    {
      var myItems = e.NewItems.OfType<MyType>();

      if(myItems.Any())
      {
        //do stuff
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我面临的问题是myItems总是说"枚举没有结果".

扩展调试e.NewItems.SyncRoot显示以下内容:

e.NewItems.SyncRoot | {object[1]}
|-[0] | {System.Linq.Enumerable.WhereSelectListIterator<MyType, IMyInterface>}
| |-base ...
| |-Non-public members
| |-Results View | Expanding the Results View...
|   |-[0] | MyType
Run Code Online (Sandbox Code Playgroud)

很明显,数据就在那里.检索此数据的方法是什么?

c# linq inotifycollectionchanged

5
推荐指数
1
解决办法
1006
查看次数

使用匿名类型时,在"加入"调用中类型推断失败

我对LINQ to SQL有一个特殊的问题:

这样做很好:

from s in Something
join a in AnotherThing
on s.NullableDateTime.Value
equals a.DateTime
select s
Run Code Online (Sandbox Code Playgroud)

但是,使用匿名类型如下:

from s in Something
join a in AnotherThing
on new { s.NullableDateTime.Value }
equals new { a.DateTime }
select s
Run Code Online (Sandbox Code Playgroud)

结果是

join子句中某个表达式的类型不正确.调用"加入"时类型推断失败.

我需要使用匿名类型,因为我的目标是添加另一列来加入.

有关为什么会发生这种情况以及如何解决的任何想法?

c# linq linq-to-sql

5
推荐指数
1
解决办法
6486
查看次数

如何在控制台应用程序中设置默认连接字符串?

在我的带有Web界面的MVC项目中,我习惯在Web.Config文件中设置连接字符串.

但是,现在我正在制作一个bog标准控制台应用程序 - 也使用数据库挂钩,但如何为应用程序全局设置连接字符串?

目前,我正在设定

var dbIndex = new DBContext();
dbIndex.Database.Connection.ConnectionString = 
    "Data Source=USER-PC;Initial Catalog=TextProject.DBContext;" + 
    "Integrated Security=True;MultipleActiveResultSets=True";
Run Code Online (Sandbox Code Playgroud)

但是我必须在所有函数调用中每次都设置这个connectionstring属性.当我没有web.config时,有没有办法设置全局连接字符串?

c# entity-framework

5
推荐指数
2
解决办法
1万
查看次数

在Firefox中居中传奇

问题

问题是以下内容适用于Chrome,Opera和IE (!?),但在Firefox中不起作用:

fieldset>legend {
  display: table;
  float: none;
  margin: 0 auto;
}
Run Code Online (Sandbox Code Playgroud)
<fieldset>
  <legend>Legend</legend>
</fieldset>
Run Code Online (Sandbox Code Playgroud)

导致Chrome

Chrome上的结果

Firefox中的结果

关于Firefox的结果

解决方案黑客

有几个问题,但没有一个令人满意的答案:

/* intended styling */
fieldset>legend {
    display: table;
    float: none;
    margin: 0 auto;
}

fieldset.absolute-fix {
    position: relative;
}
fieldset.absolute-fix>legend {
    position: absolute;
    left: 50%;
}

fieldset.margin-fix>legend {
    margin-left: 50%;
    margin-right: 50%;
    width: auto;
    transform: translate(-50%, 0)
}

fieldset.width-fix>legend {
    width: 100%;
    text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
<fieldset class="absolute-fix">
    <legend>Fix with absolute</legend>
    <p>Not centered and inconsitant styling</p>
    <a href="http://stackoverflow.com/a/4006871/1185053">Source</a>
</fieldset> …
Run Code Online (Sandbox Code Playgroud)

html css firefox

5
推荐指数
1
解决办法
2814
查看次数

Owin的NullReferenceException

我刚刚将一个项目克隆到一台新机器上,并且我在NullReferenceException使用OWIN的MVC网站上进行了难以调试:

[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.Owin.Security.Cookies.<AuthenticateCoreAsync>d__0.MoveNext() +664
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.Owin.Security.Infrastructure.<BaseInitializeAsync>d__2.MoveNext() +860
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
   Microsoft.Owin.Security.Infrastructure.<Invoke>d__0.MoveNext() +427
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +22
   Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow() +33
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +150
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +42
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +415
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Run Code Online (Sandbox Code Playgroud)

它发生在之后

[assembly: OwinStartupAttribute(typeof(Website.Startup))]
namespace Website
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是在我抛出异常之后,这就像我可以辨别为F10ing一样 - 它永远不会到达第一个控制器的构造函数.

有没有人经历过这个和/或能指出我可能导致错误的方向?

c# owin asp.net-mvc-5

5
推荐指数
2
解决办法
2783
查看次数

自我加入LINQ查询并返回View

我正在使用LINQ Self Join Query在视图上显示数据.我的sql表包含一些员工详细信息.我需要用他们的Manager Name显示员工详细信息,因为它是表中的ManagerID

EmpID  Name ManagerID   Designation Phone   Address
1   Mike    3          Developer    123456  Texas
2   David   3           RM          123456  Delhi
3   Roger   NULL        GM          123456  Dallas
4   Marry   2          Developer    123456  NY
5   Joseph  2          Developer    123456  Singapore
7   Ben 2              Developer    123456  Mumbai
8   Steven  3          TL           123456  Banglore
 

我需要改变它的名字

我的代码在控制器动作中

var emp = from m in t.Employees
          join e1 in t.Employees on m.ManagerID equals e1.EmployeeID
          select new { Id = m.EmployeeID , 
                       Name = m.Name, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

4
推荐指数
1
解决办法
2万
查看次数

无限循环计算立方根

我正在尝试通过牛顿方法创建一个计算立方根的函数,但由于某种原因,我似乎在这里有一个无限循环?

#include <iostream>
#include <math.h>

using namespace std;

double CubicRoot(double x, double e);

int main()
{
    cout << CubicRoot(5,0.00001);
}

double CubicRoot(double x, double e)
{
    double y = x;
    double Ynew;
    do 
    {
        Ynew = y-((y*y)-(x/y))/((2*y)+(x/(y*y)));
        cout << Ynew;

    } while (abs(Ynew-y)/y>=e);

    return Ynew;
}
Run Code Online (Sandbox Code Playgroud)

c++ newtons-method

4
推荐指数
1
解决办法
1150
查看次数

将派生属性映射到数据库中的序列化列

我有以下课程:

public class Base
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class Alpha : Base
{
    public string Foo { get; set; }
    public int Bar { get; set; }
}

public class Beta : Base
{
    public string Baz { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我希望能够将其存储在 SQL 数据库中,如下所示:

Id    Name    Type    ExtraInfo
=======================================
1     Asdf    Alpha   {"Foo":"hello","Bar":7}
2     Qwer    Beta    {"Baz":"goodbye"}
Run Code Online (Sandbox Code Playgroud)

并且能够以合理的方式检索它,例如(伪代码):

repo.Bases.First(a => a.Type == "Alpha").Magic<Alpha>().Foo; // returns hello …
Run Code Online (Sandbox Code Playgroud)

c# sql nhibernate orm entity-framework

4
推荐指数
1
解决办法
2685
查看次数

我的简单MSIL出了什么问题?

我正在尝试生成以下类:

public class MyType
{
    public string MyMethod() { return "Hi"; }
}
Run Code Online (Sandbox Code Playgroud)

我的Emit代码如下:

var assemblyBuilder = GetAssemblyBuilder("MyAssembly");
var moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule");
var typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public);
var methodBuilder = typeBuilder.DefineMethod("MyMethod", MethodAttributes.Public, typeof(string), new Type[] { });
var ilBuilder = methodBuilder.GetILGenerator();
ilBuilder.Emit(OpCodes.Nop);
ilBuilder.Emit(OpCodes.Ldstr, "Hi");
ilBuilder.Emit(OpCodes.Stloc_0);
ilBuilder.Emit(OpCodes.Br_S);
ilBuilder.Emit(OpCodes.Ldloc_0);
ilBuilder.Emit(OpCodes.Ret);
var type = typeBuilder.CreateType();
Run Code Online (Sandbox Code Playgroud)

但是当我调用MyMethod一个实例时,MyType我得到一个InvalidProgramException:Common Language Runtime检测到一个无效的程序.

我已经尝试将返回类型更改为void并使用just EmitWriteLineEmit(OpCodes.Ret),运行正常,所以它必须是我在这里写的IL.

我错过了一些明显的东西吗?一个明确的解释将有所帮助,因为我刚刚开始使用Emit.

评论中的其他信息:

"原始"IL取自LINQ-pad中的IL-generation.

c# cil reflection.emit

4
推荐指数
1
解决办法
228
查看次数