小编Pan*_*cus的帖子

如何使C#.NET CF程序的AssemblyInfo版本传播到Explorer Properties窗口?

看起来如果您编译Visual Studio解决方案并在AssemblyInfo.cs文件中有一个版本#,那应该传播到Windows资源管理器属性对话框.这样,有人可以直接右键单击*.exe并单击"属性"以查看版本#.Visual Studio中是否有特殊设置才能实现此目的?

示例图片http://content.screencast.com/users/Pincas/folders/Jing/media/40442efd-6d74-4d8a-8e77-c1e725e6c150/2008-09-24_0849.png

编辑:我应该提到,这是特别适用于.NET Compact Framework 2.0,它不支持AssemblyFileVersion.所有希望都失去了吗?

.net c# versioning compact-framework

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

我可以通过编程方式加载<asp:RoleGroup>的"角色"属性吗?

我正在维护一个ASP.NET应用程序,现在整个站点的各个地方都定义了安全性.在代码隐藏中有一些逻辑,比如if User.IsInRole(...),在ASPX页面中还有其他逻辑:

<asp:LoginView ID="lvDoSomeStuff" runat="server">
    <RoleGroups>
        <asp:RoleGroup Roles="Accounting,HR,Blah">
        ...
    </RoleGroups>
</asp:LoginView>
Run Code Online (Sandbox Code Playgroud)

当新功能请求进入并创建新角色时,我不得不浏览整个应用程序并确保我没有错过任何区域.我想在将来避免这种情况.

如何Roles<asp:RoleGroup>编程方式设置元素的属性?我尝试过这样的事情:

<asp:LoginView ID="lvDoSomeStuff" runat="server">
    <RoleGroups>
        <asp:RoleGroup Roles="<%= UserManager.GetRolesThatCanDoX() %>">
        ...
    </RoleGroups>
</asp:LoginView>
Run Code Online (Sandbox Code Playgroud)

where GetRolesThatCanDoX()返回以逗号分隔的角色名称列表,但我的方法似乎永远不会被调用.

是否有可能在ASP.NET WebForms中执行类似的操作?请帮我解耦我的代码!;-)

解决方案: Phantomtypist的答案非常有效.我的实施如下:

ASPX:

<asp:LoginView ID="lvDoSomeStuff" runat="server">
    <RoleGroups>
        <asp:RoleGroup>
        ...
        </asp:RoleGroup>
    </RoleGroups>
</asp:LoginView>
Run Code Online (Sandbox Code Playgroud)

代码隐藏:

protected void Page_Load(object sender, EventArgs e)
{
    // Load rolegroups from UserManager
    lvDoSomeStuff.RoleGroups[0].Roles = UserManager.GetRolesThatCanDoStuff().ToArray();
    lvDoSomeOtherStuff.RoleGroups[0].Roles = UserManager.GetRolesThatCanDoOtherStuff().ToArray();
}
Run Code Online (Sandbox Code Playgroud)

asp.net security webforms roles

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

如何配置Microsoft Enterprise Library日志记录应用程序块以处理任何日志记录类别?

我正在尝试将Enterprise .NET通用基础结构库(Common.Logging)与Enterprise Library 4.1的Logging Application Block一起使用。根据docs,这是受支持的。

我遇到的问题是,当我尝试记录某些内容时(例如在本示例中,我在ASP.NET MVC应用程序中):

public ActionResult Index()
{
    ViewBag.Message = "Welcome to ASP.NET MVC!";

    ILog log = LogManager.GetCurrentClassLogger();
    log.Info("Hello world!");

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

我没有收到日志消息,而是在事件日志中遇到错误:

消息:类别“ TestApp.Controllers.HomeController”没有明确的映射。

好吧,Common.Logging中似乎没有任何选项可以设置默认类别,而且即使没有定义类别,我也无法弄清楚如何配置LoggingConfiguration接受任何类别。

这是我的LoggingConfiguration的一个片段:

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
...
  <categorySources>
    <add switchValue="All" name="General">
      <listeners>
        <add name="Formatted EventLog TraceListener" />
        <add name="Email TraceListener" />
      </listeners>
    </add>
  </categorySources>
  <specialSources>
    <allEvents switchValue="All" name="All Events" />
    <notProcessed switchValue="All" name="Unprocessed Category" />
    <errors switchValue="All" name="Logging Errors &amp; Warnings">
      <listeners> …
Run Code Online (Sandbox Code Playgroud)

.net logging enterprise-library app-config web-config

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

在C#.NET中,是否有理由没有StringDictionary的复制构造函数?

如果这是一个愚蠢的问题,我道歉,但请听我说:

Dictionary<string, string> genericDict = new Dictionary<string, string>;
genericDict.Add("blah", "bloop");
// Use the copy constructor to create a copy of this dictionary
return new Dictionary<string, string>(genericDict);
Run Code Online (Sandbox Code Playgroud)

在上面的代码示例中,我可以创建一个通用字典的副本.

现在假设我使用的是System.Collections.Specialized.StringDictionary,因为我不喜欢到处键入"字符串"类型.StringDictionary没有复制构造函数!实际上,它只有默认构造函数.

当然,我可以遍历StringDictionary并手动添加每个键/值对,但我不想:-P

为什么没有复制构造函数?我在这里错过了什么吗?

.net c# collections dictionary stringdictionary

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

当用户使用CAS SSO注销时,ASP.NET MVC会触发HttpRequestValidationException

我们使用Jasig .NET CAS Client与我们组织的CAS SSO服务器连接.

但是,我们注意到在ASP.NET MVC 3中(我认为这会影响ASP.NET WebForms)应用程序,当用户注销时,我们在错误日志中看到以下错误:

System.Web.HttpRequestValidationException (0x80004005):
A potentially dangerous Request.Form value was detected from the client
(logoutRequest="<samlp:LogoutRequest...").
  at System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)
  at System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, RequestValidationSource requestCollection)
  at System.Web.HttpRequest.get_Form()
  at System.Web.HttpRequest.FillInParamsCollection()
  at System.Web.HttpRequest.GetParams()
  at DotNetCasClient.Utils.RequestEvaluator.GetRequestIsCasSingleSignOut() in C:\Projects\Jasig\CAS\dotnet-client\trunk\DotNetCasClient\Utils\RequestEvaluator.cs:line 292
  at DotNetCasClient.CasAuthenticationModule.OnBeginRequest(Object sender, EventArgs e) in C:\Projects\Jasig\CAS\dotnet-client\trunk\DotNetCasClient\CasAuthenticationModule.cs:line 93
  at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Run Code Online (Sandbox Code Playgroud)

我不相信这是用户收到的错误消息 - 它似乎只能被服务器看到.就用户而言,注销成功.

有没有办法让ASP.NET MVC停止尝试验证这些类型的请求?我知道我可以完全禁用请求验证,但这是不可能的.带有连字符的网站对此有一个很好的问题,但不是一个真正可以接受的答案:

将以下设置添加到web.config:

<httpRuntime requestValidationMode="2.0" />

设置此值后,U可以通过设置validateRequest ="false"来禁用请求验证

那么,有没有办法为这个请求禁用ASP.NET验证而不完全关闭它?

编辑:调试也很棘手,因为此请求来自CAS服务器,而不是来自用户的浏览器.我认为这是CAS服务器试图通知用户已注销的所有正在运行的应用程序(单点注销 …

asp.net asp.net-mvc iis-7 cas request-validation

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