ASP.NET: Web Deployment Task Failed - microsoft.web.publishing.targets - asp.net

I am in the process of moving away from FTP and into webDeploy. I first built a sample web application with just a webpage, and that deployed fine. I then added a connectionString and a page that accesses data, and that deployed fine.
Then I added forms authentication with a custom data store and that did not deploy fine. I then used FTP to move all of my files, and they successfully transferred and the website functions as it should. So webDeploy must not like something that was added to the web.config when I added forms authentication, but I don't know what that something is.
This is an ASP.NET Web Form application on .NET 4.5.
What was added to the web.config, after webDeploy started giving me the error
<membership defaultProvider="MyMembershipProvider">
<providers>
<add name="MyMembershipProvider" type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MyCs"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
passwordAttemptWindow="10"
applicationName="/"/>
</providers>
</membership>
<profile defaultProvider="MyProfileProvider">
<providers>
<add name="MyProfileProvider" type="System.Web.Providers.DefaultProfileProvider" connectionStringName="MyCs" applicationName="/"/>
</providers>
</profile>
<roleManager defaultProvider="MyRoleProvider">
<providers>
<add name="MyRoleProvider" type="System.Web.Providers.DefaultRoleProvider" connectionStringName="MyCs" applicationName="/"/>
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="MySessionProvider">
<providers>
<add name="MySessionProvider" type="System.Web.Providers.DefaultSessionStateProvider" connectionStringName="MyCs"/>
</providers>
</sessionState>
The last part of the build output:
Generate source manifest file for Web Deploy package/publish ...
Start Web Deploy Publish the Application/package to https://myServer/msdeploy.axd?site=mySite.com ...
Starting Web deployment task from source: manifest(C:\Users\ME\Documents\Visual Studio 2012\Samples
\MyApp\MyApp\obj\Debug\Package\MyApp.SourceManifest.xml) to Destination: auto().
Adding ACL's for path (mySite)
C:\Program Files\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets(4196,5):
Error : Web deployment task failed. ((9/26/2013 11:36:26 PM) An error occurred when the request
was processed on the remote computer.)
(9/26/2013 11:36:26 PM) An error occurred when the request was processed on the remote computer.
The server experienced an issue processing the request. Contact the server administrator for
more information.
Publish failed to deploy.
Okay so lets look at line 4196 and column 5 of microsot.web.publishing.targets
4196 <VSMSDeploy
4167 Condition="!$(UseMsdeployExe)"
4198 MSDeployVersionsToTry="$(_MSDeployVersionsToTry)"
4199 Source="#(MsDeploySourceProviderSetting)"
4200 Destination="#(MsDeployDestinationProviderSetting)"
DisableLink="$(PublishDisableLinks)"
EnableLink="$(PublishEnableLinks)"
AllowUntrustedCertificate="$(AllowUntrustedCertificate)"
BuildingInsideVisualStudio="$(BuildingInsideVisualStudio)"
SkipExtraFilesOnServer="$(SkipExtraFilesOnServer)"
.....
>
Now I am at a dead end because I do not know what I am looking at. Any ideas? I am not sure what code is relevant, so please let me know if something else would be of assistance.

Related

How do I stop using ASPNETDB.MDF in LocalDB?

I implemented ASP.NET Identity and it automatically created ASPNETDB.MDF and aspnetdb_log.ldf in my App_Data folder. I already have the AspNet tables (i.e., AspNetRoles, AspNetUsers, etc) in my SQL Express instance (which is where all my other tables are sitting). As far as I can see, my application is reading and writing membership and role data from the SQL Express database and not ASPNETDB.MDF.
I have set my connectionString in web.config to:
<add name="DefaultConnection" connectionString="Data Source=MyComputerName\SQLEXPRESS;Initial Catalog=MyDatabaseName;Integrated Security=True" providerName="System.Data.SqlClient" />
However, if I remove ASPNETDB.MDF from App_Data, I get the following error when I login:
Exception Details: System.Data.SqlClient.SqlException: One or more files do not match the primary file of the database. If you are attempting to attach a database, retry the operation with the correct files. If this is an existing database, the file may be corrupted and should be restored from a backup.
Cannot open user default database. Login failed.
Login failed for user 'MyComputerName\MyUserName'.
Log file 'C:\Users\MyProjectName\App_Data\aspnetdb_log.ldf' does not match the primary file. It may be from a different database or the log may have been rebuilt previously
The error goes away once I add ASPNETDB.MDF back to App_Data.
I have searched all the code in my solution and it makes no reference to ASPNETDB. So why is it still trying to read from it?
I am developing ASP.NET web forms on .Net 4.5.
I was getting exactly the same problem. I discovered that VS annoyingly pulls in config settings from machine.config, which lives outside of the project, in my case in...
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
Identity 2.0 had used the following connection string inside machine.config...
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
to set up a connection for...
<membership>
<providers>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, ........" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
</providers>
</membership>
.. (which was also set in machine.config). If you haven't been using Membership then it's fine to do as Lord nick suggests (except just the clear/ will do the job) and simply do the following in web.config...
<connectionStrings>
<clear/>
<add name="DefaultConnection" connectionString="whatever" providerName="System.Data.SqlClient" />
However, if you, like me, previously had Membership running (https://msdn.microsoft.com/en-us/library/6e9y4s5t(v=vs.100).aspx), you will need to comment out or delete the following sections from machine.config...
<!--
<membership>
<providers>
...
</providers>
</membership>
<profile>
<providers>
...
</providers>
</profile>
<roleManager>
<providers>
..
</providers>
</roleManager>
-->
... since all this stuff is no longer needed for AspNet Identity 2.
I also had to add the following into in my web.config:
<modules>
<remove name="RoleManager"/>
</modules>
... as per this answer: Default Role Provider could not be found on IIS 7 running .NET 4
I hope I've saved someone some time. This took me hours and hours to work out.
I had the same Problem where the ASPNETDB.MDF was automatically created, even if I use Asp.Net Identity as the main user management.
I solved it by removing the following line from web.config:
<roleManager enabled="true" />
This one tells ASP.NET to use the older ASP.NET Membership user management, which is not supported by ASP.NET Identity.
It seems you have something like in your web.config
<add name="DefaultConnectionForLocalDb" connectionString="Data Source=(LocalDb)\v11.0;..."; />
In your AccountModels.cs file, you have:
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnectionForLocalDb")
{
}
}
However it should be this way:
<add name="DefaultConnectionForSQLEXPRESS" connectionString="data source=.\SQLEXPRESS;...;" />
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnectionForSQLEXPRESS")
{
}
}
Then you can remove safely DefaultConnectionForLocalDb entry from your web.config and ASPNETDB.MDF from to App_Data.
I don't know if you've figured this out or not but one of the things you can try is: in web.config, connections section, add <Clear/> and then <Remove Name=LocalSqlServer/>
Apparently if you don't change/remove the LocalSqlServe will still try to connect to the aspnetdb.mdf.
You might also think about adding back in the LocalSqlServer and having it point to your SqlExpress or SqlServer.

Asp.Net Unit Testing: Membership TypeLoadException for DefaultMembershipProvider

I have an ASP.Net Web Forms application and I am now writing some unit tests for it.
The test code throws a TypeLoadException at the following line:
if (Membership.GetUser("some name") == null)
The exception text says that "System.Web.Providers.DefaultMembershipProvider" in the assembly "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be loaded. When the running the application normally, everything works fine on the built-in test server as well as on the live IIS server. I have simply copied the Web.config from the Web forms application to the Unit test project. I should also mention that other database connections (e.g. Entity Framework) work fine. Here is the relevant config section:
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<clear />
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="10" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" passwordFormat="Hashed" />
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
I have also set a reference to System.Web in the Unit test project, but I still get the mentioned exception. Does anybody have a clue why this is not working in the Unit test project?
Update: the following line works fine, so the cause must be somehwere in the initialization of my DefaultMembershipProvider:
System.Web.Providers.DefaultMembershipProvider test= new System.Web.Providers.DefaultMembershipProvider();
The problem was "ClientAuthenticationMembershipProvider" was set as default provider. I don't know where it can from; it must have been added by NuGet or something. In my original Web.Config, it it not present. By removing it, everything worked again.

ASP.NET MVC 4 Template project fails to find 'MySql.Web

I have created a new project in ASP.NET MVC 4. Normally you just hit F5 and it runs as a semi empty project. Instead I'm getting:
Parser Error Message: Could not load file or assembly 'MySql.Web,
Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or
one of its dependencies. The system cannot find the file specified.
This makes no sense. I have no such entries in my config file and dont event want to use MySql. What has changed in MVC 4? What do I need to do?
I guess your machine.config file has been changed, I suggest take a look at that in either of these locations:
32-bit
x:\Windows\Microsoft.NET\Framework\[version]\config\machine.config
64-bit
x:\Windows\Microsoft.NET\Framework64\[version]\config\machine.config
as suggested by Petoj in this post
Where Is Machine.Config?
I was having the same issue ..adding following tags to web.config file worked for me :
<membership defaultProvider="SimpleMembershipProvider">
<providers>
<clear/>
<add name="SimpleMembershipProvider"
type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"
/>
</providers>
</membership>
<roleManager defaultProvider="SimpleRoleProvider">
<providers>
<clear/>
<add name="SimpleRoleProvider"
type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"
/>
</providers>
</roleManager>

The connection name 'DefaultConnection' was not found in the applications configuration or the connection string is empty

I just started getting this message when I run my ASP.NET MVC 4 application in debug mode in Visual Studio 2010 Professional in the internal development server. It was working fine till yesterday. It just started coming yesterday.
Also, this error comes only on my desktop. The application runs fine on all the other developer's machines, my laptop, and all the servers, both in debug mode as well as when deployed on IIS.
The actual error I get in the yellow screen of death is given below:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The connection name 'DefaultConnection' was not found in the applications configuration or the connection string is empty.
Source Error:
Line 267: <membership defaultProvider="DefaultMembershipProvider">
Line 268: <providers>
Line 269: <add name="DefaultMembershipProvider"
type="System.Web.Providers.DefaultMembershipProvider,
System.Web.Providers, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
connectionStringName="DefaultConnection"
enablePasswordRetrieval="false" enablePasswordReset="true"
requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10" applicationName="/" />
Line 270: </providers>
Line 271: </membership>
I checked the version history of my web.config in TFS and there isn't and there also never used to be a connection string by that name DefaultConnection ever.
Add this to your web.config file
<connectionStrings><add name="DefaultConnection" connectionString="Data Source=YourServername;Initial Catalog=YourDBname;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /></connectionStrings>
Only thing I can think of is you can browse the public pages without proper membership connection string. However, as soon as you browser pages which require authentication, it will fail.
It should work if you replace DefaultConnection with working connection string.

Attached DB Can login but not create user "invalid value for key 'attachdbfilename'"

I have a application running on our server (it works fine on my computer not that it matters).
It is a windows server 2003, Sql Express 2008 r2 server.
Im using a attached DB for storing users (the asp.net supplied db).
I can login to the web application with no problem but when i try to create a user it just says invalid value for key 'attachdbfilename' with the yellow screen of death.
here you have the connection string in the web.config
<add name="ConnectionStringASPNETDB.MDF" connectionString="Data Source=localhost\SQLEXPRESS_2008;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
and the membership provider
<add name="daganteckning" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ConnectionStringASPNETDB.MDF"
enablePasswordRetrieval="false"
enablePasswordReset="false"
requiresQuestionAndAnswer="false"
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
description="Stores and retrieves membership data from a Microsoft SQL Server database." />
My only guess is that there is some sort of directory/file security permission i must set but i have no idea what user iis/sql uses to access the database file.
Any one got a idea?
Edit:
I tryed by replacing localhost\sqlexpress_2008 with .\sqlexpress_2008 and now i got
Unable to open the physical file
"C:\Inetpub\wwwroot\MEDLEM_TEST\App_Data\ASPNETDB.MDF".
Operating system error 32: "32(The
process cannot access the file because
it is being used by another
process.)". An attempt to attach an
auto-named database for file
C:\Inetpub\wwwroot\MEDLEM_TEST\App_Data\ASPNETDB.MDF
failed. A database with the same name
exists, or specified file cannot be
opened, or it is located on UNC share.
Check if your server's antivirus or any other process could be accessing the file.
You could also try recycling the application after making the change you listed.
Also if you use the Asp.Net Configuration tool it will attach to the mdf file and your application will create that error while you are connected through that.
After browsing around i found that i was not using the defined provider unless i stated that i wanted to use it by name.. so i solved it by adding <clear /> to the Providers tag and adding the attribute defaultProvider="daganteckning" to the membership tag.
<membership defaultProvider="daganteckning">
<providers>
<clear />
<add name="daganteckning" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ConnectionStringASPNETDB.MDF"
enablePasswordRetrieval="false"
enablePasswordReset="false"
requiresQuestionAndAnswer="false"
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
description="Stores and retrieves membership data from a Microsoft SQL Server database." />
</providers>
....

Resources