C# Change Sitemap From Ashx To Xml?
Mar 7, 2011sitemap is at: http://localhost/scirranew/sitemap.ashx
<%@ WebHandler Language="C#" Class="SiteMap" %>
using System;
using System.Web;
[code]...
sitemap is at: http://localhost/scirranew/sitemap.ashx
<%@ WebHandler Language="C#" Class="SiteMap" %>
using System;
using System.Web;
[code]...
I've got a custom menu navigation built from a web.sitemap file, the first line of this would be something like:
SiteMapNodeCollection topLevelNodes = SiteMap.RootNode.ChildNodes;
However, now I want to be able to create multiple web.sitemap files, and then programmatically determine which web.sitemap file to use, but I can't seem to find out how to do this. I'm assuming I could either create one custom SiteMapProvider that can perform the logic to determine which web.sitemap file to load, or I have multiple providers, each one with the SiteMapFile property set to a specific *.sitemap file, and then switch providers programmatically before I access SiteMap.RootNode.
I have multiple .sitemap xml defined with different providers. For one xml file, I want to change the url (append Customerid in the url) by taking the defined url in xml file. I want this to be changed when the page is loaded the first time.
For eg one of my node is
<siteMapNode
url="~/CustDetail.aspx?type=Contact"
title="Contacts"
description="Contacts">
And I want to make it as
<siteMapNode
url="~/CustDetail.aspx?type=Contact&CustID=ABCD"
title="Contacts"
description="Contacts">
I have read many articles online talking about changing node in memory but cant make it work.
I have a CMS that allows an administrator to add/create pages for his website.
When a page is created a SiteMapNode is added to the web.sitemap file with the an url , title and resourceKey.
Now I wish to add a resourcekey to the appropriate web.sitemap.resx file(located in App_GlobalResources).
I have tried many different ways :
- using XMLDocument load/save => says I don't have access to write to that resource file
- ResourceReader says the source stream is not valid.
We are getting this error message when we try to click the link in the menu to go to Report Server:
Source Error:
Line 31: <siteMapNode title="Reports" description="Reports">
Line 32:
Line 33: <siteMapNode url="https://ffxsqldgc01.ffx.co.fairfax.va.us/Reports/Pages/Folder.aspx?ItemPath=%2fDPZ&ViewMode=List" title="View Reports"
description="Click here to view the reports" />
Line 34: </siteMapNode>
Line 35:
I tried to add after the &, as it was suggested on one of the forum but it did not work. Any other ideas.
I've been having some production runtime errors that I don't fully understand. This has happened to us on a couple different ASP.NET 4.0 Web Sites (shudders - yes, I know - we're porting it to MVC but that's taking some time).
First of all, we have never been able to reproduce this issue in development/QA environments. Secondly, upon deployment, the issue seems to be non-existent. Sometimes the issue manifests within a day or two of deployment and other times the deployment will be live for a month without it manifesting at all. However, once it manifests, then ANY page viewed under the web site causes the error. Lastly, this problem seemed to only come up once we migrated to .NET 4.0. We started at 2.0, a year ago upped to 3.5, and recently upped to 4.0 with this solution and most child projects.
The error:
Could not find the sitemap node with URL '~/Default.aspx'.
A simplified version of our sitemap (with some names changed and uninteresting nodes removed) is as follows:
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<siteMapNode roles="*" title="EG">
<siteMapNode url="~/../SM/Default.aspx" title="Welcome" description="" roles="*" />
<siteMapNode url="~/../SD/Default.aspx" title="SD" description="" roles="*" />
<siteMapNode url="~/../SMD/Default.aspx" title="SMD" description="" roles="*" />
[code]...
I have confirmed in all of the SiteMaps that there is a node with url="~/Default.aspx" with roles="*" (which includes public/anonymous access), so I am very confused as to why this problem occurs.
SiteMap does not have a node for Default.aspx. All of them do. SiteMap's Default.aspx node is not accessible for security reasons to the current user/role. They're all accessible to anonymous users and this problem even exists for super admin users. Passed-in URL contains querystrings (Default.aspx?abcd). I don't know if this is a problem (I sure would hope not) but once the problem manifests itself, I can handwrite the URL with no querystrings and the problem still exists.
SiteMap changes. It doesn't Service's permissions to the sitemap file. The sitemap works perfectly fine after a deployment, so unless permissions are changed in a way that IISRESET fixes, then this is not an issue. The worker process becomes globally corrupt. I don't think so. We have ~12 web sites all in the same app pool and the problem always stays confined within a single web site. Also, we have yet to have this happen to more than a single web site at a time although it has manifested itself in 4 different ones so far.
I am creating a CacheDependency on the file that my SiteMap provider uses. I would like to get the name of the file from my sitemap provider instead of hard coding it. Is there a way?
Edit
Duh, I forgot to mention: XmlSiteMapProvider that comes with ASP.NET
Edit 2
Reflector shows a private member field called _filename that isn't exposed in any way as far as I can tell.
How would I programatically reference a .sitemap file that is not the root web.sitemap file? I have a file called research.sitemap in a folder a level under root. I want to refernce this file in my code behind like his: SiteMapNode m1 = SiteMap.RootNode (but since this isnt web.sitemap in the root, I dont know how to get access to it).
View 1 RepliesI have a second level node that goes onto two lines. The first line indents 15px as is set by the class for node level 2. The seond line kicks back to the same level as 1st level nodes. Here's what I mean:
Parent Node
Second node
line 2 of second node
I want it to be like this:
Parent Node
Second Node
line 2 of second node
I got an ashx file to create an image. I am referencing it via web.config like this:
<add verb="*" path="captcha.ashx" validate="false" type="eVoila.Security.Captcha.CaptchaImageHandler, eVoila" />
My handler looks like that:
[Code]....
Actually the handler never gets called. I already searched the forums and tried some tips and hints. But nothing of that worked. Try to call the url via[URL]
Can u explain me what ASHX HttpHandler uses for?
View 7 RepliesThere is an ashx file containing "ProcessRequest(HttpContext context)" method which gets triggered automatically. When and how does it get fired?Another question, How can I get the current QueryString when I am inside this file? When I type "context.Request.QueryString" it says it's null or empty although the address have arguments.
View 1 RepliesI've got a simple ASHX handler that returns an dynamically generated image; the image is generated from a custom created class, and an object belonging to this class is passed to the handler using Session (I'd rather avoid using QueryString).The handler is used as the URL of an image on a ASP form which is very simple: a drop down list, a button and an image. Basically, depending on what the user selects from the list, the appropriate image will be generated once the button is pressed.
At the start the actual image has it's Visible property set to false; I don't want the handler to display anything before the data is all there.Once the button is pressed, the required Session parameter is added containing the necessary object, and the page is refreshed using Server.Transfer. When the Page_load method detects that the Session parameter has been correctly set, it sets the Visible parameter on the image to true.After that the handler fires up and generates the image.
So far so good... However, if the user now picks something different from the list and presses the button, despite the correct object being passed in the Session, the image won't be updated. In fact, the handler won't even fire up (if I put a breakpoint in there). I need to close the browser window and reopen it for it to work.Any ideas what could be the cause of such behaviour?I suspect the answer is very simple, and I just don't know something fundamental about ASP (or handlers)...
In my web application I use an ashx file to write a file to the browser. I've noticed that there's no compression over the .ashx file, but only over my .aspx files.
Is it possible to compress .ashx? And if it is possible, how?
Currently I use global.asax to handle the compression:
<%@ Application Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.IO.Compression" %>
<script runat="server">
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;.......
As you can see only files which inherit from 'Page' are compressed, and my ashx file is not of type Page. So I added a condition and now it works just fine:
if (!(app.Context.CurrentHandler is Page ||
app.Context.CurrentHandler.GetType().Name == "SyncSessionlessHandler" ||
app.Context.CurrentHandler is ViewMht // This is the type I had to add
) ||
app.Request["HTTP_X_MICROSOFTAJAX"] != null)
return;
What is the Difference betweeen axd and ashx handlers.
View 3 RepliesMy web site has a handler (FileDownload.ashx) that deals with all file download requests. I've recently migrated my site to ASP.Net 4.0, and it now uses routing extensively. Everything works fine when dealing with page requests (aspx), but it's not working with my handler - I encounter the following error:
Type '<snip>.Handlers.FileDownload' does not inherit from 'System.Web.UI.Page'.
This makes sense, as routing is only implemented in the page. So, my question is, what steps do I need to take to be able to use routing and my ASHX together? I want to be able to extract RouteData.Values from the url.
public class FileDownload : IHttpHandler
{
}
i have a handler(.ashx) that returns an html . i want to call the handler in .ashmx(webservice). how do i call it?
View 1 RepliesI would like to use Server.UrlEncode in .ashx.
I try with the following code.
HttpServerUtility ser = new HttpServerUtility();
ser.UrlEncode(pfile.FileName);
That's wrong but however I would like to use Server.UrlEncode so let know the way.
I have created webpage and I am calling it from Jquery function. Technically I am {info} is image button and I am replacing with it with aspx
.replace("${info}","/_layouts/webpage.aspx");
The web page is opening in new browser window. Is there any way that I could make it as pop up whereever I can place in the page. That is get rid off the toolbar address bar. It should look like a pop up.
I am using ashx to serve images from a database, is there anyway to have a user click on a link that allows them to download the file on the computer. (IE it shows the Save Dialog) Like you download a file.
View 2 RepliesI've been trying to use the jQuery plugin Colorbox to display images I have in my DB through an ashx file. Unfortunately it just spits a bunch of gibberish at the top of the page and no image. Can this be done? Here is what I have so far:
$(document).ready
(
function ()
{
$("a[rel='cbImg']").colorbox();
}
);
...
<a rel="cbImg" href="HuntImage.ashx?id=15">Click to see image</a>
UPDATE:
My ashx file is writing the binary out:
context.Response.ContentType = "image/bmp";
context.Response.BinaryWrite(ba);
If I access session variable in ashx handler through it is always null. How can I access the current user here.
public void ProcessRequest (HttpContext context) {
context.Session[UIConstants.SessionItems.ID] = Id;
}
i have a ashx file
this file return string (plain/text)
i want ro read this from another page
Like:
http://www.domain.com/My-ashx.ashx?q=1 (This URL Return One Line Plain/Text)
i have another page: http://www.domain2.com/default.aspx ( I want write string(Return From ashx file))
THere is an external ASHX url that dinamically generates an XML file.
I tried to parse this XML using the doc.Load("http://www.domain.com.br/asp.net/integration.ashx") but it haven't worked.
The same code above work fine if I use a XML file instead of ashx one.
I need to read the XML file generated by the ASHX one in order to integrate the websites.
I have ASP.NET page with an iframe on it for displaying some pdf reports on this page. When user select the report type from dropdown, I add the needed for report data into the ASP.NET Session and change the attribute "src" of the iframe to .ashx module address which generates the .pdf report.But if Adobe glug-in for viewing .pdf files in browser is not installed, browser proposes to save report file and name of the proposed file is "HandlerName.ashx".But I want to make the browser proposed to save the file with the name "Report.pdf".
View 3 Replies