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

218 Views Asked by At

I posted a question a few days ago about a Win32 Exception error about the parameter was incorrect when deploying to godaddy, that link is here Well after some more digging around, I thought I had figured out the issue because what I was trying to do was not only deploy the web app (which I have successfully done) but also deploy the asp.net membership database that gets created when creating a project and using the Webforms template in VS2013. So I found some tutorials on this here and here So after following and trying both, I am still getting the same error that I mentioned in my original question. I took a look at the webconfig and noticed this 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" />

This was created when I created the project. I commented that out because I generated scripts from SSMS with schema and data, and ran it against the shared database and then added this connectionstring

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

this is the connectionstring that I use to connect to the database through SSMS and was provided when I opened the database in the Server Explorer of Visual Studio and got it from right clicking the database and clicking properties then copied it over from properties area. So next I went back to SSMS and queried the table to make sure that there was data in the AspNetUsers table and there was. So after a number of failed attempts at registering on the site and getting the same Win32 Exception error, I decided to go into the App_Data folder and published the database and thought maybe that was the issue and no, didn't work again.

So I thought that maybe that I may have done something wrong and wrote a test app to see if I could connect to the database and just wrote this

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();

I set a break point at da.fill(ds); and it threw the exact same error as it did from my original project and that error is

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)

So I am pretty lost now on what to do or try, and am still waiting on a response from GoDaddy. Has anyone had any issues on deploying a web application that uses asp.net membership database? or does anyone notice where I may have went wrong?

EDIT

Here is the entire IdentityModel with the DbContext

    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
1

There are 1 best solutions below

0
On BEST ANSWER

Remove the port from your connection string