How to add Web API to an existing ASP.NET MVC (5) Web Application project?

Assuming you forgot to tick the Web API checkbox (add it to the project) when making a new MVC (5) project, what do you need to do add Web API and get it working? There are a bunch of migration questions, but none seemed to have the complete and up-to-date steps for adding Web API to an MVC 5 project and it seems to have changed from some of the old answers. Add Web API to MVC 4 Adding Glob

如何将Web API添加到现有的ASP.NET MVC(5)Web应用程序项目?

假设您在创建新的MVC(5)项目时忘记勾选Web API复选框(将其添加到项目中),那么您需要添加Web API并使其工作? 有一堆迁移问题,但似乎没有将Web API添加到MVC 5项目的完整和最新步骤,它似乎已经从一些旧的答案中改变了。 将Web API添加到MVC 4 添加GlobalConfiguration.Configure(WebApiConfig.Register)MVC 4 更新MVC项目 使用Nuget获取最新的Web API。 项目 - 右键单击​​ - 管理Nuget包 - 搜索Web API(Mic

Web API Put Request generates an Http 405 Method Not Allowed error

Here's the call to the PUT method on my Web API - the third line in the method (I am calling the Web API from an ASP.NET MVC front end): client.BaseAddress is http://localhost/CallCOPAPI/ . Here's contactUri : Here's contactUri.PathAndQuery : And finally, here's my 405 response: Here's the WebApi.config in my Web API project: public static void Register(Http

Web API Put请求生成一个Http 405方法不允许的错误

以下是对我的Web API的PUT方法的调用 - 方法的第三行(我从ASP.NET MVC前端调用Web API): client.BaseAddress是http://localhost/CallCOPAPI/ 。 这里是contactUri : 这里是contactUri.PathAndQuery : 最后,这是我的405回应: 这是我的Web API项目中的WebApi.config: public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name:

Web API in MVC solution in separate project

I am creating a new MVC4 project, and research has lead me to believe that communicating from javascript to the server side is better achieved now through web API framework rather than controller actions. Is my understanding correct on this? I am presuming that I can share all my attributes etc between web API and MVC controllers so on the face it, it does not seem a massive change for me. W

单独项目中的MVC解决方案中的Web API

我正在创建一个新的MVC4项目,研究让我相信,通过web API框架而不是控制器动作,现在可以更好地实现从javascript到服务器端的通信。 我的理解是否正确? 我假设我可以在Web API和MVC控制器之间共享我的所有属性等等,所以对我来说这似乎不是一个巨大的改变。 当我设置应用程序时,我喜欢将组件分解到项目中。 我的计划是有一个MVC项目和一个Web API项目。 但是我遇到了问题。 例如,我已经结束了2个应用程序,分开的路由

SqlConnection and SqlCommand with using statement

I have a connection to a database set up like this to call a stored procedure. I am just wondering if this is the best way to do this. I have two using statements one for the sqlConnection and one for the sqlCommand (which I am not really sure if its needed) using (SqlConnection con1 = new SqlConnection(conString1)) { using (SqlCommand cmd1 = new SqlCommand()) { cmd1.Connection

使用语句的SqlConnection和SqlCommand

我有一个连接到像这样设置的数据库来调用存储过程。 我只是想知道这是否是最好的方式来做到这一点。 我有两个使用语句一个用于sqlConnection,一个用于sqlCommand(我不确定它是否需要) using (SqlConnection con1 = new SqlConnection(conString1)) { using (SqlCommand cmd1 = new SqlCommand()) { cmd1.Connection = con1; cmd1.CommandType = CommandType.StoredProcedure; cmd1.Comman

C# Why SqlCommand constructor has both SqlConnection and SqlTransaction?

虽然SqlTransaction具有Connection属性,但为什么SqlCommand有一个同时具有SqlConnection和SqlTransaction的构造函数?

C#为什么SqlCommand构造函数同时具有SqlConnection和SqlTransaction?

虽然SqlTransaction具有Connection属性,但为什么SqlCommand有一个同时具有SqlConnection和SqlTransaction的构造函数?

Is it necessary to dispose SqlConnection as well as SqlCommand?

Is it necessary to separately dispose of a SqlConnection as well as a SqlCommand? I'm doing some maintenance work on an application and found the following code: public void CallStoredProc(string storedProcName) { using (SqlCommand command = new SqlCommand(storedProcName, CreateConnection())) { command.CommandType = CommandType.StoredProcedure; command.Connection.Op

是否需要配置SqlConnection以及SqlCommand?

是否有必要分开处理一个SqlConnection以及一个SqlCommand? 我正在做一些应用程序的维护工作,并找到以下代码: public void CallStoredProc(string storedProcName) { using (SqlCommand command = new SqlCommand(storedProcName, CreateConnection())) { command.CommandType = CommandType.StoredProcedure; command.Connection.Open(); // Additional code here. command.Exec

SQLTransaction has completed error

I got following error once in my application. This SQLTransaction has completed; it is no longer usable Stack Trace is attached below – It says about Zombie Check and Rollback . What is the mistake in the code? Note: This error came only once. UPDATE From MSDN - SqlTransaction.Rollback Method A Rollback generates an InvalidOperationException if the connection is terminated or if th

SQLTransaction已完成错误

我在应用程序中遇到过一次错误。 此SQLTransaction已完成; 它不再可用 堆栈跟踪附在下面 - 它说关于Zombie Check和Rollback 。 代码中的错误是什么? 注意:此错误只出现一次。 UPDATE 从MSDN - SqlTransaction.Rollback方法 如果连接终止或者事务已在服务器上回滚,则回滚会生成InvalidOperationException。 从僵尸检查交易 - 错误 我发现在各种应用程序中出现此错误的最常见原因之一是,在我们的应用程序

Is SqlConnection / SqlCommand thread safe?

I am currently creating a WCF web service. As part of its job, it will unfortunately need to do some fairly intensive computations, however these computations can fortunately be shared between calls to the webservice. In effect - we only need to do the computations once, and all later calls can get the benefit. However, since WCF has no shared application state it seems logical to set WCF in

SqlConnection / SqlCommand线程安全吗?

我目前正在创建一个WCF Web服务。 作为其工作的一部分,它不幸需要进行一些相当密集的计算,但是这些计算可能会在对Web服务的调用之间共享。 实际上 - 我们只需要进行一次计算,所有后来的调用都可以获得好处。 但是,由于WCF没有共享应用程序状态,因此将WCF设置为单实例模式似乎是合理的。 (每个客户都需要一些相关的计算,迫使我们重新计算每次可能会出现的问题,或者每个呼叫都是站不住脚的) 但是,我不太熟悉多线

What's the @ in front of a string in C#?

This is a .NET question for C# (or possibly VB.net), but I am trying to figure out what's the difference between the following declarations: string hello = "hello"; vs. string hello_alias = @"hello"; Printing out on the console makes no difference, the length properties are the same. It marks the string as a verbatim string literal - anything in the string that would normally be interpr

C#中字符串前的@是什么?

这是C#(或可能是VB.net)的.NET问题,但我试图弄清楚下列声明有什么区别: string hello = "hello"; 与 string hello_alias = @"hello"; 在控制台上打印没有区别,长度属性相同。 它将字符串标记为逐字字符串文本 - 字符串中通常会被解释为转义序列的任何内容都将被忽略。 因此"C:\Users\Rich"与@"C:UsersRich" 有一个例外:双引号需要转义序列。 为了避免双引号,您需要在连续放置两个双引号

C# Oracle Custom type for TABLE OF NUMBER without custom OBJ

Trying to get Collection of numbers as an output parameter from Oracle function. I was able to call custom object and collection of the objects, but I am not sure how to get oracle table of number in C# as output of oracle stored procedure. C# Error Message: Custom type mapping for ' dataSource='xxxx' schemaName='ODS' typeName='NUMBER_TBL'' is not specified or

C#Oracle Oracle自定义类型,用于没有自定义OBJ的TABLE NUMBER

尝试从Oracle函数获取数字的集合作为输出参数。 我可以调用自定义对象和对象的集合,但我不确定如何获取C#中的Oracle数字表作为oracle存储过程的输出。 C#错误消息:'dataSource ='xxxx'schemaName ='ODS'typeName ='NUMBER_TBL''的自定义类型映射未指定或无效 这里是Oracle中的自定义类型number_tbl。 create or replace TYPE number_tbl IS TABLE OF NUMBER(38,4); Oracle Package Fu