asp.net-identity – 使用SQL Server而不是LocalDB的Web API和ASP.Net标识
|
>如何设置ASP.Net Identity以使用SQL Server数据库而不是LocalDB?
在Web API .Net 4.5中使用Microsoft.AspNet.Identity.Core 1.0.0和EntityFramework 6.0.0 Web.config更改: <connectionStrings>
<add name="myAppDB"
connectionString="data source=.;Initial Catalog=mydb1;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
调用api / account / register时出错 {"Message":"An error has occurred.","ExceptionMessage":"An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.","ExceptionType":"System.Data.Entity.Core.ProviderIncompatibleException","StackTrace":" at System.Web.Http.ApiController.<InvokeActionWithExceptionFilters>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerSeres.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"The provider did not return a ProviderManifestToken string.","StackTrace":" at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices,DbConnection connection)","ExceptionMessage":"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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
)","ExceptionType":"System.Data.SqlClient.SqlException","StackTrace":" .....
和Windows应用程序事件日志 Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS,make sure that profile loading is enabled for the current user. 解决方法如果尚未更改MVC 5 Internet模板使用的基本配置,则ASP.NET标识的连接字符串的名称为“DefaultConnection”.尝试使用此名称创建连接字符串,并将其配置为指向sql server.如果您使用Web API模板,则默认设置为“无身份验证”,如下图所示. 如果选择“无身份验证”,则不会安装适用于ASP.NET身份的程序集,也不会创建帐户控制器,并且不会使用连接字符串更新web.config.请注意,MVC仍包含在模板中. 如果要使用ASP.NET标识,请选择“更改身份验证”并选择“个人帐户” 现在您拥有了所有必需的程序集,ASP.NET Identity在启动配置中连接,默认连接字符串在您的web.config中. <configSections>
<!-- For more information on Entity Framework configuration,visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<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-TestWebApiTemplateWithAuth20140218082219.mdf;Initial Catalog=aspnet-TestWebApiTemplateWithAuth- 20140218082219;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
请注意,您还为Entity Framework配置了并为其配置了正确的程序集.默认情况下,ASP.NET Identity使用EF代码优先于数据存储.默认设置为使用本地数据库.只需更改此连接字符串即可使用SQL Server数据库. 如果要将基础数据存储更改为SQL Server以外的其他数据,则存在a tutorial you can follow here.此特定教程显示如何将其更改为MySql. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – MVC 5使用旧表单身份验证而不是OWIN
- 如何将ASP.NET MVC5身份认证添加到现有数据库
- asp.net-mvc-2 – 如何在ASP.NET MVC2中枚举formcollection
- asp.net-mvc-4 – MVC4 StyleBundle不以正确的顺序呈现捆绑
- 默认按钮在asp.net面板中不起作用
- asp.net – 在Response.Redirect之后获取上一页网址
- asp.net – 我应该在服务层或控制器层发送电子邮件吗?
- Azure Apps EasyAuth声称使用.NET Core
- asp.net-mvc – 什么是好的openid选择器控件?
- 如何在asp.net中检测服务器端的浏览器关闭?
- asp.net-mvc – 缓存CSS和JS文件
- asp.net-mvc – 如何使用Ninject将服务注入授权过
- asp.net-mvc-4 – 如何在Kendo Grid的每一行中添
- asp.net – 访问asp:从代码背后的内容
- asp.net – 使用jQuery以编程方式触发JavaScript
- ASP.NET应用程序通过Windows身份验证或表单身份验
- asp.net-core – Visual Studio 2017 RC安装会中
- asp.net-mvc – ActionLink后退按钮
- asp.net-mvc – EntityFramework代码在部署到Azu
- asp.net-mvc-4 – 在IIS 7.5中注册.NET Framewor
