How to configure multiple sitemaps with asp:menu control - web-config

It's driving me nuts. I've searched and tried and searched and tried ... now I ask for your help!
I have an asp:menu control that uses a sitemap. Once the user is authenticated, I want to dynamically change the site map from code behind (c#). Here's the pertinent lines of code:
Site.Master:
<asp:Menu ID="aspMenu" runat="server" StaticDisplayLevels="1" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False">
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False"
StartFromCurrentNode="False" StartingNodeOffset="0" />
web.config:
<siteMap defaultProvider="WebSitemap" >
<providers>
<add name="WebSitemap" type="System.Web.XmlSiteMapProvider" siteMapFile="Web.sitemap"/>
<add name="MemberSiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="Member.sitemap"/>
</providers>
</siteMap>
Site.Master.cs:
protected override void OnPreRender(System.EventArgs e)
{
if (Request.IsAuthenticated)
{
SiteMapDataSource1.SiteMapProvider = "MemberSitemap";
}
}
After a successful build (VS 2010, 4.0 framework) I get the following error after a login:
Server Error in '/' Application.
The SiteMapProvider 'MemberSitemap' cannot be found.
What am I doing wrong? Thanks .... Bob

Duh, had the siteMap providers in the wrong section of web.config. I don't recommend web.config on sleep deprivation.

Related

Logging in Identity Server 3

There seems to be a lot of people asking questions about this, and yet the folks over there have decided to close my question before it's resolved; the perception being that I'm a lazy developer and haven't read documentation - not the case: https://github.com/IdentityServer/IdentityServer3/issues/3083
I've followed the instructions here: https://identityserver.github.io/Documentation/docsv2/configuration/logging.html
but I cannot get logging to happen.
My question really at this point in time is, assuming I haven't done something wrong, does it matter that I'm firing things from a unit test method?
I have a separate unit test project which is just requesting a token and writing the response out, but I'm getting a 500 error somewhere and I'd assume logging would tell me why.
The test was working before I had some repo issues a while ago and lost some work, and I THINK I am back to where I was, but I'm sure the root cause will be something simple that I've overlooked - it usually is.
Anyway, I really hope someone can help, and not just be snotty.
Many thanks!
First adding logger to IdentityServer Configuration (if Owin, under Startup public void Configuration(IAppBuilder app) method;
Serilog.Log.Logger = new LoggerConfiguration()
.WriteTo.Trace(outputTemplate: "{Timestamp} [{Level}] ({Name}){NewLine} {Message}{NewLine}{Exception}")
.CreateLogger();
Then adding webconfig the following under configuration;
<system.diagnostics>
<sources>
<source name="Thinktecture.IdentityServer" switchValue="Information, ActivityTracing">
<listeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="trace.svclog" />
</listeners>
</source>
</sources>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="sybsListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="Trace.log" />
<remove name="Default" />
</listeners>
</trace>
After running, and trying to interact with the IndentityServer, you can check the Trace.log file under your project. Don't forget selecting "Show All Files"
Based on Trace.log, can you specify the problem again if you can't solve?
I managed get logging working by wrapping my unit test in
using (var logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File(#"C:\Users\Richard Terris\Desktop\idsLogs.txt")
.CreateLogger())
{
It's not the best solution possibly, but it works!
Thanks for the replies!

Sitecore 8.1 error: "No session Id managers were found to manage the session Id for the current request"

I'm attempting to get a basic layout up and running in Sitecore 8.1, and I've hit an error about which I can find very little information. When attempting to view any page (even the backend interface or connecting from Sitecore Rocks), I get the message "No session Id managers were found to manage the session Id for the current request."
Some Googling suggests that this has to do with some issues with the out-of-box session provider and recommends swapping it out for keeping the sessions in Mongo. Sitecore's documentation provides a description of this, both for shared and private sessions. I've attempted to implement those but continue to receive the same error.
Here's my code as it stands now:
App_Config/Include/MongoSessionProvider.config
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<tracking>
<sharedSessionState>
<providers>
<clear/>
<add name="mongo" type="Sitecore.SessionProvider.MongoDB.MongoSessionProvider, Sitecore.SessionProvider.MongoDB" connectionString="session" pollingInterval="2" compression="true" sessionType="shared"/>
</providers>
</sharedSessionState>
</tracking>
</sitecore>
</configuration>
App_Config/Include/ConnectionStrings.config (excerpt)
<add name="session" connectionString="mongodb://localhost/sharedsession" />
Web.config (excerpt)
<sessionState mode="Custom" cookieless="false" timeout="20" sessionIDManagerType="Sitecore.FXM.SessionManagement.ConditionalSessionIdManager" customProvider="mongo">
<providers>
<add name="mongo" type="Sitecore.SessionProvider.MongoDB.MongoSessionStateProvider, Sitecore.SessionProvider.MongoDB" sessionType="Standard" connectionStringName="session" pollingInterval="2" compression="true" />
<add name="mssql" type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider, Sitecore.SessionProvider.Sql" sessionType="Standard" connectionStringName="session" pollingInterval="2" compression="true" />
</providers>
</sessionState>
Note that this is on my local development machine. I have Mongo running (and confirmed its connection to Sitecore), and I created both the session and sharedsession databases in it using use session and use sharedsession, which I understand to be the way to create DBs in Mongo.
Am I missing something here? Or does the error simply not mean what I think it means?
The message you are seeing is not supposed to be an error, it is rather a log warning. It is related to retrieving the configuration of the Session ID Manager rather that to the configuration of the session itself.
Why this warning normally appears
In the Sitecore.config under <pipelines> there's the getSessionIdManager pipeline defined.
<getSessionIdManager>
</getSessionIdManager>
In the Sitecore.FXM.config, there is a processor configured for this pipeline:
<getSessionIdManager>
<processor type="Sitecore.FXM.Pipelines.ChooseSessionIdManager.FXMSessionIdManagerProcessor, Sitecore.FXM" />
</getSessionIdManager>
This pipeline allows to dynamically select a Session ID Manager for the request. In the default Sitecore configuration, a non-default Session ID Manager will be used only for requests with explicit sessionId URL parameter, i.e. for FXM requests only.
For all other requests, no Session ID Manager will be explicitly selected, and the default System.Web.SessionState.SessionIDManager will be used; this is reflected in the warning message you're seeing. There is nothing wrong with this situation per se, this is by default and by design.
Seeing the message as an error on every page request
This definitely sounds like a defect to me. This message is supposed to be logged once per application lifetime instead of being thrown as an exception on every page.
You should report this to Sitecore support.
An attempt to fix
I cannot debug your system, so I have to do this blindfolded. I would try to create you own Session ID Manager selector:
public class CustomSessionIdManagerProcessor
{
public void Process(GetSessionIdManagerArgs args)
{
if(args.SessionIdManager == null)
{
args.SessionIdManager = new System.Web.SessionState.SessionIDManager();
}
}
}
Configure it as the last processor in the getSessionIdManager pipeline. This will make sure that there is always an explicitly selected Session ID Manager and should hopefully prevent the error from happening.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<getSessionIdManager>
<processor type="YourNamespace.CustomSessionIdManagerProcessor, YourAssembly" />
</getSessionIdManager>
</pipelines>
</sitecore>
</configuration>
In case it helps anyone else, we were running into this issue as well after upgrading to Sitecore 8.1 rev. 151003.
In our particular case the issue was with a namespace change in this line in the Web.config:
<sessionState mode="InProc" cookieless="false" timeout="20"
sessionIDManagerType="Sitecore.FXM.SessionManagement.ConditionalSessionIdManager">
That should be the following:
<sessionState mode="InProc" cookieless="false" timeout="20"
sessionIDManagerType="Sitecore.SessionManagement.ConditionalSessionIdManager">
It might have been something we missed in the upgrade guide, but we finall found it after pulling down the a copy of Sitecore 8.1 rev. 151003.zip from the downloads page.

How to separate between debug and release for connections etc in mvc4

So I am fairly new MVC4 and many patterns are new to me.
However the one thing I am curious about is best practice about release/debug modes.
There are a bunch of things for me that differ between live and debug mode and I would like for all of them to be automatic so I don't need to change anything to publish.
So for instance I have done like this in my repo (domain project)
public class EFAccountRepository : IAccountRepository
{
private EFDbContext _context;
public EFAccountRepository()
{
#if DEBUG
_context = new EFDbContext("name=Debug");
#else
_context = new EFDbContext("name=Live");
#endif
}
and like this in my DI (webui)
#if DEBUG
EFDbContext efcontext = new EFDbContext("name=Debug");
#else
EFDbContext efcontext = new EFDbContext("name=Live");
#endif
Or would it be smarter to simply have
EFDbContext efcontext = new EFDbContext("name=MyApp");
And then change with web.config transform what MyApp means?
Any other tips of automating debug/release-publish is warmly welcomed.
I would strongly recommend not hardcoding your connection strings into your code. Please consider pointing your code to a web.config transform. You can add the connection string there and depending on the version of code the proper transform can be applied so that you simply need to use the following code once in your app to cover all environments.
ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString
Inside of the debug version you could have something similar to
<configuration xmlns:xdt="...">
<connectionStrings>
<add name="MyConnectionString" connectionString="debugstring"
providerName="debugprovider" />
</connectionStrings>
</configuration>
Inside your release version you can tell the transform to replace your old string as so
<configuration xmlns:xdt="...">
<connectionStrings>
<add name="MyConnectionString" connectionString="newstring"
providerName="newprovider"
xdt:Transform="Replace" />
</connectionStrings>
</configuration>
for more reference check out
http://msdn.microsoft.com/en-us/library/dd465326.aspx
The selected answer will not work if you have more than one connection string. in the release config add below tags for all your connectionstrings
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"
This is what I have in my Web configuration files
in Web.Debug.Config
<add name="MyConnectionString"
connectionString="Data Source=dev;Initial Catalog=DevDB;Integrated Security=True;
providerName="System.Data.SqlClient"/>
and in Web.Release.Config
<add name="MyConnectionString"
connectionString="Data Source=LIVESERVER;Initial Catalog=DB98;Integrated Security=True;
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
Use web.config transformations http://msdn.microsoft.com/en-us/library/dd465326.aspx

Azure EF Code First Migration Initializer

I am just messing with Azure, and I can't seem to get my Db to work. I am following what it says here: https://www.windowsazure.com/en-us/develop/net/tutorials/web-site-with-sql-database/ and I updated my web.config to have this:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<contexts>
<context type="DownloadThis.Models.DownloadThisDb, DownloadThisDb">
<databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion">
<parameters>
<parameter value="DownloadThisDb_DatabasePublish" />
</parameters>
</databaseInitializer>
</context>
</contexts>
</entityFramework>
As is shown in the example, but I keep getting this error:
Format of the initialization string does not conform to specification
starting at index 0.
I have triple checked my connectionString, so that isn't it - any ideas?
Assuming that you're publishing with the VS2012 publish wizard, I've run into the same issue. If you choose to have the publishing wizard enable code first migrations instead of manually wiring them up in your code, then you need to provide a connection string in the publish settings. Your normal connection string is not used to run the migrations, this new connection string is used for this purpose only. This is nice because you can specify an account that has elevated privileges for performing your migrations, however, your app won't run under this user context. The problem is that the wizard doesn't make the need to specify this connection string very obvious. When you don't supply this, you end up with a null migration connection string and you spend a lot of time trying to figure out what's wrong with your normal connection strings.
Let's say that your context class is named FooContext. By convention, you'll have a connection string in your web.config named FooContext. When you enable code migrations via this wizard, the wizard will create a second connection string named FooContext_DatabasePublish that will only be used for running your code first migrations.
This blog post on MSDN explains this process in some detail.
I think you're missing a . in your type string:
<databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion">
The red rectangle over the code makes it hard to read...
If that doest fix it, post a comment and I'll work up a sample to match yours and see if I can get it to work...
[UPDATED 2012-08-15]
OK - I think I know what's going on here... You mentioned "I updated my web.config to have this:" and showed your XML. When I ran through the tutorial, I did NOT have to enter ANY extra XML into my web.config. During the publishing process, the XML was added for me automagically by Visual Studio's deployment process and it all "just worked".
Here's your solution:
Go back to the original web.config file without these updates, and try publishing again.
For reference, here are the <entityFramework> sections from my two web.config files, first from my project, second from my hosted service (I got that by connecting to the running site via FTP and downloading it). The VS project is called 11964172 after the SO record number for this post:
local web.config file settings
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
deployed web.config file settings
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<contexts>
<context type="_11963331.Models.ToDoDb, 11963331">
<databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[_11963331.Models.ToDoDb, 11963331], [_11963331.Migrations.Configuration, 11963331]], EntityFramework, PublicKeyToken=b77a5c561934e089">
<parameters>
<parameter value="_11963331.Models.ToDoDb_DatabasePublish" />
</parameters>
</databaseInitializer>
</context>
</contexts>
</entityFramework>
I guess that explains why they took a picture of the web.config file changes instead of actually providing the code to type in :-)
See this question. If you leave the deployment connection string as "Remote connection string", and check the "Execute Code First Migrations" box, you will get this exception as the migration connection string, DownloadThisDb_DatabasePublish will not be defined properly. Either specify a real connection string instead of leaving the connection string box blank in the deployment wizard, or define a connection string named DownloadThisDb_DatabasePublish in your Azure site configuration.

Simulating timeout on ASP.NET MVC

Problem:
I need to create a web project with a controller that times out.
What I have done:
Create a new web application
Empty the web.config, and write the values below:
.
<?xml version="1.0"?>
<configuration>
<system.web>
<httpRuntime executionTimeout="1" />
<compilation debug="false" />
<httpModules>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
</system.web>
</configuration>
Write the following code to the controller:
.
public class DefaultController : Controller
{
public EmptyResult Index()
{
System.Threading.Thread.Sleep(3000);
Response.Write("ScriptTimeout: " + HttpContext.Server.ScriptTimeout);
return new EmptyResult();
}
}
When run, the server sleeps for 3 seconds, then returns the response without any timeout error. ScriptTimeout value is 1.
Question:
Any idea what went wrong?
Do you want a 408 Request Timeout HTTP status code?
public ActionResult Index()
{
return new HttpStatusCodeResult(408);
}
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
The executionTimeout attribute on the <httpRuntime/> element is only taken into account if debug="false" on the <compilation/> element.
Try removing the debug attribute or explicitly setting it to false. Of course, you'll have to run your application without debugging to test it.
See http://msdn.microsoft.com/en-gb/library/vstudio/e1f13641(v=vs.100).aspx for more details.