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

Mar 22, 2011

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:

~/asp/ClockState.aspx

into

/NextAllowed/asp/ClockState.aspx

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

Page.ResolveUrl("~/asp/ClockState.aspx")

which resolves to:

/NextAllowed/asp/ClockState.aspx

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

[Code]....



ADVERTISEMENT

Converting Virtual Path To Physical Path In A Handler?

Feb 14, 2010

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);

View 2 Replies View Related

Content Type When Serving A File In A Generic Handler?

Dec 10, 2010

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:

[code]....

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?

View 1 Replies View Related

C# - PlatformNotSupportedException When Saving A File From Silverlight Through A Generic Handler

Jul 30, 2010

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.Clear();
context.Response.AddHeader("content-disposition", "attachment; filename=Report.csv");
context.Response.ContentType = "text/csv";
context.Response.Write(_csvReport);
}

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

{System.Web.HttpResponse}
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.

View 2 Replies View Related

Web Forms :: Using Generic File Upload Handler For Uploading Files In C#?

Sep 21, 2009

Am trying to call upload handler on button click to upload the files.some how i don't see that it is working:

public
class Uploader : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string strResponse = "error";
try
{
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);
context.Request.Files[0].SaveAs(strSaveLocation);
strResponse =
"success";
}
catch
{
}
context.Response.ContentType =
"text/plain";
context.Response.Write(strResponse);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}

ASPX:

<asp:FileUpload
ID="FileUpload1"
runat="server"
/>
<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?

View 2 Replies View Related

C# - Can Get The Current Virtual Path Without File Name

Jun 20, 2010

Request.Path will get the current Path name with file name such as:

C:/......./Personal/Items.aspx

How can I get the only Path name such as:

C:/......./Personal

View 4 Replies View Related

MVC :: Using A Virtual Directory To Specify Uploaded File Path?

Mar 18, 2010

I created a virtual directory in the Visual Web Developer, according to this post:

[URL]

I want the user to upload / download documents in the mvc app to that virtual directory. When a document is uploaded, I'm specifying the path to the document to 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].

View 1 Replies View Related

Architecture :: Virtual Path Provider File Retrieval?

Nov 26, 2008

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

View 10 Replies View Related

C# - Load A Definition File At Application Start Located In A Virtual Path?

Jun 28, 2010

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.

View 2 Replies View Related

Web Forms :: Converting A Physical Path To Virtual Path And Vice Versa?

Oct 7, 2010

I have a code to open PDF file, like this

[Code]....

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

View 1 Replies View Related

Web Forms :: FileUpload - Getting An Error 'C:/WebSite/userimages/' Is A Physical Path But A Virtual Path Was Expected

Jul 3, 2010

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:

[Code]....

View 6 Replies View Related

Web Forms :: Convert A Virtual Path To A Physical Path?

Jan 30, 2010

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.

View 3 Replies View Related

Asp.Net Routing To A Generic Handler?

Sep 20, 2010

I Have a generic handler that's serving member logo images:

http://site.com/logo.ashx?memberid=123

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

http://site.com/logo/john.jpg

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.

View 1 Replies View Related

Handler And Generic Handler?

Mar 16, 2010

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.

View 1 Replies View Related

Looking For A Generic Handler / Service For Mongodb?

May 25, 2010

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 asp.net/c# 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.

View 3 Replies View Related

Get Image By Database By Generic Handler?

Jul 9, 2009

In my asp.net application, i want to display some data from database, every thing is fine but the image display.

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

the code is

[Code]....

View 3 Replies View Related

C# - Dynamic Image (from Db) Using Generic Handler

Feb 9, 2010

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;

[Code]....

View 1 Replies View Related

Ajax - .net Generic Handler Encoding ?

Sep 6, 2010

I'm sending values to Generic Handler via Ajax like that way.

xmlHttpReq.open("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?

View 2 Replies View Related

Secure Generic Handler Calls?

Jul 9, 2010

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.

View 2 Replies View Related

Web Forms :: Passing Parameter To Generic Handler

Aug 26, 2009

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.

[Code]....

View 9 Replies View Related

C# - Send Html Text To Generic Handler?

Mar 1, 2011

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:

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

[Code]....

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

View 1 Replies View Related

Session Not Working In Generic Handler .ashx In Firefox?

Apr 28, 2010

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.

View 1 Replies View Related

Serving An Image With A Generic Handler Within A List View. Is It Possible

Feb 27, 2011

Currently in my webpage i load images to the ListView object as follows...

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

[code]...

View 2 Replies View Related

Configuration :: Web Setup Does Not Install Generic Handler (ashx)

Jul 21, 2010

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?

View 1 Replies View Related

HttpHandlers / Modules :: Cannot Retrieve An Image Using A Generic Handler

Mar 26, 2010

I wrote a generic handler like this:

[Code]....

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.

View 2 Replies View Related

Web Forms :: Generic Handler Compilation Error VS 2005?

Feb 10, 2010

I have write a simple generic handler with 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

<compilation
debug="true"
strict="true"
explicit="true">

View 2 Replies View Related

HttpHandlers / Modules :: Access Particular ASPX Page From Generic Handler

Dec 2, 2008

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.

View 3 Replies View Related

HttpHandlers / Modules :: Redirect To Login Page From Generic Handler

Sep 8, 2010

I have created a asp.net generic handler to use it in auto-complete text box. Here is my code to it

/// <summary>

View 1 Replies View Related

Flash - Can't Get Session In Generic Handler (.ashx) When Using Firefox Or Chrome Except IE

Nov 5, 2010

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

View 2 Replies View Related

HttpHandlers / Modules :: Use Generic Handler To Call External Web Service?

Oct 28, 2010

I am tring to call external web service through generic handler ,post some example code for the call webservice from generic handler .

View 1 Replies View Related

How To Set A Generic Page Path

Apr 23, 2009

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.

View 2 Replies View Related

HttpHandlers / Modules :: Passing Parameters From Webpage To Generic Handler Page?

May 20, 2008

Q.how 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 variables sToolGUID 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 page receives 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.

[Code]....

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?

View 6 Replies View Related

How To Retrieve The Virtual Path

Dec 10, 2009

I'm testing my web app locally and I need to refer to the virtual path.

Code:

Protected Sub ddlEvent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlEvent.SelectedIndexChanged
Try
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) & """>" & _
"</a>"
pics.Add(html)
Next
dlPictures.DataSource = pics
dlPictures.DataBind()
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"

View 5 Replies View Related

Virtual Path Provider?

Jan 6, 2011

I am new to asp.net and trying to build a top level in asp.net. 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.

View 1 Replies View Related

How To Get Virtual Path Of Web.config

Mar 19, 2009

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 "~" .

View 12 Replies View Related

State Management :: Setting Session Values In Generic Handler And Accessing Them From A Page?

Jun 10, 2010

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?

View 1 Replies View Related

Web Forms :: Getting Virtual Path From Web Or Executable

Nov 5, 2009

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, and this functionality can 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:

[Code]....

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

View 4 Replies View Related

Virtual Directory In IIS To Physical Path

Mar 1, 2010

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.

View 10 Replies View Related

Web Forms :: How To Change The Virtual Path

Dec 15, 2009

I created a virtual directory under Default Web Site in IIS, this virtual directory alias "VD" and the local path of it is "C:\VDirectory".

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

But I see the virtual path of my application 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?

View 12 Replies View Related

MVC :: Relative Virtual Path Is Not Allowed Here?

Oct 29, 2010

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:

[Code]....

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 without a problem. They're created exactly the same way. Here's another:

[Code]....

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.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved