部署使用 Asp.NET 成员数据库的 Web 应用程序在登录和注册时抛出错误

Deploying web application that uses Asp.NET Membership database throws error on Login and Register

我前几天发布了一个问题,关于部署到godaddy时参数不正确的Win32异常错误,即link是here 好吧,经过更多的挖掘,我认为我已经找到了问题,因为我试图做的不仅是部署网络应用程序(我已经成功完成),而且还部署了创建的 asp.net 成员数据库在 VS2013 中创建项目和使用 Webforms 模板时。 所以我找到了一些关于这个的教程 here and here 因此,在遵循并尝试两者之后,我仍然遇到与我在原始问题中提到的相同的错误。我看了一下 webconfig 并注意到这个 connectionstring

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-GSDataCollection-20150421103634.mdf;Initial Catalog=aspnet-GSDataCollection-20150421103634;Integrated Security=True" providerName="System.Data.SqlClient" />

这是我在创建项目时创建的。我注释掉了这一点,因为我从 SSMS 生成了带有架构和数据的脚本,并且 运行 它针对共享数据库,然后添加了这个连接字符串

<add name="DefaultConnection" connectionString="Data Source=*****:1433;Initial Catalog=*****;Persist Security Info=True;User ID=*****;Password=*****" providerName="System.Data.SqlClient" />

这是我用来通过 SSMS 连接到数据库的连接字符串,当我在 Visual Studio 的服务器资源管理器中打开数据库并通过右键单击数据库并单击属性获得它时提供,然后复制它来自属性区域。 所以接下来我回到 SSMS 并查询 table 以确保 AspNetUsers table 中有数据并且确实存在。因此,在多次尝试在网站上注册并收到相同的 Win32 异常错误后,我决定进入 App_Data 文件夹并发布数据库,并认为这可能是问题所在,但不,没有用再次.

所以我想也许我可能做错了什么并写了一个测试应用程序看看我是否可以连接到数据库并写了这个

string cnStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection cn = new SqlConnection(cnStr);

string cmStr = "SELECT * FROM AspNetUsers";
SqlCommand cm = new SqlCommand(cmStr, cn);
cm.CommandType = CommandType.Text;

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cm);

cn.Open();
da.Fill(ds);
cn.Close();

我在da.fill(ds)设置了一个断点;它抛出了与我原来的项目完全相同的错误,那个错误是

Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)

所以我现在完全不知道该做什么或尝试什么,并且仍在等待 GoDaddy 的回复。有人在部署使用 asp.net 成员数据库的 Web 应用程序时遇到过任何问题吗?或者有人注意到我可能哪里出错了吗?

编辑

这是带有 DbContext 的整个 IdentityModel

    using System;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using GSDataCollection.Models;

namespace GSDataCollection.Models
{
// You can add User data for the user by adding more properties to your User class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
    public ClaimsIdentity GenerateUserIdentity(ApplicationUserManager manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = manager.CreateIdentity(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }

    public Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager)
    {
        return Task.FromResult(GenerateUserIdentity(manager));
    }
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
}
}

#region Helpers
namespace GSDataCollection
{
public static class IdentityHelper
{
    // Used for XSRF when linking external logins
    public const string XsrfKey = "XsrfId";

    public static void SignIn(ApplicationUserManager manager, ApplicationUser user, bool isPersistent)
    {
        IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
        authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
        var identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
        authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
    }

    public const string ProviderNameKey = "providerName";
    public static string GetProviderNameFromRequest(HttpRequest request)
    {
        return request.QueryString[ProviderNameKey];
    }

    public const string CodeKey = "code";
    public static string GetCodeFromRequest(HttpRequest request)
    {
        return request.QueryString[CodeKey];
    }

    public const string UserIdKey = "userId";
    public static string GetUserIdFromRequest(HttpRequest request)
    {
        return HttpUtility.UrlDecode(request.QueryString[UserIdKey]);
    }

    public static string GetResetPasswordRedirectUrl(string code, HttpRequest request)
    {
        var absoluteUri = "/Account/ResetPassword?" + CodeKey + "=" + HttpUtility.UrlEncode(code);
        return new Uri(request.Url, absoluteUri).AbsoluteUri.ToString();
    }

    public static string GetUserConfirmationRedirectUrl(string code, string userId, HttpRequest request)
    {
        var absoluteUri = "/Account/Confirm?" + CodeKey + "=" + HttpUtility.UrlEncode(code) + "&" + UserIdKey + "=" + HttpUtility.UrlEncode(userId);
        return new Uri(request.Url, absoluteUri).AbsoluteUri.ToString();
    }

    private static bool IsLocalUrl(string url)
    {
        return !string.IsNullOrEmpty(url) && ((url[0] == '/' && (url.Length == 1 || (url[1] != '/' && url[1] != '\'))) || (url.Length > 1 && url[0] == '~' && url[1] == '/'));
    }

    public static void RedirectToReturnUrl(string returnUrl, HttpResponse response)
    {
        if (!String.IsNullOrEmpty(returnUrl) && IsLocalUrl(returnUrl))
        {
            response.Redirect(returnUrl);
        }
        else
        {
            response.Redirect("~/");
        }
    }
}
}
#endregion

从连接字符串中删除端口