ASP.NET Profile section in web.config disappears after successful build - asp.net-profiles

I'm trying to add a section to an ASP.NET web.config file for using the default profile provider. Here's what I'm adding to web.config in the system.web node:
<profile defaultProvider="AspNetSqlProfileProvider">
<providers>
<clear/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ApplicationServices"
applicationName="/"
/>
</providers>
<properties>
<group name="UserDetails">
<add name="FirstName" />
<add name="LastName" />
<add name="BirthDate"
type="System.DateTime" />
</group>
</properties>
</profile>
I can build the website successfully, but as soon as it completes I get the prompt that web.config has been modified outside of the editor and do I want to reload it. I click Yes, and the profile section disappears. Everything else in the web.config file remains intact and functioning correctly.
Any ideas of where to look for troubleshooting this issue? Thanks!

It sounds like you are editing the output config file in the Web site's root and that the build is overwriting with the unedited config held in the ASP.NET project.

Related

Can I enable tracing in OWIN?

I have an environmental problem somewhere in OWIN and I want to get some information about what is happening. I have read that I can enable tracing but can't find much information on how to do it.
I have added the following to my web.config but no joy. Is this possible?
<!-- 1. Enable the switch here. Without this, you get nothing. By default, Katana has "new SourceSwitch("Microsoft.Owin")" at the root level. -->
<switches>
<add name="Microsoft.Owin" value="Verbose" />
</switches>
<!-- 2. Add your shared listeners. -->
<trace autoflush="true" />
<sharedListeners>
<add name="file" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\traces\Microsoft.OWIN.trace.log" />
<add name="console" type="System.Diagnostics.ConsoleTraceListener" />
</sharedListeners>
<sources>
<!-- "Microsoft.Owin" is the SourceSwitch name katana is using at the rootlevel. By enabling this, we are enabling all sub level traces by the components (if we don't change the default trace settings). -->
<source name="Microsoft.Owin">
<listeners>
<add name="file" />
<add name="console" />
</listeners>
</source>
</sources>
Not 100% sure that this will solve your issue, but we got it working with following config. Slight difference in the following line:
<source name="Microsoft.Owin" switchName="Microsoft.Owin" switchType="System.Diagnostics.SourceSwitch">
Notice that the <source> tag includes a switchName (and switchType) attribute which is missing from your example. I think that this instruction links the TraceSource with the Switch and makes the entire work.
In our case, we use trace listeners for Azure Web sites (and web jobs).
<system.diagnostics>
<sharedListeners>
<add name="AzureTableTraceListener" type="Microsoft.WindowsAzure.WebSites.Diagnostics.AzureTableTraceListener, Microsoft.WindowsAzure.WebSites.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="AzureBlobTraceListener" type="Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener, Microsoft.WindowsAzure.WebSites.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="AzureDriveTraceListener" type="Microsoft.WindowsAzure.WebSites.Diagnostics.AzureDriveTraceListener, Microsoft.WindowsAzure.WebSites.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</sharedListeners>
<sources>
<source name="Microsoft.Owin" switchName="Microsoft.Owin" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="AzureTableTraceListener"/>
<add name="AzureDriveTraceListener"/>
</listeners>
</source>
</sources>
<switches>
<add name="Microsoft.Owin" value="All" />
</switches>
<trace autoflush="true" indentsize="4" />
</system.diagnostics>

Issue: creating AD FS claims aware application in Visual Studio 2013

I am new to trying to use AD FS and I have been running in circles.
Trying to make a claims aware application
The organization handles its own authentication
I have gotten my test application to verify authentication but it seems wrong.
Create new application in Visual Studio
Choose Web -> Visual Studio
Choose .Net Framework 4.5
Select ASP.Net MVC 4 Web Application
Add Reference to System.Identity
Add Reference to System.Identity.Services
Edit my web.Config file
in the configsection -- add the following
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
then add
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="ida:FederationMetadataLocation" value="https://fedtest.xxxxxxxx.com/FederationMetadata/2007-06/FederationMetadata.xml" />
<add key="ida:Realm" value="https://myappNameHere.xxxxxx.com" />
<add key="ida:AudienceUri" value="http://myappNameHere.xxxxxxx.com" />
<add key="loginUrl" value="~/Home" />
</appSettings>
Then add
<location path="Home">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="Logout.html">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
Then add
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authorization>
<deny users="?" />
</authorization>
<authentication mode="None" />
</system.web>
Then add
<identityConfiguration>
<audienceUris>
<add value="http://myappName.xxxxxx.com/" />
</audienceUris>`
<issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry">
<authority name="http://fedtest.xxxxxxx.com/adfs/services/trust">
<keys>
<add thumbprint="12345567890asdasfsdgdfhdfgjdf123124" />
</keys>
<validIssuers>
<add name="http://fedtest.xxxxxxxx.com/adfs/services/trust" />
</validIssuers>
</authority>
</issuerNameRegistry>
<securityTokenHandlers>
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</securityTokenHandlers>
<certificateValidation certificateValidationMode="None" />
</identityConfiguration>
</system.identityModel>
<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="true" />
<wsFederation passiveRedirectEnabled="true"
issuer="https://fedtest.xxxxxxxxx.com/adfs/ls/"
realm="https://myappName.xxxxxxxx.com/"
reply="https://myappName.xxxxxxxxx.com/"
requireHttps="true" />
</federationConfiguration>
</system.identityModel.services>
Why do I think all this is wrong?? Well I got all those lines of web.config from the following steps...
go back to step 5 and do the following
Under Tempalte click web
chose the only option --- ASP.NET Web Application
Wizard comes up and click the 'change Authentication'
Choose Organizational accounts
change drop down to 'On Premises'
fill out 'On-Premises Authority'
Fill out 'App ID URI'
Look at web.config
But using the application that those steps produce will create a redirect loop that I have never been able to trouble shoot.
So -- suggestions on what I am doing wrong. It can't be considered right to generate the web.config in a standard way and paste it into a previous version to get it to work.
Refer: Use the On-Premises Organizational Authentication Option (ADFS) With ASP.NET in Visual Studio 2013.
In terms of the redirect loop. the usual reason is that for your ADFS RP, you configured the endpoint without a trailing slash.
Add the missing "/" and ensure it matches the string in your web.config.
Enable SSL in your application and set the SSL URL as the default in your web properties.
Okay -- what the answer ended up being...
1) I started down this route because i kept getting a redirect loop that I thought was caused by the web.config.
It wasn't the web.config.
2) So create the the application as you are supposed to in VS 13 -- namely go to c# -> web -> and then click the ASP.NET Web Application and set up the on premise authentication
3) My redirect loop was caused by multiple LDAP claims bundled together coming from AD FS
4) Sent my claims one rule at a time and worked like magic.
If anyone can shed light as to why this should be true I am curious.

Problem running MVC3 app in IIS 7

I am having a problem getting a MVC 3 project running in IIS7 on a computer running Windows 7 Home-64 bit. Here is what I did.
Installed IIS 7.
Accessed the server and got the IIS welcome page.
Created a directory named d:\MySite and copied the MVC application to it. (The MVC app is just the standard app that is created when you create a new MVC3 project in visual studio. It just displays a home page and an account logon page. It runs fine inside the Visual Studio development server and I also copied it out to my hosting site and it works fine there)
Started IIS management console.
Stopped the default site.
Added a new site named "MySite" with a physical directory of "d:\Mysite"
Changed the application pool named MySite to use .Net Framework 4.0, Integrated pipeline
When I access the site in the browser I get a list of the files in the d:\MySite directory. It is as if IIS is not recognizing the contents of d:\MySite as an MVC application.
What do I need to do to resolve this?
As requested, here is the web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I posted this question on "ServerFault" as well and got a resolution to the issue here.
The answer is:
Since IIS was installed after .NET 4, you likely need to run the aspnet_regiis.exe tool to register all the .NET 4 stuff with IIS.
I like to add some details:
After registering ASP.NET 4 using aspnet_regiis -i I also had to update the web application using aspnet_regiis -s W3SVC/1/ROOT/SampleApp1 in order to fix the problem.
The /1/ in W3SVC/1/ROOT/SampleApp1 is the instance of your web application. You can find it by looking into your IIS Manager in the column ID.
The ROOT/SampleApp1 in W3SVC/1/ROOT/SampleApp1 is your application path. If you want to update all sites, just do aspnet_regiis -s W3SVC/.
Afterwards it worked fine for me.
I had 403.14 errors when running an MVC 3 website on the server. Server was 32 bit. 2008. IIS7. The problem was that the HTTP Redirection feature was not installed. Server Manager -> Roles -> Web Server -> Roles Services -> HTTP Redirection. This is the only thing that fixed it for me. The web.config needed no change.
I think the majority of IIS7 website setup problems is due to folder security. If you try to create a website by copying the application folders directly from your dev environment to a folder not under wwwroot, the security on your folders will be wrong and you will fight it for hours getting ambiguous errors. The EASY way to get it correct, is to inspect and inetpub/wwwroot folder, examine it and add permissions to your folder, starting with computername\IIS_IUSRS and computername\Users. For mvc, make sure you have a web.config AND global.asax at the root. You do not need a default document for mvc and you should not allow directory browsing. If using aspnet_regiis, you may want to use the -ir if there are other sites being hosted on the machine.
Have you checked the websites default document in IIS is at the top of the list.
I think it defaults to default.asp with default.aspx either not there or at the bottom of the list
I didn't solve this problem until I install .net v4.0.30319 ,before that .net version on my machine is v4.0.30128 . It takes me a long time to figure out the problem,hope this can help someone.

ASP.NET Web Site Administration Tool unkown Error ASP.NET 4 VS 2010

I was following the MVCMusic tutorial with an machine with full sql server 2008 r2
and full visual studio professional, in ASP.NET 4.0 and when I got to the page where it sets up membership (near page 66) the Web administration tool wont work, i got the following error:
An error was encountered. Please return to the previous page and try again.
my web config is like this:
<connectionStrings>
<clear />
<add name="MvcMusicStoreCN" connectionString="Data Source=.;Initial Catalog=MvcMusicStore;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MvcMusicStoreEntities" connectionString="metadata=res://*/Models.Store.csdl|res://*/Models.Store.ssdl|res://*/Models.Store.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=MvcMusicStore;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<membership defaultProvider="AspNetSqlMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MvcMusicStoreCN" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10" applicationName="/" passwordFormat="Hashed" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider"
connectionStringName="MvcMusicStoreCN" applicationName="/" />
</providers>
</profile>
<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
<providers>
<clear />
<add connectionStringName="MvcMusicStoreCN" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/" name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
<customErrors mode="Off">
</customErrors>
</system.web>
EDIT: I've run the
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regsql.exe
executable and added the tables to my MvcMusicStore database sucessfully, changed the web.config from MY application (MVCMusicStore), and tryed running the ASP.NET Configuration shortcut, and got the error.
My Default Browser is firefox, and when I click the shortcut the browser doesn't even open the page, only when I right click on the tray icon and choose open in web browser.
I've solved it, I entered another project (VS 2010 doesn't let me change the default browser in an MVC project) changed the default browser, changed back to the MVC project and tryed opening the configuration again, and it worked.
Looks like the configuration doesn't allow firefox.
Thanks Anyway Raj.
Get your app to show detailed errors by turning off custom errors
http://msdn.microsoft.com/en-us/library/h0hfz6fc(VS.71).aspx
<configuration>
<system.web>
<customErrors mode="Off">
</customErrors>
</system.web>
</configuration>
I also experienced this problem and found out it was because the directory my solution was in contained a weird character. 'C:....\C#' Changing the directory to CSharp got rid of this problem.

Getting an ASP.MVC2/VS2010 application to work in IIS 7.5

I've recently downloaded beta 2 of VS2010 and started playing with ASP.NET MVC2. Initial development was done with Casini, but now I wanted to run the application from IIS 7.5 (I'm running Windows 7).
I've installed the IIS6 metabase compatiblity and I run VS2010 as administrator so I can use the "Create Virtual Directory" button from the "Web" tab of the project settings.
This created the web application entry in IIS, but it doesn't work.
When I go to the main page (http://localhost/MyMvcApp/) I get a HTTP 403 error. When I go directly to one of the sub-pages (http://localhost/MyMvcApp/Home/) I get an HTTP 404.
So I guess for some reason the URL routing isn't working.
I've already added UrlRouting as a module and a handler to the web.config. In my searches this is offered as a solution for some similair problems. But for me this still doesn't work.
The interesting part of my web.config looke like this:
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
<httpHandlers>
<add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler" />
</httpHandlers>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" >
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
<remove name="MvcHttpHandler" />
<add name="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler" />
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
<httpErrors errorMode="Detailed" />
</system.webServer>
I've just had this problem, and unfortunately the fix here didn't work for me.
What did work was running this:
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
in a command window...works like a dream now!
(So, is ASP.Net not installed into IIS by default when you install VS2010?)
After more checking and trying I noticed in the "Turn Windows features on or off" dialog that "HTTP Errors" and "HTTP Redirection" were missing.
This is strange because as far as I can remember this was installed automatically by the Microsoft Web Platform Installer.
In any case "HTTP Redirection" seemed like a need-to-have feature when working with MVC. So after I installed it everything seemed to work perfectly.
Add this to your web.config file:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!-- rest of config -->
</system.webServer>
It is such a pain doing this manually. But definitely doable! I managed it and summed it up in this step by step guide on adding an mvc 2 project to an exisitng web forms solution here. Hope this helps... it took me ages to work though all the config settings and there seem to be so few resources on the subject.
Please note that you must run aspnet_regiis.exe -ir as administrator, it seems obvious but when you are tired of trying things with no success to solve that, you could pass it.
Just to say a big THANK YOU to all the responses, after many hours trying different things, finally I could get work my MVC 2 app in IIS.
What Helped to me is using classic pipeline for AppPool instead of integrated:
I was building an MVC2 application on my laptop Windows 7, using .net beta 2 and
VS 2010 beta 2. When I installed the entire development environment on Windows Server 2008, including VS, built the solution and ran it, the routing worked fine.
The next step was to create a production server on Windows Server 2008, on which I deployed the .net 4.0 beta but none of the other stuff which came with the VS 2010 beta download.
Under this configuration the routing never worked until I enable HTTP Redirection as indicated by Jeroen.
Hope this helps someone who might be in the same boat.
Just wanted to note that I was having the same problem with 403 and 404s but adding the system.webServer and all the elements from the system.web/pages/namespaces node resolved it for me.

Resources