小编Jop*_*per的帖子

ASP.NET授权属性和管理员用户角色

使用Authorize属性i可以指定允许访问资源的角色.

[Authorize(Roles="User")]
Run Code Online (Sandbox Code Playgroud)

但是,如果我有管理员用户,允许转到任何资源,我也需要指定这个

[Authorize(Roles="User, Administrator")]
Run Code Online (Sandbox Code Playgroud)

但可能有某种方式我可以说某种方式,管理员允许去任何地方,而不是在授权属性中指定这一个?

所以我的意思是,如果代码中的某个地方(在控制器上或在操作上)将是这样,[Authorize(Roles="User")]这意味着允许管理员角色也去那里.

或者我可以动态地将它设置为所有授权角色应用程序何时启动?

有任何想法吗?

更新:

目前我有一个带有Authorize属性的管理控制器,[Authorize(Role="Administrator")]我在一些其他具有属性的控制器中有一些操作,[Authorize(Role="User")]所以"Administrator"如果我找不到更好的解决方案,我还需要添加它.

authorization asp.net-mvc-3

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

.NET中的常量与String.Format

我有两个常数:

public const string DateFormatNormal = "MMM dd";
public const string TimeFormatNormal = "yyyy H:mm";
Run Code Online (Sandbox Code Playgroud)

在我决定在这两个方面有另一个基础之后:

public const string DateTimeFormatNormal = String.Format("{0} {1}", DateFormatNormal, TimeFormatNormal);
Run Code Online (Sandbox Code Playgroud)

但我得到编译错误 The expression being assigned to 'Constants.DateTimeFormatNormal' must be constant

我尝试后做那样的事情:

public const string DateTimeFormatNormal = DateFormatNormal + " " + TimeFormatNormal;
Run Code Online (Sandbox Code Playgroud)

它正在使用,+ " " +但我仍然喜欢使用类似于String.Format("{0} {1}", ....)任何想法的东西,我怎么能使它工作?

c# .net-4.0

9
推荐指数
1
解决办法
8341
查看次数

中心在td内对齐jquery ui-icon

我有这样的情况,使用gQGrid:

<td role="gridcell" style="text-align:center;" title="" aria-describedby="BaseBetsGrid1_approved">
<span class="ui-icon ui-icon-closethick"/>
</td>
Run Code Online (Sandbox Code Playgroud)

我怎么可以慢慢来?

我试图把它包装到div并wraptocenter从这里上课:http://www.brunildo.org/test/img_center.html

<style type="text/css">
.wraptocenter {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}
.wraptocenter * {
    vertical-align: middle;
}
/*\*//*/
.wraptocenter {
    display: block;
}
.wraptocenter span {
    display: inline-block;
    height: 100%;
    width: 1px;
}
/**/
</style>
<!--[if lt IE 8]><style>
.wraptocenter span {
    display: inline-block;
    height: 100%;
}
</style><![endif]-->

    <td role="gridcell" style="text-align:center;" title="" aria-describedby="BaseBetsGrid1_approved">
    <div class="wraptocenter">
    <span class="ui-icon ui-icon-closethick"/>
    </div>
</td>
Run Code Online (Sandbox Code Playgroud)

但它没有帮助.

我怎么能用最小的CSS样式做到这一点?

可能 …

jquery jquery-ui jqgrid

8
推荐指数
2
解决办法
6415
查看次数

C#比较两个集合的更有效方式

我有两个系列

List<Car> currentCars = GetCurrentCars();
List<Car> newCars = GetNewCars();
Run Code Online (Sandbox Code Playgroud)

我不想使用foreach循环或其他东西,因为我认为应该有更好的方法来做到这一点.

我正在寻找更有效的方法来比较这个集合并获得结果:

  1. 在newCars中而不在currentCars中的汽车列表
  2. 不在newCars和currentCars中的汽车列表

Type Car有int属性Id.

有一个答案,已经删除了说我的意思是说有效:更少的代码,更少的机制,更可读的案例

所以这样思考我的情况是什么?

什么是更少的代码,更少的机制,更可读的案例?

.net c# c#-4.0

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

CSS一个href样式

我有一个href class="button"

我想尝试这样的风格:

.button a:link {text-decoration: none} 
.button a:visited {text-decoration: none} 
.button a:active {text-decoration: none} 
.button a:hover {text-decoration: none; background-color:yellow;color:blue}
Run Code Online (Sandbox Code Playgroud)

为什么它不起作用?如何使用该类设置一个href的stye(class="button")

css

6
推荐指数
2
解决办法
10万
查看次数

自定义jQGrid后期操作

我有一个很好的内联编辑示例jQGrid http://ok-soft-gmbh.com/jqGrid/TestSamle/Admin.htm 有两个自定义操作编辑和删除.

我想添加一个自定义内联Action,让我们称之为ToggleOnline.在此操作上,我想将网格的所有单元格发布到控制器.基本上它将是一种编辑操作,但它会为某些列设置一些默认值.

内联按钮添加如下:

{ name: 'act', index: 'act', width: 55, align: 'center', sortable: false, formatter: 'actions',
                        formatoptions: {
                            keys: true, // we want use [Enter] key to save the row and [Esc] to cancel editing.
                            delOptions: myDelOptions
                        }
                    }
Run Code Online (Sandbox Code Playgroud)

比添加自定义附加按钮我正在使用事件 loadComplete:

loadComplete: function(){ 
            debugger;
            var ids = jQuery("#Grid1").getDataIDs(); 
                for(var i=0;i<ids.length;i++){ 
                    var cl = ids[i];
                    custom = "<input style='height:22px;width:20px;' type='button' value='E' onclick=jQuery('#Grid1').editRow(" + cl + "); />";
                    jQuery("#Grid1").setRowData(ids[i], { act: custom }) 
                } 
            } 
Run Code Online (Sandbox Code Playgroud)

但自定义按钮根本没有出现.而且我还需要以某种方式发布行数据,我还需要指定自定义操作名称(操作)来处理服务器上的此操作.

jqgrid

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

如何从razor视图将参数传递给引用的javascript文件

如果我javascript在剃须刀中有这样的话:

@{
    Grid grid = @Model.GetGridFromModel();

    Bool isSomething = @Model.GetSomething();

    Bool isSomethingMore  = @Model.GetSomehtingMore();

    Bool isSomethingElse = @Model.GetSomethingElse()

    int caseCount = 0;
 }  



$(document).ready(function () {    
    $("#tabs").tabs({
        show: function (event, ui) {        
            switch (ui.index) {
            @if (isSomething){
            <text>
                case @caseCount:                    

                    change('@grid.Avalue');

                    break;
            </text>
                caseCount++;
                }

            @if(isSomethingElse){
            <text>   
                case @caseCount:

                    change('@grid.Bvalue');
                    break;
            </text>
                caseCount++;
                }

            @if (isSomethingElseMore){
            <text> 
                case @caseCount:
                    change('@grid.Cvalue');
                    break;
                </text>                 
                }
            }
        }
    });

    funciton change(id)
    {
    //doing somehting;
    }
Run Code Online (Sandbox Code Playgroud)

所以我想把这个javascript放在单独的文件中并将该文件引用到我的视图中,问题是当我在单独的文件中javascript时,如何将值从razor传递给javascript?

javascript asp.net-mvc-3

6
推荐指数
1
解决办法
6485
查看次数

实体框架检测到冲突的更改.尝试使用相同的密钥插入多个实体时可能会发生这种情况

我有User几个one-to-onemany-to-many关系的实体Identity primary key,并且generic repository在每个请求上创建.

我有一个带有客户端和服务器验证的注册表单,我决定关闭客户端验证以测试服务器在这种情况下的行为方式.

我关闭了客户端验证来测试注册表单并输入一些无效的值,所以我回到表单说我有一些错误,在我修复后我得到了非常有趣的错误说:

_context.SaveChanges(); //towing the error below:

Conflicting changes detected. This may happen when trying to insert multiple entities with the same key
Run Code Online (Sandbox Code Playgroud)

这对我来说很奇怪,因为我分离了实体User,但当我发现这个如何清理实体框架对象上下文? 所以相反只分离User实体我决定尝试清理完全运行该代码的对象上下文:

var objectStateEntries = this.objectContext
                             .ObjectStateManager
                             .GetObjectStateEntries(EntityState.Added);

    foreach (var objectStateEntry in objectStateEntries)
    {
        if(objectStateEntry.Entity != null)
           this.objectContext.Detach(objectStateEntry.Entity);
    }
Run Code Online (Sandbox Code Playgroud)

所以在那之后一切运作良好,我不再得到Conflicting changes detected错误,但我仍然想知道为什么会出现这种情况,可能有人可能会解释一下?

entity-framework-4 asp.net-mvc-3

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

ASp.NET MVC 3.0调用泛型扩展html辅助方法时出错

我有一个像这样的扩展方法:

namespace System.Web.Mvc.Html
{
    public static class HtmlExtensions
    {
        public static T GetEnumValue<T>(this HtmlHelper helper, int value) where T : struct, IConvertible
        {
            return EnumHelper<T>.GetEnumValue(value);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我在Razor View上调用这个方法(该方法的自动完成工作,它在视图中可见),但是我收到错误:

@Html.GetEnumValue<MyEnumHere>(1) //Getting error here
Run Code Online (Sandbox Code Playgroud)

错误: Cannot convert method group 'GetEnumValue' to non-delegate type 'object'. Did you intend to invoke the method?

如果我这样 - 在编译期间没有错误:

Html.GetEnumValue<MyEnumHere>(1) //but in that case didnt get data to display.
Run Code Online (Sandbox Code Playgroud)

如果说谎的话,在编译期间也不会出错

 @{
     Html.GetEnumValue<MyEnum>(1); //But then I am getting error during execution  
 }
Run Code Online (Sandbox Code Playgroud)

错误: No …

html-helper asp.net-mvc-3

3
推荐指数
1
解决办法
2110
查看次数

一个href指向无处添加#到url

a href指出了什么#

<a href="#" id="bla" >Bla<a>
Run Code Online (Sandbox Code Playgroud)

我有onclick功能,点击一个href显示弹出窗口.

function doingClick()
{
   //display popup
   return false;
}
Run Code Online (Sandbox Code Playgroud)

但是#每次点击符号后都会在浏览器中添加到网址中.

因此,例如,如果在点击我的链接之前url是那样的话 http://mywebsite.com

但点击a href看起来像这样的网址:http://mywebsite.com#

有没有办法避免这种行为?

html javascript

3
推荐指数
1
解决办法
6443
查看次数