如何使用localDB将ASP.NET MVC 4应用程序部署到Windows 7上的本地IIS?

时间:2014-03-29 21:51:58

标签: asp.net .net iis windows-7 localdb

当我尝试使用Visual Studio 2013在Windows 7上使用本地IIS运行我的ASP.NET MVC 4应用程序时。当应用程序尝试连接到localDB \ v11.0时,我遇到以下错误

  

' /'中的服务器错误应用

     

发生与网络相关或特定于实例的错误   建立与SQL Server的连接。服务器不是   发现或无法访问。验证实例名称是否正确   并且SQL Server配置为允许远程连接。   (提供者:SQL网络接口,错误:50 - 本地数据库运行时   发生了错误。无法创建自动实例。查看Windows   应用程序事件日志以获取错误详)

     

2个事件日志

     

尝试访问LocalDB实例时发生意外错误   注册表配置。请参阅Windows应用程序事件日志   错误详情。

     

     

无法获取本地应用程序数据路径。最有可能是用户个人资料   没有加载。如果在IIS下执行LocalDB,请确保   为当前用户启用了配置文件加载。

我在网上找到的大多数解决方案都引用了这篇文章:http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-1-user-profile.aspx

我在描述的情况和我的情况之间看到的唯一区别是所描述的错误代码是0而我的错误代码是50.但是,建议的解决方案对我不起作用。

即使我将修改setProfileEnvironment设置为true并且我花了好几个小时来处理不同的processModel参数和应用程序池,我也无法理解这个错误。

5 个答案:

答案 0 :(得分:45)

我也遇到了同样的问题,但有一个解决方案。

转到IIS服务器,然后转到运行应用程序的应用程序池。在应用程序池的高级设置中,有一个“过程模型”选项,在该选项下有一个“标识”选项。默认情况下,这是应用程序池标识。将其更改为本地系统,您就完成了。

并记住将App_Data文件夹放在IIS服务器的WWW文件夹中

答案 1 :(得分:6)

试试这个,这将解决您的问题:

编辑%windir%\ system32 \ inetsrv \ config \中的applicationHost.config文件,特别是ApplicationPools部分。

将IdentityType更改为NetworkService以使用新创建的数据库。

<add name="ASP.NET v4.0" managedRuntimeVersion="v4.0">
   <processModel identityType="NetworkService" loadUserProfile="true" setProfileEnvironment="true" />
</add>

答案 2 :(得分:2)

确保应用程序池使用可以访问所需LocalDB实例的标识。

然后在应用程序的身份验证设置中禁用ASP.NET模拟。否则,应用程序使用IUSR_MachineName帐户访问数据库。

此设置可能不适合生产环境,但可能足以用于数据库和应用程序开发。

答案 3 :(得分:0)

也许这会对某人有所帮助。我有同样的问题安装一个空的Epise3rver 7.5+版本,但很明显它没有任何设置或配置,因为我的同事没有这个问题。我结束了卸载所有与MSSQL相关的应用程序并重新安装了MsSQL Express 2014.它工作正常!我之前尝试过安装2014但它并没有改变任何东西,所以我说再安装2014之前我卸载了MsSQL相关的所有东西。希望它有所帮助。

答案 4 :(得分:0)

使用MVC 5.2.3.0我遇到了类似的问题......将其添加到我的web.config。

//test the ability to validate new passwords with Infrastructure/CustomPasswordValidator.cs 
        [Fact]
        public async void Validate_Password()
        {
            //Arrange
            <Mock><UserManager<AppUser>> userManager = new <Mock><UserManager<AppUser>>(); //caused null exception, use GetMockUserManager() instead
            <Mock><CustomPasswordValidator> customVal = new <Mock><CustomPasswordValidator>(); //caused null result object use customVal = new <CustomPasswordValidator>() instead
            <AppUser> user = new <AppUser>
            user.Name = "user" 
            //set the test password to get flagged by the custom validator
            string testPwd = "Thi$user12345";

            //Act
            //try to validate the user password
            IdentityResult result = await customVal.ValidateAsync(userManager, user, testPwd);

            //Assert
            //demonstrate that there are two errors present
            List<IdentityError> errors = result.Succeeded ? new List<IdentityError>() : result.Errors.ToList();
            Assert.Equal(errors.Count, 2);
        }

//create a mock UserManager class
        private Mock<UserManager<AppUser>> GetMockUserManager()
        {
            var userStoreMock = new Mock<IUserStore<AppUser>>();
            return new Mock<UserManager<AppUser>>(
                userStoreMock.Object, null, null, null, null, null, null, null, null);
        }

Mocking new Microsoft Entity Framework Identity UserManager and RoleManager