如何使用 VS2013 在 Godaddy 中使用 SQL 服务器数据库(启用会员资格)部署 ASP.NET 网站
How to deploy ASP.NET website with SQL Server database (membership enabled) in Godaddy using VS2013
我知道这个问题已经回答了,但是 none 解决了我的问题,我可能遇到了某些未知问题。所以我再次问这个问题。请帮忙…。提前致谢。
我正在使用 Visual Studio 2013 更新 3。我开发了一个 ASP.NET 启用了成员资格的 Web 应用程序,它使用 VS2013 提供的 LocalDb
。我已将网站发布到 GODADDY 网络服务器,但无法部署数据库。没有数据库,我的应用程序工作正常。我已经在 GODADDY 服务器中创建了 SQL 服务器数据库。我正在使用 VS2013 中可用的 Build -> Publish
选项。
我的 web.config
文件是
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebTest-20150416011010.mdf;Initial Catalog=aspnet-WebTest-20150416011010;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5"/>
<customErrors mode="Off"/>
<trust level="Full"/>
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
<add namespace="Microsoft.AspNet.Identity"/>
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<membership>
<providers>
<clear/>
</providers>
</membership>
<profile>
<providers>
<clear/>
</providers>
</profile>
<roleManager>
<providers>
<clear/>
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection"/>
</providers>
</sessionState>
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed"/>
<asp scriptErrorSentToBrowser="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
我的 web.Release.config
文件为
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=xxx.xxx.xxx.xxx; Initial Catalog=mydatabase; User ID=username; Password=password"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
最新版本的成员资格最简单的部署方式是 Code First migrations。
即如果 Sql 连接凭据具有对您的 Godaddy 数据库的 DBO 访问权限,当您通过您的网站访问它时,一旦需要会员功能,就会创建这些表。
如果连接没有 DBO 访问权限,另一种方法是 Script the DDL to a .SQL file) 来自本地数据库的 AspNet*
成员表,然后 运行 相同的脚本在您的 Godaddy 数据库上使用具有 DBO 访问权限的登录名使用 SSMS。您只需要以下表格:
- AspNetRoles
- AspNetUserClaims
- AspNetUserLogins
- AspNetUserRoles
- AspNetUsers
终于在这里做到了
上传前请执行以下操作:
Goto Models 打开 IdentityModels.cs 并将 DefaultConnection 更改为 LocalSqlServer
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("LocalSqlServer", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
上传后在你的web.config中改变这个
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source= (LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebTest-20150416011010.mdf;Initial Catalog=aspnet-WebTest-20150416011010;Integrated Security=True"
providerName="System.Data.SqlClient"/>
到
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=111.111.111.111; Initial Catalog=myDB; User ID=username; Password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
和
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
到
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="LocalSqlServer" />
</providers>
现在转到您的 godaddy 帐户并打开网站与域 ---> ASP.NET 设置并在其中添加 LocalSqlServer 连接字符串(如果未添加)。
连接字符串必须与 web.config 文件
中的相同
对于数据库部分,您需要通过您在godaddy中的数据库帐户在服务器上手动执行脚本
我知道这个问题已经回答了,但是 none 解决了我的问题,我可能遇到了某些未知问题。所以我再次问这个问题。请帮忙…。提前致谢。
我正在使用 Visual Studio 2013 更新 3。我开发了一个 ASP.NET 启用了成员资格的 Web 应用程序,它使用 VS2013 提供的 LocalDb
。我已将网站发布到 GODADDY 网络服务器,但无法部署数据库。没有数据库,我的应用程序工作正常。我已经在 GODADDY 服务器中创建了 SQL 服务器数据库。我正在使用 VS2013 中可用的 Build -> Publish
选项。
我的 web.config
文件是
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebTest-20150416011010.mdf;Initial Catalog=aspnet-WebTest-20150416011010;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5"/>
<customErrors mode="Off"/>
<trust level="Full"/>
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
<add namespace="Microsoft.AspNet.Identity"/>
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<membership>
<providers>
<clear/>
</providers>
</membership>
<profile>
<providers>
<clear/>
</providers>
</profile>
<roleManager>
<providers>
<clear/>
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection"/>
</providers>
</sessionState>
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed"/>
<asp scriptErrorSentToBrowser="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
我的 web.Release.config
文件为
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=xxx.xxx.xxx.xxx; Initial Catalog=mydatabase; User ID=username; Password=password"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
最新版本的成员资格最简单的部署方式是 Code First migrations。
即如果 Sql 连接凭据具有对您的 Godaddy 数据库的 DBO 访问权限,当您通过您的网站访问它时,一旦需要会员功能,就会创建这些表。
如果连接没有 DBO 访问权限,另一种方法是 Script the DDL to a .SQL file) 来自本地数据库的 AspNet*
成员表,然后 运行 相同的脚本在您的 Godaddy 数据库上使用具有 DBO 访问权限的登录名使用 SSMS。您只需要以下表格:
- AspNetRoles
- AspNetUserClaims
- AspNetUserLogins
- AspNetUserRoles
- AspNetUsers
终于在这里做到了 上传前请执行以下操作:
Goto Models 打开 IdentityModels.cs 并将 DefaultConnection 更改为 LocalSqlServer
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("LocalSqlServer", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
上传后在你的web.config中改变这个
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source= (LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebTest-20150416011010.mdf;Initial Catalog=aspnet-WebTest-20150416011010;Integrated Security=True"
providerName="System.Data.SqlClient"/>
到
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=111.111.111.111; Initial Catalog=myDB; User ID=username; Password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
和
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
到
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="LocalSqlServer" />
</providers>
现在转到您的 godaddy 帐户并打开网站与域 ---> ASP.NET 设置并在其中添加 LocalSqlServer 连接字符串(如果未添加)。 连接字符串必须与 web.config 文件
中的相同对于数据库部分,您需要通过您在godaddy中的数据库帐户在服务器上手动执行脚本