Tracking Forums, Newsgroups, Maling Lists
Home Submit Tracker Forums
  Advanced Search


How To Get The Virtual Path Of A File From A Generic Handler

How can i resolve a virtual path to a file into a path, suitable for the browser, from within a generic .ashx handler?

e.g. i want to convert:




If i were a WebForm Page, i could call ResolveUrl:


which resolves to:


But i'm not a WebForm Page, i'm a generic handler. You know, that IHttpHandler object with all kinds of things injected:


View 1 Replies (Posted: Mar 22 at 3:27)

Sponsored Links:

Related Forum Messages For ASP.NET category:
Converting Virtual Path To Physical Path In A Handler?
I am trying to convert the virtual path to a physical path but don't seem to have Server.MapPath or HttpServerUtility.MapPath available in my handler. I add the System.Web namespace with no luck.

string virtualTargetFolder = String.Format("~/UserImages/{0}/Images/", user.ProviderUserKey.ToString());
string physicalTargetFolder = System.Web.HttpServerUtility.MapPath (virtualTargetFolder);

Posted: Feb 14, 2010 08:56 PM

View 2 Replies!   View Related
Content Type When Serving A File In A Generic Handler?
I'm busy writing a handler to serve various documents for download or presentation in web forms pages. The documents range from various image formats, to PDF, to MS Office documents, to generic binaries. My basic draft of the download process is as below:


However, I have some misgivings about lumping all documents together as application/octet-stream, and I would prefer, if feasible, to use a more specific content type per document type. I have a DB table for document types where I could store this. Am I going in the right direction, and if so, where can I find a suitable starting list of content types for document types?

Posted: Dec 10 10 at 5:15

View 1 Replies!   View Related
C# - PlatformNotSupportedException When Saving A File From Silverlight Through A Generic Handler
I have a Silverlight application hosted in an ASP.NET site, through which I'm starting an HttpWebRequest to a Generic Handler in order to save a CSV file to the user's machine.

From the Silverlight app, a Uri is constructed with parameters to make the CSV file server-side. A button is clicked which triggers the following:

string httpHandlerName = "HttpDownloadHandler.ashx";
// CustomUri handles making it an absolute Uri wherever we move the handler.
string uploadUrl = new CustomUri(httpHandlerName).ToString();
UriBuilder httpHandlerUrlBuilder = new UriBuilder(uploadUrl);
httpHandlerUrlBuilder.Query = string.Format("{3}startdate={0}&enddate={1}&partnerId={2}", startDate, endDate, partnerId, string.IsNullOrEmpty(httpHandlerUrlBuilder.Query) ? "" : httpHandlerUrlBuilder.Query.Remove(0, 1) + "&");
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(httpHandlerUrlBuilder.Uri);
webRequest.Method = "POST";
webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);

Now here is the ProcessRequest code from the HttpDownloadHandler.ashx

public void ProcessRequest(HttpContext context)
_httpContext = context;
string partnerId = _httpContext.Request.QueryString["partnerId"];
string startDate = _httpContext.Request.QueryString["startDate"];
string endDate = _httpContext.Request.QueryString["endDate"];
ExportCsvReport exportCsv = new ExportCsvReport();
_csvReport = exportCsv.ExportMemberRegistrationReport(partnerId, startDate, endDate);
context.Response.AddHeader("content-disposition", "attachment; filename=Report.csv");
context.Response.ContentType = "text/csv";

Here is the HttpResponse header information that comes back when the Save File Dialogue refuses to appear:

Buffer: true
BufferOutput: true
Cache: {System.Web.HttpCachePolicy}
CacheControl: "private"
Charset: "utf-8"
ContentEncoding: {System.Text.UTF8Encoding}
ContentType: "text/csv"
Cookies: {System.Web.HttpCookieCollection}
Expires: 0
ExpiresAbsolute: {1/1/0001 12:00:00 AM}
Filter: {System.Web.HttpResponseStreamFilterSink}
HeaderEncoding: {System.Text.UTF8Encoding}
Headers: 'context.Response.Headers' threw an exception of type 'System.PlatformNotSupportedException'
IsClientConnected: true
IsRequestBeingRedirected: false
Output: {System.Web.HttpWriter}
OutputStream: {System.Web.HttpResponseStream}
RedirectLocation: null
Status: "200 OK"
StatusCode: 200
StatusDescription: "OK"
SubStatusCode: 'context.Response.SubStatusCode' threw an exception of type 'System.PlatformNotSupportedException'
SuppressContent: false
TrySkipIisCustomErrors: false

When I navigate to localhost/HttpDownloadHandler.ashx while the site is up, without initiating it from within the Silverlight app - the Save File Dialogue appears just fine, it seems to be a case where Silverlight is not accepting the response header properly.

Posted: Jul 30 10 at 20:51

View 2 Replies!   View Related
Web Forms :: Using Generic File Upload Handler For Uploading Files In C#?
Am trying to call upload handler on button click to upload the files.some how i don't see that it is working:

class Uploader : IHttpHandler
public void ProcessRequest(HttpContext context)
string strResponse = "error";
string strFileName = context.Request.QueryString["fileName"];
string strFilePath= context.Request.QueryString["filePath"];
//string strExtension = Path.GetExtension(context.Request.Files[0].FileName).ToLower();
string strSaveLocation = context.Server.MapPath( strFilePath);
strResponse =
context.Response.ContentType =
public bool IsReusable
return false;


<asp:Button ID="btnUpload" runat="server" CssClass="button" Text="Upload" OnLoad="btnUpload_Load" />
protected void btnUpload_Load(object sender, EventArgs e)
string strFilePath=System.IO.Path.GetFullPath (FileUpLoad1.FileName);
(sender as Button).OnClientClick = "Uploader.ashx?fileName=" + FileUpLoad1.FileName + "&filePath=" + strFilePath;

Will that still cause postback when button is clicked?

Posted: Sep 21, 2009 03:05 PM

View 2 Replies!   View Related
C# - Can Get The Current Virtual Path Without File Name
Request.Path will get the current Path name with file name such as:


How can I get the only Path name such as:


Posted: Jun 20 10 at 12:09

View 4 Replies!   View Related
MVC :: Using A Virtual Directory To Specify Uploaded File Path?
I created a virtual directoryin the Visual Web Developer, according to this post:


I want the userto upload / download documents in the mvcappto that virtual directory.When a document is uploaded, I'm specifying the path to the documentto be stored for later retrieval like so:

~/VirtualDirectoryName/FileContent.docx. But when I try to open that as a link in th app,using ResolveUrl, it appends the port number after localhost like so,[URL],I get a document not found, since it really should be, [URL].

Posted: Mar 18, 2010 12:52 AM

View 1 Replies!   View Related
Architecture :: Virtual Path Provider File Retrieval?
We have developed a Virtual Path Provider and a custom cachedependency for our aspx pages. Everything seems to be working just fine since we serve and invalidate aspx pages. The issue is that some machines retrieve a fresh copy of the form on first request while others reuse a previously cached copy. To make it more clear:Assume the IIS Temporary Files folder is empty

Posted: Nov 26, 2008 03:33 PM

View 10 Replies!   View Related
C# - Load A Definition File At Application Start Located In A Virtual Path?
How do I load a definition file which contains some start up logic at Application_Start?

I only know the virtual path but not the server physical path. How do I convert the virtual path to server path without Server.MapPath()

I am not sure I can access httpcontext or not in the application start stage.

Posted: Jun 28 10 at 8:16

View 2 Replies!   View Related
Web Forms :: Converting A Physical Path To Virtual Path And Vice Versa?
I have a code to open PDF file, like this


Over here I have created a folder with name Data inside my solution, so the Server.Mappath("Data") as well the statemet for converting assigning the src property of the IFrame I1 is working properly. But I want to use the files from a folder which resides in a network folder like

Posted: Oct 07, 2010 05:56 AM

View 1 Replies!   View Related
Web Forms :: FileUpload - Getting An Error 'C:/WebSite/userimages/' Is A Physical Path But A Virtual Path Was Expected
I am trying to upload a file Into a MapPath but I am getting a error 'C:/WebSite/userimages/' is a physical path, but a virtual path was expected. My code is:


Posted: Jul 03, 2010 04:29 AM

View 6 Replies!   View Related
Web Forms :: Convert A Virtual Path To A Physical Path?
the syntax to convert a virtual path to a physical path.

I wanted to upload a file located in one server and i know only the website name.

Posted: Jan 30, 2010 06:39 AM

View 3 Replies!   View Related
Asp.Net Routing To A Generic Handler?
I Have a generic handler that's serving member logo images:

Now, I want to use it by caling a url like:

So I would create a route for that (pattern: "logo/{username}.jpg"). But, my problem is - how do I retrieve {username} when inside ProcessRequest() of my generic handler? It's not a page, so I can't get Page.RouteData.Values.

Posted: Sep 20 10 at 20:55

View 1 Replies!   View Related
Handler And Generic Handler?
In Visual Studio 2010, when you say new Item, you can see Asp.NET Handler and Generic Handler. Can you tell me what's the difference, I think it came with .NET 4.0 because I couldn't find related thins on Google.

Posted: Mar 16 10 at 3:08

View 1 Replies!   View Related
Looking For A Generic Handler / Service For Mongodb?
I am new to MongoDB and have a perfect place in mind to use it. However, it's only worth it if I can make the queries from JavaScript and return JSON.

What's the easiest way I can implement a generic service/handler in that would allow me to interact with mongodb via JavaScript? I understand JavaScript can't call mongodb directly, so the next best thing is what I'm looking for.

Posted: May 25 10 at 2:43

View 3 Replies!   View Related
Get Image By Database By Generic Handler?
In my application, i want to displaysome data from database, every thing is fine but the image display.

i have used a generic handler "DisplayImg.ashx" file ingrid view for imageurl

the code is


Posted: Jul 09, 2009 11:31 AM

View 3 Replies!   View Related
C# - Dynamic Image (from Db) Using Generic Handler
I'm trying to using a Generic Handler to retrieve and display images that are stored in a database.

But its just not working. Ive tried verious of the code below, but I cant seem to get it to work.

<%@ WebHandler Language="C#" Class="IconsDb" %>
using System;
using System.Web;
using System.Linq;
using System.Data.Entity;


Posted: Feb 9 10 at 17:57

View 1 Replies!   View Related
Ajax - .net Generic Handler Encoding ?
I'm sending values to Generic Handler via Ajax like that way."GET", "AddMessage.ashx?" + (new Date().getTime()) +"&Message=" + Message,true);

when message contains they are looking like that on Handler in context.Request. these characters are looking as it should. But in context.Request.Url they are looking like and when i want QueryString values it gives me what can i do?

Posted: Sep 6 10 at 18:22

View 2 Replies!   View Related
Secure Generic Handler Calls?
I am creating a myspace application and for some database entries I am using generic handlers which I have hosted on another website. From my myspace application I use ajax calls to those handlers to perform the activities that I want. I want to know how can I make these ajax calls secure? I mean I want to be sure that the handlers are being called by only the myspace app and not by entering url into the browser etc.

Posted: Jul 9 10 at 10:30

View 2 Replies!   View Related
Web Forms :: Passing Parameter To Generic Handler
I would like to pass a url string parameter into a generic hanler (.ashx). I have been googleing for days with no luck. Here is my handler.


Posted: Aug 26, 2009 07:53 PM

View 9 Replies!   View Related
C# - Send Html Text To Generic Handler?
I have a WYSIWYG editor on one of my forms and I want to send the contents of the editor to an ASP.NET generic handler for processing via an Ajax call.

I am having a little bit of trouble parsing the html received.

Client Side:

$('.send').bind('click', function(event){
var message = $('#TxtMessage').htmlarea('toHtmlString');
message = escape(message);


So the problem is that even when I call Server.HtmlDecode(string) the message is garbled.

Posted: Mar 1 at 16:41

View 1 Replies!   View Related
Session Not Working In Generic Handler .ashx In Firefox?
I have created .ashx which implemented IRequiresSessionState, so I can create session variables in that ashx, it worked in IE, but doesn't work in Firefox.When access this session variable from other pages it's NULL.

Posted: Apr 28 10 at 13:29

View 1 Replies!   View Related
Serving An Image With A Generic Handler Within A List View. Is It Possible
Currently in my webpage i load images to the ListView object as follows...

<asp:ListView ID="ListView1" runat="server">


Posted: Feb 27 at 7:43

View 2 Replies!   View Related
Configuration :: Web Setup Does Not Install Generic Handler (ashx)
I've created a Web application (VS2008) that contains a single Generic Handler (handlername.ashx) and a web.config. I've also added a Web Setup project to use for deployment that uses the primary output from the Handler project. Install works without any errors and all the referenced DLLs are installed in the target location, with one issue. It doesn't install the ASHX file or the web.config.

Publishing the web app to the target location works as expected (includes both DLLs and the ASHX/Config files).

Is there something specific I need to do for the Web setup to include the ASHX/Config files?

Posted: Jul 21, 2010 03:05 PM

View 1 Replies!   View Related
HttpHandlers / Modules :: Cannot Retrieve An Image Using A Generic Handler
I wrote a generic handler like this:


and on the other page I would like to retrieve the database image using :

<img alt="" src="ShowImage.ashx?ID=467711" />

but I am getting nothing in this case. The picture exists and there are 91000 bytes in array.

Posted: Mar 26, 2010 08:02 AM

View 2 Replies!   View Related
Web Forms :: Generic Handler Compilation Error VS 2005?
Ihave write a simple generic handlerwith VB as the language.

I am then trying to access the static properties of the handler via an aspx page using <%= handlerclassname.propname %> code.

However it is failing to compile. The compiler throws an error Name HandlerClassname is not declared.

I have checked in my code about namespace or something like that, but there aren't any.

Compilation option in web.config is


Posted: Feb 10, 2010 10:22 PM

View 2 Replies!   View Related
HttpHandlers / Modules :: Access Particular ASPX Page From Generic Handler
I was wondering how to get access to a particular page class from Generic Handler (.ashx). My purpose is to access Default.aspx from the generic handler, create server controls dynamically and then add them to the controls collection. I have thus far been unable to do this. Can someone point me in the right direction? Basically, I have two requirements

i) How to access a certain page class from generic http handler? For example, how can i reference default.aspx and deault.aspx.vb from my ashx?
ii) How to add controls to any form from within the ashx file? I am not looking for the html32textwriter and response.write combinations? I wanted to output controls dynamically like we can in code behind pages like:

form1.controls.add(new hyperlink())

Now, in the above, how to get access to this FORM1? To put things into perspective, here is what I am trying to do:

I have an ashx file that would create controls dynamically based on the querystring parameter in Default.aspx. So, for example, the requested url is default.aspx?op=create. The ashx handler would read the op querystring and create controls for the create operation.

Posted: Dec 02, 2008 04:37 AM

View 3 Replies!   View Related
HttpHandlers / Modules :: Redirect To Login Page From Generic Handler
I have created a generic handler to use it inauto-completetext box. Here is my code to it

/// <summary>

Posted: Sep 08, 2010 05:00 PM

View 1 Replies!   View Related
Flash - Can't Get Session In Generic Handler (.ashx) When Using Firefox Or Chrome Except IE
im now using FancyUpload (flash upload) to allow user to upload files in a small project. I use Generic Handler to handler in server when user uploads his file, but i'm getting error: Can't get session in Generic Handler (.ashx) when using Firefox or Chrome etc except IE I read so many solution and finally found out that Flash has some bug that can't send cookie in Firefox or Chrome except IE, Maybe i can check the session in Flash before it's start to send the file to the server or check session in Generic Handler before save it

Posted: Nov 5 10 at 3:22

View 2 Replies!   View Related
HttpHandlers / Modules :: Use Generic Handler To Call External Web Service?
I amtring to call external web servicethrough generic handler ,post some example code for the call webservice fromgeneric handler.

Posted: Oct 28, 2010 11:21 AM

View 1 Replies!   View Related
How To Set A Generic Page Path
I have a file on location C:/sample/Css/easy.css

Now, in HTML code, I need to use the CSS file, but I dont want to enter the enter directory details etc.

I want some thing like href="../../easy.css". Obviously this one does not work.

Do anyone know why this doesnt work or have your sugesstion.

Posted: Apr 23, 2009 12:01 PM

View 2 Replies!   View Related
HttpHandlers / Modules :: Passing Parameters From Webpage To Generic Handler Page? to pass parameters from webpage to Generic Handler page and how to receive them

1. When the user clicks a button I want to pass 2 parameters to the 'ViewImage' page. The code below passes just 1 parameter (concatenates the variablessToolGUID and lGrid). Can I split the parameters up or do I have to split them up in the 'ViewImage' page?[Code]....

2.The code below in the 'ViewImage' generic handler pagereceives 2 parameters from the webpage(if I can send 2 parameters). But how would i use the string instead of the index (querystring["..."]). It looks like I can only use the string querystring["id"] to retrieve the parameter.


I get the impression I can only send 1 parameter then use the split function to seperate the querystring but surely there is a way to send 2 parameters and why do I have to use an index?

Posted: May 20, 2008 10:59 AM

View 6 Replies!   View Related
How To Retrieve The Virtual Path
I'm testing my web app locally and I need to refer to the virtual path.


Protected Sub ddlEvent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlEvent.SelectedIndexChanged
If ddlEvent.Text.Length > 0 Then
ImageDir = "C:WebsitesPF" & ddlEvent.SelectedItem.Text & ""
Dim pics As ArrayList = New ArrayList()
Dim s As String, html As String
For Each s In Directory.GetFiles(Server.MapPath(ImageDir), "*.jpg")
html = "<a href=""" & ImageDir & Path.GetFileName(s) & """>" & _
"<img src=""" & ImageDir & Path.GetFileName(s) & """>" & _
dlPictures.DataSource = pics
End If
Catch ex As Exception
mmp.errorLabel.Text = ex.Message
End Try
End Sub

For some reason it doesn't like the highlighted line of code even though it is a valid path. When I run the app, I get the error message:

"C:WebsitesPFTestImages is not a valid virtual path"

Posted: Dec 10th, 2009, 02:01 PM

View 5 Replies!   View Related
Virtual Path Provider?
I am new to and trying to build a top level in Actually i want to save .aspx pages in sql server database and excute directly from the database. I search a lot and come to know about VirtualPathprovider class. It is helpful in building cms like what i want but the problem is that i am quite unable to understand the use of this class.

Posted: Jan 06, 2011 01:11 PM

View 1 Replies!   View Related
How To Get Virtual Path Of Web.config
This code is running absolutely fine In my local .

This .cs file is in the my application APP_code folder

// Get the Web application configuration.
Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");

but when i host this site on my shared hosting , it shows the error . as i think i need to change this tilde sign.

because in my shared hosting account i m not allowed to go beyond my application folder .so when i write this sign ~ it goes to the server root folder which i am not allowed , so i need to get the virtual path of my application project only.

what piece of code should be written here in place of "~" .

Posted: Mar 19, 2009 07:33 PM

View 12 Replies!   View Related
State Management :: Setting Session Values In Generic Handler And Accessing Them From A Page?
I have a generic handler in which I fill up a Session variable. I implemented the IRequiresSessionState interface, so it shouldn't be a problem.

In a given page, I want to display that value, but it seems like the value is always empty. Is it because the session that is accessed and written to in the handler isn't the same one that is used on this page?

In the handler, I used context.Session["EID"] = "somevalue";

edit: i found out what the issue is but I do not know how to solve it. It's because I have this Java applet which reads out an eID, calls the handler to store the data, but the session used by the applet is not the same as the session used by the browser... so how could I exchange this data in a safe way?

Posted: Jun 10, 2010 12:31 PM

View 1 Replies!   View Related
Web Forms :: Getting Virtual Path From Web Or Executable
I have a web applicaiton that must be able to retrieve the values from an XML config file. That's not a problem. The problem is that this config file has the values that power an FTP module of my application, and that must be periodically kicked off to automatically download new files from a remote FTP server. I have all of this working. A Windows Scheduled Task kicks off an executable file that calls code kept in the web application's classes, andthis functionalitycan be manually started from the web app as well.

The problem is the location of the config file. There are several Projects in the Solution, and the Console application that the Windows Scheduled Task kicks off is just one of them. Since I can't rely on HttpContent.Current.Server.MapPath when I'm coming in from the side of an executable Console app, how do I get the path to the config file without hard-coding an absolute path or creating multiple copies of it for each application module to access? Say the config.xml file is in the root of the Web application. I can easily snag it by using:


But how do I reference the same location from a Console app in another Project of the same Solution?

Posted: Nov 05, 2009 05:40 PM

View 4 Replies!   View Related
Virtual Directory In IIS To Physical Path
My basic question is, can a virtual directory in IIS point to a physical path that's not on the local machine? For instance, right now I have a virtual path /NaturalGasReport/NYMEX which points to physical path C:Program Files (x86)NymexSettleNATGAS_REPORTNYMEX, but I want it to point to a physical path on a difference PC on the same network. Is this possible? (I know I can just try it out so I apologize for asking but I thought it would be best to get an explanation along with "yes" or "no"). If you want more detail, this is what I need to do. To make a long story short, because of a vendor product we are using that won't run on a 64-bit operating system, I have to run a program called Generate_NGReportData.vbs (it's a vbscript program) on a PC I will call 28. It uses a vendor product which produces jpg files which are graphs of the Natural Gas market. The machine where I wish it could run is called RTEST01 but this machine runs a 64-bit OS and the components won't work there. RTEST01 has the databases. So, I created a datasource on 28 which points to RTEST01's database. The vbs program will read the data, generate the reports, and write one row to a database table on RTEST01. RTEST01 has to run the complimentary program which sends these reports (via email). 28 is not an email server so it can't email the reports. So on RTEST01 I will run Send_NaturalGasReport.vbs. This program creates an email body of html. The html references [URL]NaturalGasReport/NYMEX/" & Day(nymex_update_dt) & ".jpg which is a virtual directory pointing to C:Program Files (x86)NymexSettleNATGAS_REPORTNYMEX. I need it to point to the folder and files on 28.So if my initial question has a simple yes answer then I am all set. If not, examine my architecture and propose an alternative solution.

Posted: Mar 1st, 2010, 09:27 AM

View 10 Replies!   View Related
Web Forms :: How To Change The Virtual Path
I created a virtual directory under Default Web Site in IIS,this virtual directoryalias "VD" and the local path of it is "C:\VDirectory".

I wish touse "VD" to store files through my application.

But I see the virtual path of myapplication is/DW/APP.

When my codes runs MapPath(@"~/VDirectory/123.jpg"), the MapPath returns "C:CodeVPAFDWAPPVDirectory123.jpg".

There is no physical VDirectory folder in DWAPP, so when my codes wants to create a new folder in it, it is denied(DWAPP are not allowed writing).

how to make my application to access the VD virtual directory?

Posted: Dec 15, 2009 04:12 PM

View 12 Replies!   View Related
MVC :: Relative Virtual Path Is Not Allowed Here?
OK, I've seen a lot of ambiguous errors, but this was is in the top 20 or so. I have a RenderPartial that looks like this:


When the view loads, I get this error:

The relative virtual path '~Areas/User/Views/Shared/ProjectStats.ascx' is not allowed here. That really helps. Why isn't it allowed there? What's wrong with it? Just above it I have other PartialRender calls that work withouta problem. They're created exactly the same way. Here's another:


This works fine. I thought maybe it was due to accessing a view from another Area, but I added a partial view to that Area's folder and it still didn't work.

Posted: Oct 29, 2010 07:34 PM

View 3 Replies!   View Related
Copyright 2005-08, All rights reserved