我正在尝试将我的web api 2项目移动到ASP.NET 5.但是我有许多不再存在的元素.
例如IHttpActionResult或Ok(), NotFound()方法.或者RoutePrefix[]
我应该改变每一个IHttpActionResult用IActionResult?改变Ok()用new ObjectResult?(它是一样的吗?)
那怎么样HttpConfiguration似乎在startup.cs中不存在?
如何让我的vnext API返回XML和JSON?
我认为使用带有application/xml的content-type可以像以前一样工作.请注意,我尝试使用Accept:application/xml.
但似乎没有.
编辑:
这是我的project.json文件:
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
"Microsoft.AspNet.Mvc": "6.0.0-beta4",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-beta4"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
Run Code Online (Sandbox Code Playgroud)
这是我的startup.cs:
public class Startup
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.ConfigureMvc(options =>
{ …Run Code Online (Sandbox Code Playgroud) 假设我有一个应用程序,例如一个网站,我的objectcontext在请求期间离开.我应该缓存一些使用EF加载的数据,以避免读取数据库并提高性能.
好吧,我用EF读取数据,我将对象放在缓存中(说AppFabric,而不是内存缓存),但是可以延迟加载的相关数据现在为空(对此属性的访问会导致nullreferenceexception).我不想在一个请求中加载所有内容,因为它会太长,所以我希望按需加载,一旦读取,我想用新获取的数据完成缓存.
注意 :
我怎样才能做到这一点 ?
编辑:我用northwind数据库构建了这个样本,它正在工作:
class Program
{
static void Main(string[] args)
{
// normal use
List<Products> allProductCached = null;
using (NORTHWNDEntities1 db = new NORTHWNDEntities1())
{
allProductCached = db.Products.ToList().Clone<DbSet<Products>>();
foreach (var product in db.Products.Where(e => e.UnitPrice > 100))
{
Console.WriteLine(product.ProductName + " => " + product.Suppliers.CompanyName);
}
}
// try to use cache, but missing Suppliers
using (NORTHWNDEntities1 db = new NORTHWNDEntities1())
{
foreach (var product in allProductCached.Where(e => e.UnitPrice > 100)) …Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Studio Express for web来学习本教程http://msdn.microsoft.com/en-US/data/jj193542.教程告诉我们
按照惯例,DbContext为您创建了一个数据库.
如果本地SQL Express实例可用(默认情况下使用Visual Studio 2010安装),则Code First已在该实例上创建数据库如果SQL Express不可用,则Code First将尝试使用LocalDb(默认情况下安装在Visual Studio 2012中) )数据库以派生上下文的完全限定名称命名,在我们的例子中是CodeFirstNewDatabaseSample.BloggingContext
所以,它应该使用localdb.但是当我尝试访问我的模型时,我可以在调试中看到连接字符串指向.\ SQLEXPRESS,虽然我没有sqlexpress.所以,我有一个超时异常......
为什么不使用localdb?
请注意,如果我明确地将连接字符串设置为localdb,它正在工作......请注意,如果我使用Vs Express for Desktop,它也在工作......
Vs Express for web出了什么问题?
尝试将xunit测试添加到我的ASP.NET 5项目中,我添加了一个类库并填充project.json,如下所示:
{
"version": "1.0.0-*",
"description": "",
"authors": [ "" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"xunit": "2.1.0-beta2-build2981",
"xunit.runner.visualstudio": "2.1.0-beta2-build1055"
},
"commands": {
"test": "xunit.runner.visualstudio"
},
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Collections": "4.0.10-beta-22816",
"System.Linq": "4.0.0-beta-22816",
"System.Threading": "4.0.10-beta-22816",
"Microsoft.CSharp": "4.0.0-beta-22816"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但Visual Studio无法识别测试资源管理器中的任何单元测试:
public class Class1
{
[Fact]
public void PassingTest()
{
Assert.Equal(4, Add(2, 2));
}
[Fact]
public void FailingTest()
{
Assert.Equal(5, Add(2, 2));
}
int Add(int x, int …Run Code Online (Sandbox Code Playgroud) 可能重复:
主键ID会发生什么?什么时候超过极限?
如果SQL服务器表具有一个达到int的最大容量的标识列(表示为int),那么会附加什么?
回到开头?
假设行数增加100,每次我插入100个新行,我删除100个旧行.
谢谢你的回答.祝你好运
在我的WP7应用程序中,我正在做:
string userName = IsolatedStorageSettings.ApplicationSettings.Contains("UserName") ? IsolatedStorageSettings.ApplicationSettings["UserName"].ToString() : null;
if (string.IsNullOrEmpty(userName))
IsolatedStorageSettings.ApplicationSettings["UserName"] = "test";
Run Code Online (Sandbox Code Playgroud)
我启动我的应用程序(F5),当然,userName为空,因此它存储在独立存储中.
我停止我的应用程序(停止调试),我不关闭模拟器
再次启动我的应用程序(F5),但仍然是空的.
我已经读过,在仿真器未关闭时,隔离存储应该保持不变.
我究竟做错了什么 ?
提前感谢您的回答.
我有一个图像,让我们说一个.png,由用户上传.此图像具有固定大小,例如100x100.
我想用这个图像创建4个精灵.
一个从(0,0)到(50,50)
另一个从(50,0)到(100,50)
第三个从(0,50)到(50,100)
从(50,50)到(100,100)的最后一个
我如何用我喜欢的C#做到这一点?
在此先感谢您的帮助
我正在寻找能够匹配以下路线的路线定义:
/segment/xxxx/def/segment/.../xxxx/def/segment/that/can/span/xxxx/def并能够xxxx使用参数 `def 运行操作。
但这种路线是不允许的:
[Route("/{*segment}/xxx/{myparam}")]
Run Code Online (Sandbox Code Playgroud)
如何做呢?
asp.net-mvc routes url-routing asp.net-mvc-routing .net-core
asp.net-core ×3
c# ×2
silverlight ×2
.net-core ×1
asp.net-mvc ×1
caching ×1
content-type ×1
gif ×1
localdb ×1
owin ×1
routes ×1
sprite ×1
sql-server ×1
url-routing ×1
xml ×1
xna-4.0 ×1
xunit.net ×1