将asp.net核心webapi应用程序从VS Code部署到IIS Web服务器错误

时间:2019-02-13 21:44:30

标签: iis asp.net-web-api asp.net-core

我是asp.net核心的新手,我是Visual Studio 2017的新手,以及发布Web应用程序的工作方式。

我使用VS Code在asp.net核心中重写了一个简单的登录终结点,该终结点以前是在Visual Studio 2017中使用MVC编写的,并尝试在我用Google搜索的文章后发布。在IIS中浏览应用程序时出现错误。当我查看已发布的文件时,它们看起来也很不完整。我是VS Code创建Webapi核心应用程序的新手,所以也许我错了。我将附上已发布文件的屏幕截图。

我得到的错误是: HTTP错误502.3-错误的网关 尝试路由请求时出现连接错误。 “

我已经安装了.NET Core SDK,并且需要在IIS计算机上进行安装,并且还为无托管代码设置了APP池。

Web配置

    <?xml version="1.0" encoding="utf-8"?>
 <configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\LB_CONNECT_API_2.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
    </system.webServer>
  </location>
</configuration>

已发布文件的屏幕快照

Published webapi files from VSCODE

我尝试编辑web.config并从AspNetCore删除V2

  [Route("api/[controller]")]
   [ApiController]
   public class LoginController : ControllerBase
     {
      // POST: api/Login
       public User Post(User user)
      {

          SqlDataReader reader = null;
          SqlConnection myConnection = new SqlConnection
          {

               ConnectionString = @"Server=ServerName;Database=DB;User ID=User;Password=password;"
           };

            SqlCommand sqlCmd = new SqlCommand
            {
                CommandType = CommandType.StoredProcedure,
                CommandText = "lb_Login",
                Connection = myConnection
            };
            sqlCmd.Parameters.AddWithValue("@Email", user.Email);
            sqlCmd.Parameters.AddWithValue("@Password", user.Password);
            myConnection.Open();
            reader = sqlCmd.ExecuteReader();
            User _user = null;


            while (reader.Read())
            {
                _user = new User
               {
                   UserID = Guid.Parse(reader["UserID"].ToString()),
                   FirstName = reader["FirstName"].ToString(),
                   LastName = reader["LastName"].ToString(),
                   GroupName = reader["GroupName"].ToString(),
                   Email = reader["Email"].ToString(),
                   Cell = reader["Cell"].ToString()

                };
            }
            return _user;



        }

我需要它以JSON返回用户对象

0 个答案:

没有答案