我们有一个ASP.NET Core 2.0网站,它还提供了一些用于UI增强目的的简单Web API方法.
在IIS Express下本地运行时,Web API调用按预期工作,但是当我们部署到IIS 8.5生产Web服务器时,在发出HTTP 和请求时会出现以下错误...DELETEPUT
405 Method Not Allowed
Run Code Online (Sandbox Code Playgroud)
经过一些网络搜索后,我们发现了几篇建议删除IIS WebDAV模块的帖子.我们在IIS中禁用了它(它是我们的服务器),我们也尝试了以下方法:
Allow verb filtering = FalseaspNetCore,WebDAV和ExtensionlessUrlHandler-Integrated-4.0上述步骤都没有解决我们的问题.
任何建议/方向将不胜感激.
我有什么看起来(对我来说)是一个奇怪的问题......
我为SelectListItem创建了一个简单的编辑器模板(〜/ Views/Shared/EditorTemplates文件夹中的SelectListItem.cshtml),例如:
<ul class="select-list-item cell-15 col-3 omega clearfix">
@Html.EditorFor(c => c.Categories)
</ul>
Run Code Online (Sandbox Code Playgroud)
其中c.Categories是IEnumerable
这工作正常,但我想要另一个模板来呈现具有略微不同标记的集合,因此我将编辑器模板复制并重命名为,例如,"CategoryIcons.cshtm"并调用如下:
<ul class="select-list-item cell-15 col-3 omega clearfix">
@Html.EditorFor(c => c.Categories, "CategoryIcons")
</ul>
Run Code Online (Sandbox Code Playgroud)
简而言之,唯一的区别是我正在指定一个命名的编辑器模板.
当我打开页面时,我现在收到以下错误:
传递到字典中的模型项的类型为'System.Collections.Generic.List`1 [System.Web.Mvc.SelectListItem]',但此字典需要类型为'System.Web.Mvc.SelectListItem'的模型项
两个模板ID中的模板模型声明:
@model System.Web.Mvc.SelectListItem
Run Code Online (Sandbox Code Playgroud)
我不明白为什么默认模板工作而命名模板不工作.任何帮助,将不胜感激.
谢谢.
我有一个表,包含,例如,我想在数据库中使两个字段唯一.例如:
create table Subscriber (
ID int not null,
DataSetId int not null,
Email nvarchar(100) not null,
...
)
Run Code Online (Sandbox Code Playgroud)
ID列是主键,DataSetId和Email都被编入索引.
我希望能够做的是阻止表中出现相同的Email和DataSetId组合,换句话说,对于给定的DataSetId,Email值必须是唯一的.
我尝试在列上创建一个唯一索引
CREATE UNIQUE NONCLUSTERED INDEX IX_Subscriber_Email
ON Subscriber (DataSetId, Email)
Run Code Online (Sandbox Code Playgroud)
但我发现这对搜索时间产生了相当大的影响(例如,当搜索电子邮件地址时 - 表中有150万行).
有没有更有效的方法来实现这种类型的约束?
应该调用异步库方法await吗?例如,假设我有一个数据服务库方法,可以访问名为"repository" 的Entity Framework 6数据上下文.据我所知,我有两种方法来定义这个方法:
public static async Task<IEnumerable<Blogs>>
GetAllBlogsAsync(EfDataContext db)
{
return await db.Blogs
.OrderByDescending(b => b.Date)
.SelectAsync();
}
Run Code Online (Sandbox Code Playgroud)
或没有async/ await装饰
public static Task<IEnumerable<Blogs>>
GetAllBlogsAsync(EfDataContext db)
{
return db.Blogs
.OrderByDescending(b => b.Date)
.SelectAsync();
}
Run Code Online (Sandbox Code Playgroud)
在应用程序端点,在这种情况下是MVC控制器操作,对于任一方法,调用都是相同的:
public async Task<ActionResult> Blogs()
{
var blogs = await BlogService.GetAllBlogs(_blogRepository);
return View(blogs);
}
Run Code Online (Sandbox Code Playgroud)
当然,在应用程序调用异步方法链的情况下,这种情况可能会更复杂.链中的每个方法应该调用await,还是应该只await在调用链的末尾有一个语句,这会产生什么区别?
我正在使用MVC 3我想动态创建一个CSV文件供下载,但我不确定正确的MVC导向方法.
在传统的ASP.net中,我会写一些类似的东西:
Response.ClearHeaders();
Response.ContentType = "text/csv";
Response.AddHeader("content-disposition", attachment;filename='Test.csv'");
Response.Write("1,2,3");
Response.End();
Run Code Online (Sandbox Code Playgroud)
我已经查看了ContentResult操作,但似乎我需要将结果创建为字符串,即
return Content(myData,"text/csv");
我想,我可以构建一个字符串,但由于这些文件可能长达数千行,这对我来说似乎效率低下.
有人能指出我正确的方向吗?谢谢.
我需要克隆Linq to SQL实体.概述:
Customer origCustomer = db.Customers.SingleOrDefault(c => c.CustomerId == 5);
Customer newCustomer = CloneUtils.Clone(origCustomer);
newCustomer.CustomerId = 0; // Clear key
db.Customers.InsertOnSubmit(newCustomer);
db.SubmitChanges(); // throws an error
Run Code Online (Sandbox Code Playgroud)
其中CloneUtils.Clone()是一种简单的泛型方法,它使用反射将数据从原始实体复制到新实体.
我遇到的问题是,当我尝试将新实体添加回数据库时,我收到以下错误:
已尝试附加或添加非新的实体,可能已从另一个DataContext加载.这不受支持.
我似乎无法找到一种从数据上下文中分离克隆实体的简单/通用方法.或者我可以调整克隆方法以"跳过"与上下文相关的字段?
谁能指出我正确的方向?
谢谢.
为了完整起见,这是我最终遵循Marcus的建议的方法:
public static T ShallowClone<T>(T srcObject) where T : class, new()
{
// Get the object type
Type objectType = typeof(T);
// Get the public properties of the object
PropertyInfo[] propInfo = srcObject.GetType()
.GetProperties(
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.Public
);
// Create a new object
T newObject = new …Run Code Online (Sandbox Code Playgroud) 我有一个Web应用程序需要利用应用程序缓存来存储数据(由于在请求的基础上获取该数据的高开销).请参阅上一篇文章:/sf/answers/1187337371/
这种方法似乎运行良好,但我在网站的错误中看到以下偶然的错误:
System.ApplicationException: Object synchronization method was called from an
unsynchronized block of code.
at System.Threading.Mutex.ReleaseMutex()
at InboxInsight.Web.Web_Controls.Twitter.TwitterFeed.GetTwitterData(HttpContext context)
at InboxInsight.Web.Web_Controls.Twitter.TwitterFeed.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Run Code Online (Sandbox Code Playgroud)
作为参考,这是代码块:
public string GetData(HttpContext context)
{
var cache = context.Cache;
Mutex mutex = null;
string data = (string)cache[CacheKey];
// Start check to see if available on cache
if (data == null)
{
try
{
// Lock base on resource key
// (note that not all chars are valid for name) …Run Code Online (Sandbox Code Playgroud) 我正在使用OpenId Connect身份验证服务器,特别是.NET Core 1.1上的Identity Server 4(版本1.5.2).我运行ASP.NET Framework MVC 5和ASP.NET Core 1.1 MVC Web应用程序.以下配置来自.NET Core 1.1 Web应用程序:
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
app.UseDeveloperExceptionPage();
app.UseStatusCodePages();
app.UseRewriter(new RewriteOptions().AddRedirectToHttps());
app.UseStaticFiles();
#region Configure Authentication
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
AuthenticationScheme = "Cookies",
AutomaticAuthenticate = true,
AccessDeniedPath = "/AccessDenied"
});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectOptions
{
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
Authority = "https://localhost:44316",
ClientId = "test-mule",
ClientSecret = "secret",
ResponseType = "code id_token",
SaveTokens = true,
GetClaimsFromUserInfoEndpoint …Run Code Online (Sandbox Code Playgroud) 我已将旧的HttpHandler(.ashx)TwitterFeed代码移植到WebAPI应用程序.代码的核心使用了出色的Linq2Twitter软件包(https://linqtotwitter.codeplex.com/).部分端口涉及将此组件从版本2升级到版本3,现在提供了许多异步方法调用 - 这对我来说是新的.这是基本的控制器:
public async Task<IEnumerable<Status>>
GetTweets(int count, bool includeRetweets, bool excludeReplies)
{
var auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerKeySecret"],
AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"],
AccessTokenSecret = ConfigurationManager.AppSettings["twitterAccessTokenSecret"]
}
};
var ctx = new TwitterContext(auth);
var tweets =
await
(from tweet in ctx.Status
where (
(tweet.Type == StatusType.Home)
&& (tweet.ExcludeReplies == excludeReplies)
&& (tweet.IncludeMyRetweet == includeRetweets)
&& (tweet.Count == count)
)
select tweet)
.ToListAsync();
return tweets;
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,但之前,我已经缓存了结果,以避免"过度调用"Twitter API.在这里,我遇到了一个问题(更多的是与我对异步协议的理解不比我怀疑的其他问题).
概括地说,我想要做的是首先检查缓存,如果数据不存在,则重新水化缓存并将数据返回给调用者(网页).这是我对代码的尝试 …
我刚刚更新了在ASP.NET Framework 4.5.2版上运行的MVC Web应用程序.我正在使用Twilio发送短信:
var twilio = new TwilioRestClient(twilioSid, twilioAuthToken);
var result = twilio.SendSmsMessage(twilioNumber, message.Destination, message.Body);
Run Code Online (Sandbox Code Playgroud)
更新后,我收到以下错误:
System.TypeLoadException:无法从程序集'RestSharp,Version = 105.2.1.0,Culture = neutral,PublicKeyToken = null'加载类型'RestSharp.HttpBasicAuthenticator'.
安装的版本是:
我在2014年11月(8个月前)发布了一个类似的问题,并且在Twilio Nuget页面上也讨论过一个讨论Alpha版本的讨论,据报道该版本消除了对RestSharp的依赖.
谁能告诉我项目的状态是什么以及应该使用哪些版本选项?
谢谢.
c# ×3
asp.net ×2
mutex ×2
actionresult ×1
asp.net-core ×1
asp.net-mvc ×1
async-await ×1
asynchronous ×1
caching ×1
clone ×1
detach ×1
duplicates ×1
iis ×1
indexing ×1
linq-to-sql ×1
razor ×1
restsharp ×1
sql-server ×1
twilio ×1