我想添加一个Auditor Observer,它可以随时为3个模型(书籍,角色,作者)创建一个动作...
我最近听说过Observer功能,但找不到有关该功能的任何文档.它是否支持Rails 3?
如何创建一个Auditor Observer,为3个模型执行after_create操作?
谢谢
我正在使用IIS 7 Rewrite模块重写传入的URL,如:
至
一切正常,除非在处理重写请求时,我使用MVC的UrlHelper.GenerateUrl()方法:
UrlHelper.GenerateUrl(
"Assets",
"Css",
"Asset",
new RouteValueDictionary(new { site = site.Name, assetPath = assetPath }),
RouteTable.Routes,
controllerContext.RequestContext,
false);
Run Code Online (Sandbox Code Playgroud)
调用此方法会导致HttpException:
System.Web.HttpException: Cannot use a leading .. to exit above the top directory.
at System.Web.Util.UrlPath.ReduceVirtualPath(String path)
at System.Web.Util.UrlPath.Reduce(String path)
at System.Web.VirtualPath.Combine(VirtualPath relativePath)
at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath)
at System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath)
at System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext, String contentPath)
at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues)
Run Code Online (Sandbox Code Playgroud)
查看RequestContext,似乎所有请求路径都是正确的(即,具有重写的值).我似乎无法弄清楚为什么它试图退出顶级目录...我们在路径中没有使用....
我还确保RewriteModule位于IIS中的UrlRouting模块之上.
虽然我可以进入框架方法,但我无法检查任何局部变量(在VS或WinDbg中),因为它已经过编译器优化.
有什么想法吗?
我正在尝试使用加速度计旋转精灵.当我向右倾斜时,我希望他稍微向右旋转,当我向左倾斜时,我希望他稍微向左旋转......
提前谢谢,里德
我正在尝试X509Certificate2从字节数组中的PKCS#12 blob 构造一个并且得到一个相当令人费解的错误.此代码在具有Windows XP管理员权限的桌面应用程序中运行.
堆栈跟踪如下,但由于_LoadCertFromBlob已标记,我因试图进行故障排除而丢失[MethodImpl(MethodImplOptions.InternalCall)].
System.Security.Cryptography.CryptographicException: The system cannot find the file specified.
at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
Run Code Online (Sandbox Code Playgroud)
编辑: blob是由BouncyCastle为C#生成的真正的PKCS#12,包含RSA私钥和证书(自签名或最近注册CA) - 我要做的是转换私钥和证书从BouncyCastle库到System.Security.Cryptography库,从一个导出到另一个导入.此代码适用于已经尝试过的绝大多数系统; 我从未见过该构造函数抛出的特定错误.这个盒子可能是某种环境怪异.
编辑2:错误发生在不同城市的不同环境中,我无法在本地重现它,所以我可能最终不得不将其粉碎到破损的XP安装.
既然你问过,这里是有问题的片段.该代码采用BouncyCastle表示中的私钥和证书,从个人密钥库中删除相同专有名称的任何先前证书,并通过中间PKCS#12 blob将新私钥和证书导入个人密钥库.
// open the personal keystore
var msMyStore = new X509Store(StoreName.My);
msMyStore.Open(OpenFlags.MaxAllowed);
// remove any certs previously issued for the same DN
var …Run Code Online (Sandbox Code Playgroud) 我通过从UserForm工具栏将组合框拖到我的工作表上创建了一个下拉列表.我从书中的一些单元格中为它指定了一些值.现在我想要一些VBA代码以字符串的形式访问所选下拉项的值.
我的下拉列表只包含文字.
另外,我如何找到这个新创建的下拉列表的名称(它在属性中没有任何地方!)?
我有一个服务来获取和设置会话中的用户.如果有登录用户,我想将一些用户信息传递给每个视图,并认为过滤器是最好的方式,所以我不必在每个控制器/动作中复制它.当我运行该应用程序时,它会收到此错误:
Error creating bean with name 'userService': Scope 'session' is not active for the current thread
Run Code Online (Sandbox Code Playgroud)
我的过滤器看起来像这样:
class SecurityFilters {
def userService
def filters = {
setUser(controller:'*', action:'*') {
before = {
if (userService.isLoggedIn()) {
request.user = userService.getUser()
} else {
request.user = null
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我最终可以通过session.user访问用户,但我想能够调用userService.isLoggedIn(),我无法通过视图轻松调用.那么有没有办法将服务注入过滤器,或者我应该创建一个taglib来包装userService.isLoggedIn()?
我想以最小的偏差反复产生快速随机混洗.
众所周知,只要基础随机数发生器(RNG)是无偏的,Fisher-Yates shuffle就是无偏的.
To shuffle an array a of n elements:
for i from n ? 1 downto 1 do
j ? random integer with 0 ? j ? i
exchange a[j] and a[i]
Run Code Online (Sandbox Code Playgroud)
但是如果RNG有偏差(但很快)怎么办?
假设我想生成25个元素数组的许多随机排列.如果我使用具有偏置RNG的Fisher-Yates算法,那么我的置换将是有偏差的,但我相信这假设25元素阵列在每次应用混洗算法之前从相同的状态开始.例如,一个问题是如果RNG只有2 ^ 32~10 ^ 9的周期,我们就不能产生25个元素的每个可能的排列,因为这是25!~10 ^ 25个排列.
我的一般问题是,如果我在开始Fisher-Yates shuffle的每个新应用之前将洗牌后的元素拖垮,这会减少偏差和/或允许算法产生每个排列吗?
我的猜测是它通常会产生更好的结果,但似乎如果重复洗牌的阵列有许多与基础RNG相关的元素,那么排列实际上可能比预期更频繁地重复.
有谁知道任何解决这个问题的研究?
作为一个子问题,如果我只想重复排列数组中25个元素中的5个元素,那么我使用Fisher-Yates算法选择5个元素并在完成一个完整的shuffle之前停止?(我使用交换的数组末尾的5个元素.)然后我重新使用前面部分改组的25个元素数组来选择另一个5的排列.再次,看起来这比从如果基础RNG有偏差,则原始的25个元素数组.有什么想法吗?
我认为测试部分shuffle案例会更容易,因为25个元素中有5个元素只有6,375,600个可能的排列,所以有没有简单的测试来检查偏差?
所以我想让边界消失.我有我想要的确切的webkit-gradient设置.
但不确定如何在border元素上实现它.
可能吗?我怎么做?
只有CSS3请.
顺便说一句,我尝试了下面的CSS,它没有用:
border-color: -webkit-gradient( linear, left bottom, left top, color-stop(0.74, rgb(214,11,11)), color-stop(0.39, rgb(175,13,13)), color-stop(0.07, rgb(157,22,22)));
border-style: solid;
border-width: 10px;
Run Code Online (Sandbox Code Playgroud) try
{
try
{
throw new Exception("From Try");
}
catch
{
throw new Exception("From Catch");
}
finally
{
throw new Exception("From Finally");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)
上面代码的输出是:From Finally.
为什么不From Catch呢?
-要么-
我怎样才能从外部捕获和记录两个例外?
我需要编写一个工具,用C#报告损坏的URL.如果用户在浏览器中看到404错误,则URL应仅报告已损坏.我相信可能有一些技巧来处理进行URL重写的Web服务器.这就是我所拥有的.正如您所看到的,只有一些URL验证不正确.
string url = "";
// TEST CASES
//url = "http://newsroom.lds.org/ldsnewsroom/eng/news-releases-stories/local-churches-teach-how-to-plan-for-disasters"; //Prints "BROKEN", although this is getting re-written to good url below.
//url = "http://beta-newsroom.lds.org/article/local-churches-teach-how-to-plan-for-disasters"; // Prints "GOOD"
//url = "http://"; //Prints "BROKEN"
//url = "google.com"; //Prints "BROKEN" althought this should be good.
//url = "www.google.com"; //Prints "BROKEN" althought this should be good.
//url = "http://www.google.com"; //Prints "GOOD"
try
{
if (url != "")
{
WebRequest Irequest = WebRequest.Create(url);
WebResponse Iresponse = Irequest.GetResponse();
if (Iresponse != null)
{
_txbl.Text = …Run Code Online (Sandbox Code Playgroud) c# ×3
.net ×2
algorithm ×1
asp.net ×1
cryptography ×1
css3 ×1
excel ×1
excel-2003 ×1
excel-vba ×1
grails ×1
html ×1
iphone ×1
permutation ×1
pkcs#12 ×1
random ×1
rotation ×1
shuffle ×1
try-finally ×1
vba ×1