关于利用浏览器缓存有几个问题,但我没有找到任何有助于在ASP.NET应用程序中执行此操作的内容.谷歌的Pagespeed告诉这是性能最大的问题.到目前为止,我在我的web.config中这样做了:
<system.webServer>
<staticContent>
<!--<clientCache cacheControlMode="UseExpires"
httpExpires="Fri, 24 Jan 2014 03:14:07 GMT" /> -->
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.24:00:00" />
</staticContent>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
评论代码有效.我可以将expire header设置为将来某个特定时间,但我无法设置cacheControlMaxAge从现在开始静态内容的缓存天数.这是行不通的.我的问题是:
我怎样才能做到这一点?我知道有可能只为特定的文件夹设置缓存,这是一个很好的解决方案,但它也不起作用.应用程序托管在Windows Server 2012上,在IIS8上,应用程序池设置为经典.
在web配置中设置此代码后,我的页面速度为72(之前为71).没有缓存50个文件.(现在49)我想知道为什么,我只是意识到一个文件实际上是缓存的(svg文件).不幸的是png和jpg文件没有.这是我的web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="exceptionManagement" type="Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManagerSectionHandler,Microsoft.ApplicationBlocks.ExceptionManagement" />
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E34" requirePermission="false" allowDefinition="Everywhere" />
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<exceptionManagement mode="off">
<publisher …Run Code Online (Sandbox Code Playgroud) 我在MVC 4 aspnet网站上使用EF5.在本地,一切正常,但当我将其发布到IIS并尝试进入时,我得到错误
"'System.Data.Entity.Internal.AppConfig'的类型初始化程序引发了异常."
详细例外
为entityFramework创建配置节处理程序时出错:在应用程序配置中多次指定DbContext类型'GdpSoftware.Server.Data.GdpSoftwareDbContext,GdpSoftware.Server.Data'的配置.每个上下文只能配置一次.(E:\ App\web.config第104行)
我在StackOverflow中检查了之前的问题,我已经通过Nuget EntityFramework卸载并重新安装,并检查每个项目中对它的每个引用都是EF5.我还检查了每个项目中选定的框架是4.5.
任何想法,可能导致问题的原因是什么?谢谢!吉列尔莫.
web.config中
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<connectionStrings>
<add name="GdpSoftwareConnectionString" connectionString="Persist Security Info=False;User ID=user;Password=password;Initial Catalog=databasename;Data Source=server" providerName="System.Data.SqlClient" />
<add name="GdpSoftware.Server.Data.GdpSoftwareDbContext" connectionString="GdpSoftware.Server.Data.GdpSoftwareDbContext_ConnectionString" providerName="System.Data.SqlClient"/>
<add name="GdpSoftware.Server.Ui.Web.Models.UsersContext" connectionString="GdpSoftware.Server.Ui.Web.Models.UsersContext_ConnectionString" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" /> …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc entity-framework asp.net-mvc-4 entity-framework-5
我们需要使用LINQ从数据库中获取数据.我们现在需要实施分页.
我想一次我们需要一次获取10记录,当我们点击Next按钮然后它将10从db 获取下一条记录.
请指导我代码.谢谢
如果我尝试删除"子"行,我总是会遇到异常.这是一个片段:
using (var context = new CompanyContext())
{
ItemType itemType = context.ItemTypes.FirstOrDefault(i => i.Name == "ServerType");
ItemTypeItem itemTypeItem = itemType.Items.FirstOrDefault(i => i.Name == "DatabaseServer");
itemType.Items.Remove(itemTypeItem);
context.SaveChanges(); <=== exception!
}
Run Code Online (Sandbox Code Playgroud)
该SaveChanges()方法抛出以下异常.
"由于一个或多个外键属性不可为空,因此无法更改关系.当对关系进行更改时,相关的外键属性将设置为空值.如果外键是如果不支持空值,则必须定义新关系,必须为foreign-key属性分配另一个非空值,或者必须删除不相关的对象."
实体配置
public class ItemTypeConfiguration : NamedEntityConfiguration<ItemType>
{
public ConfigurationColumn ParentIDColumn;
public ConfigurationColumn ValidationPatternColumn;
public ItemTypeConfiguration() : base()
{
ParentIDColumn = new ConfigurationColumn() { Name = "ParentID", Ordinal = base.LastOrdinalPosition + 1 };
ValidationPatternColumn = new ConfigurationColumn() { Name = "ValidationPattern", Length = 1024, Ordinal=base.LastOrdinalPosition + 2};
this.Property(t …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个包含Facebook和Twitter信息的单一数据类.
但在我从Twitter id_str获得的JSON回复中,我需要从FaceBook获得id.
我需要将这两个放入id-string中.
现在我知道[JsonProperty("id_str")]如果我想将Twitters反序列id_str化为我的id-string,我可以使用它.
但是,如果我需要在我的数据类中使用相同的字符串反序列化Facebook id和Twitters id_str,该id怎么办?
我正在尝试使用MSAA(在Win7上)获取chrome浏览器中的地址栏并将其替换为不同的URL.当chrome正常启动时(作为登录用户),我可以通过遍历进程拥有的窗口类的UI树,使用IAccessible接口找到地址栏.但是,如果我以不同的用户身份启动chrome(通过在Windows中使用RunAs),我会在浏览"RunAs"流程所拥有的类时看到名称为"chrome legacy window"的窗口.窗口层次结构和内容与我在扫描以登录用户身份运行的进程时看到的内容大不相同.
虽然我可以在两个浏览器实例中看到(窗口类名称)Chrome_WidgetWin_0和Chrome_WidgetWin_1,但只有作为当前用户运行的那个才能访问地址栏.知道chrome作为不同用户推出时发生了什么?有没有解决方法或者我应该考虑不同的技术?
通过StackOverflow中的旅行,有许多ToList()用于ICollection(或派生自的类ICollection<T>)的扩展方法.
我已经退出了好的'反编译器,看看ToList()扩展方法是如何执行的,并且随时枚举集合.通过源头我遇到了:
[__DynamicallyInvokable]
public static List<TSource> ToList<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
throw Error.ArgumentNull("source");
}
return new List<TSource>(source);
}
Run Code Online (Sandbox Code Playgroud)
现在这非常简单,因此ToList()扩展方法只是List<T>使用源对象创建一个新的.深入挖掘List构造函数会显示此行.
ICollection<T> ts = collection as ICollection<T>;
//.. ommited code
ts.CopyTo(this._items, 0);
Run Code Online (Sandbox Code Playgroud)
就像你想的那样,你会深入研究这种CopyTo方法.这是我被卡住的地方.在完成所有挖掘方法调用之后,我们进入最后的extern方法调用
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
[SecurityCritical]
internal static extern void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable);
Run Code Online (Sandbox Code Playgroud)
我的问题是(虽然我似乎无法找到它)ToList()扩展方法(ICollection<T>.CopyTo())在执行时是否遍历Collection(Array)的所有对象?
子问题:我在哪里可以找到上述来源extern void Copy()? …
在MVC 6 RC1中,我们使用IAssemlbyProvider接口来注册在运行时发现的程序集并注入其他控制器类型,与此帖子类似.现在使用RC2版本IAssemblyProvider已被删除并已更改为(请参阅参考资料).
我们的框架版本目前net46.
自升级以来,我们在外部程序集(未引用)中的控制器返回404状态.
我们尝试通过手动将控制器添加到注册的控制器ApplicationPartManager.
var mvcBuilder = services.AddMvc();
var controllerFeature = new ControllerFeature();
mvcBuilder.PartManager.PopulateFeature(controllerFeature);
var moduleControllers = ModulesManager.GetControllers();
foreach (var c in moduleControllers)
controllerFeature.Controllers.Add(c);
mvcBuilder.PartManager.PopulateFeature(controllerFeature);
Run Code Online (Sandbox Code Playgroud)
和...
services.AddMvc().ConfigureApplicationPartManager(app =>
{
var controllerFeature = new ControllerFeature();
app.PopulateFeature(controllerFeature);
var moduleControllers = ModulesManager.GetControllers();
foreach (var c in moduleControllers)
controllerFeature.Controllers.Add(c);
app.PopulateFeature(controllerFeature);
});
Run Code Online (Sandbox Code Playgroud)
现在,程序集肯定被加载到AppDomain我们的依赖注入系统中,为外部程序集中的其他项查找和填充服务.
通过我们之前的实现,这很好地使用了IAssemblyProvider.
public class ModuleAwareAssemblyProvider : IAssemblyProvider
{
private readonly DefaultAssemblyProvider _defaultProvider;
public …Run Code Online (Sandbox Code Playgroud) 我在我的程序(用Java编写)中有一个变量:
String myPassword
Run Code Online (Sandbox Code Playgroud)
在使用Android Studio编译代码后,我得到了一个Android应用程序,我想让其他人使用它.
但我很害怕:用户是否有可能从应用程序中获取变量值(密码)?
假设密码值为"myPass".它的二进制是:
01101101 01111001 01010000 01100001 01110011 01110011
应用程序二进制文件中是否包含此序列?
我需要使用Microsoft Visual C++ 2010和MSBuild为几个不同的平台构建我的软件.我将平台添加到$(VCTargetsPath)目录并创建.props和.targets文件.然后,我将文件复制到配置管理存储库,为复制的文件定义了父目录的路径:$(CM_REPO_PATH),并希望重定向visual studio以使用存储库中的文件.
当我在我的机器上创建一个名为%MSBuildExtensionsPath%的环境变量并将其指向$(CM_REPO_PATH)\ MSBuild时,我能够让项目工作.但我想要的是在visual studio项目中设置$(VCTargetsPath)和/或$(MSBuildExtensionsPath),而不是在每个开发人员的机器上设置环境变量.
当我添加属性组来执行此操作时...
<PropertyGroup>
<VCTargetsPath>$(CM_REPO_PATH)\MSBuild\Microsoft.Cpp\v4.0</VCTargetsPath>
<MSBuildExtensionsPath>$(CM_REPO_PATH)\MSBuild</MSBuildExtensionsPath>
<MSBuildExtensionsPath32>$(CM_REPO_PATH)\MSBuild</MSBuildExtensionsPath32>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
...新平台不可用(好像项目仍在使用默认的$(VCTargetsPath),而不是指定的那个).有没有办法从项目文件中覆盖$(VCTargetsPath)?
c# ×5
asp.net ×2
asp.net-mvc ×1
caching ×1
compilation ×1
httphandler ×1
icollection ×1
iis ×1
java ×1
json ×1
linq-to-sql ×1
msbuild ×1
visual-c++ ×1