我看到在一种情况下我们可以覆盖OnActionExecuting或OnActionExecuted继承ActionFilterAttribute类的方法,如下所示:
public class MyFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{ // bla bla }
}
Run Code Online (Sandbox Code Playgroud)
在其他情况下,我们也可以实现IActionFilter并FilterAttribute喜欢这样:
public class MySecondFilterAttribute : FilterAttribute, IActionFilter
{
public void OnActionExecuted(ActionExecutingContext filterContext) {}
}
Run Code Online (Sandbox Code Playgroud)
那么,这两种方法之间是否有任何差异,可能是任何特殊情况下,最好使用其中一种方法而不是另一种方法?
提前致谢.
我需要调试一些JavaScript'我使用Chrome开发工具.我是JavaScript的新手(几天前刚开始学习),"我可以通过资源窗格设置断点".但在家里由于某种原因我不能这样做:点击后没有出现断点.
我有Chrome版本:26.0.1410.64米.
可能是这样的?
我已经读过可以在visual studio(2010)中运行xsd命令.我的机器上有VS 2012,当我跑的时候
xsd XMLFile.xml
Run Code Online (Sandbox Code Playgroud)
我明白了
命令"xsd"无效.
那么,VS 2012中的"xsd"命令是不是被禁用了,还有其他方法可以在VS 2012中执行"xsd"吗?
我使用VS 2012,因为安装项目已从中删除,我必须使用InstallUtil.exe.
我的Windows服务应用程序中没有projectInstaller类.我在命令提示符下运行:
installutil FilesMonitoringService.exe
Run Code Online (Sandbox Code Playgroud)
我明白了:
C:\ Program Files\Microsoft Visual Studio 8\VC#> installutil"C:\ Program Files\Mic rosoft Visual Studio 8\VC#\ CSharpProjects\MyService\MyService\bin\Release\MyServ ice.exe"Microsoft(R) .NET Framework安装实用程序版本2.0.50727.42版权所有(c)Microsoft Corporation.版权所有.
运行事务安装.
开始安装的安装阶段.请参阅日志文件的内容以获取C:\ Program Files\Microsoft Visual Studi 8\VC#\ CSharpProjects\MyService\MyService\bin\Release\MyService.exe程序集的进度.该文件位于C:\ Program Files\Microsoft Visual Studio 8\VC#\ CSharpProj ects\MyService\MyService\bin\Release\MyService.InstallLog.安装程序集'C:\ Program Files\Microsoft Visual Studio 8\VC#\ CSharpProjec ts\MyService\MyService\bin\Release\MyService.exe'.受影响的参数是:logtoconsole = assemblypath = C:\ Program Files\Microsoft Visual Studio 8\VC#\ CSharpProjects\MyService\MyService\bin\Release\MyService.exe logfile = C:\ Program Files\Microsoft Visual Studio 8\VC#\CSharpProjects\MySer vice\MyService\bin\Release\MyService.InstallLog没有具有RunInstallerAttribute.Yes属性的公共安装程序可以在C:\ Program Files\Microsoft Visual Studio 8\VC#\ CSharpProjects\MyService\MyService\bin中找到\ Release\MyService.exe程序集.
安装阶段成功完成,提交阶段正在开始.请参阅日志文件的内容以获取C:\ Program Files\Microsoft Visual Studi 8\VC#\ CSharpProjects\MyService\MyService\bin\Release\MyService.exe程序集的进度.该文件位于C:\ Program …
我已经阅读了很多关于缓存的帖子,但它们中没有一个确实符合我的需求.在我的mvc 3应用程序中,我有一个动作方法GetImage(),它返回一个图像类型的文件.然后我在视图中使用此方法来显示图像:
<img width="75" height="75" src="@Url.Action("GetImage", "Store", new {productId = item.ProductId})"/>
Run Code Online (Sandbox Code Playgroud)
我想在服务器上缓存图像.所以,我已经尝试过:
1)使用OutputCacheAttribute:
[HttpGet, OutputCache(Duration = 10, VaryByParam = "productId", Location = OutputCacheLocation.Server, NoStore = true)]
public FileContentResult GetImage(int productId)
{
var p = _productRepository.GetProduct(productId);
if (p != null)
{
if (System.IO.File.Exists(GetFullProductImagePath(productId)))
{
var image = Image.FromFile(GetFullProductImagePath(productId));
return File(GetFileContents(image), "image/jpeg");
}
}
var defaultPath = AppDomain.CurrentDomain.BaseDirectory +
ConfigurationManager.AppSettings["default-images-directory"];
var defaultImage = Image.FromFile(Path.Combine(defaultPath, "DefaultProductImage.jpg"));
return File(GetFileContents(defaultImage), "image/jpeg");
}
Run Code Online (Sandbox Code Playgroud)
图像没有缓存(我得到状态:200 OK)
2)在GetImage()方法中使用以下Response.Cache方法:
public FileContentResult GetImage(int productId)
{
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(0, 0, 0, …Run Code Online (Sandbox Code Playgroud) 存在"具有路径压缩的加权快速联盟"算法.
代码:
public class WeightedQU
{
private int[] id;
private int[] iz;
public WeightedQU(int N)
{
id = new int[N];
iz = new int[N];
for(int i = 0; i < id.length; i++)
{
iz[i] = i;
id[i] = i;
}
}
public int root(int i)
{
while(i != id[i])
{
id[i] = id[id[i]]; // this line represents "path compression"
i = id[i];
}
return i;
}
public boolean connected(int p, int q)
{
return root(p) == root(q);
}
public void …Run Code Online (Sandbox Code Playgroud) 我有一点误解:当我们实现IDependencyResolver时,它意味着我们可以为项目中的每个部分使用DI.所以,即使我不从DefaultControllerFactory继承,我可以构建控制器重新依赖依赖项?
编辑:我建议看看通过这些所有Brad Wilson的帖子
也是这个职位是非常有用的
asp.net-mvc dependency-injection inversion-of-control asp.net-mvc-3
我在理解.NET中的值类型表示时遇到问题.每个值类型都派生自System.ValueType类,这是否意味着Value Type是一个类?
例如,如果我写:
int x = 5;
Run Code Online (Sandbox Code Playgroud)
这意味着我创建了一个System.Int32类的实例'将它写入变量x ??
我有一个由两个相同部分组成的视图,只有内容不同.所以,基本上我想以某种方式为左右两个部分使用一个控制器和一个视图.
我做什么(在HTML中):
<div class="board_body">
<div class="left_board" ng-controller="leftBoardController">
<div ng-controller="panelController" ng-include="template"></div>
</div>
<div class="right_board" ng-controller="rightBoardController">
<div ng-controller="panelController" ng-include="template"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我将所有初始化逻辑保留在左右控制器中,并使用panelController及其左右部分的视图.在这种情况下,可以共享panelController,因为它使用具有不同值的公共$ scope变量(在左侧和右侧控制器中创建变量,因此它们对panelCotrl可见).
angular.module("radar.leftController", [])
.controller("leftController", function ($scope, ...) {
$scope.data = getSomeData();
}
angular.module("radar.rightController", [])
.controller("rightController", function ($scope, ...) {
$scope.data = getOtherData();
}
angular.module("radar.panelController", [])
.controller("panelController", function ($scope, ...) {
$scope.template = "somePath/panelView.html";
// shared logic for left and right contrls goes here
}
Run Code Online (Sandbox Code Playgroud)
在panelView.html中:
<div>data: {{data.length}}</div>
Run Code Online (Sandbox Code Playgroud)
似乎从右边我可以改变左右变速器,但是从左边我只能改变左变速器(如预期的那样).(我需要左右两部分完全分开).
那么,重用一个控制器(创建多个实例)的正确方法是什么?
我的 apiController 中有以下方法:
public IEnumerable<something> GetData(DataProvider dataProvider)
{
return dataProvider.GetData();
}
Run Code Online (Sandbox Code Playgroud)
我需要的是从 javascript 调用此方法并将其传递给 DataProvider 派生类型的参数。我可以通过传递字符串来处理这个问题,例如“FirstProvider”,然后在 GetData() 方法中写入 N 个 if 来创建正确类型的实例。
但是有什么方法可以在 web.config 文件中编写类似的内容:
<DataProviders>
<type = FirstDataProvider, alias = "FirstProvider">
<type = SecondDataProvider, alias = "SecondProvider">
</DataProviders>
Run Code Online (Sandbox Code Playgroud)
将 getData 方法更改为:
public IEnumerable<something> GetData(string dataProviderAlias)
{
// get provider type by it's alias from web congfig,
// then instantiated and call:
return dataProvider.GetData();
}
Run Code Online (Sandbox Code Playgroud)
然后通过它的别名查找并实例化类型?
注意:我接受了下面的答案,因为它为我指明了正确的方向,但 msdn 表示IConfigurationSectionHandler已弃用。
所以我使用ConfigurationSection, ConfigurationElementCollection, ConfigurationElementclasses 来构建自定义配置部分。
asp.net ×3
asp.net-mvc ×3
c# ×3
.net ×1
algorithm ×1
angularjs ×1
attributes ×1
breakpoints ×1
caching ×1
debugging ×1
filter ×1
java ×1
javascript ×1
outputcache ×1
union-find ×1
web-config ×1
xsd ×1
xsd.exe ×1