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
Similar Messages:
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
Nov 25, 2010
I'm trying to create a control out of a class I found, and one of the overridden functions is the following:
protected override void PerformDataBinding(IEnumerable data)
However, when I try to build the control I'm getting the error as shown in the subject. I've tried searching, and it seems the signature for the original function matches the one I have, and all other solutions I've seen uses the same signature.
View 3 Replies
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]....
View 1 Replies
May 26, 2013
I want to download any type of file on button click,so have created a .ashx page and redirected the .aspx page to the .ashx page.Is this way correct to do the task.Below mentioned code works fine.
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
var fileName = "Tracing.pdf";
[Code] ....
View 1 Replies
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
Oct 7, 2010
I have a scenario where...
1.) Have created a div with a dropdown list and ok, cancel button
2.) On document ready - registering div created on step 1 into a jQuery dialog
3.) on a javascript button click - I am opening this dialog box.
4.) Now, the problem is - the jQuery dialogbox which I have created, needs to be used by other button clicks as well on same page. Now, my div's (which is a dialog at runtime using jQuery) ok button click is already engaged with a javascript function (button1 click) and I can not associate other button's click events with it - thus stuck up here and have no clues or hit to resolve this.
View 2 Replies
Mar 18, 2013
I need displaying my image file stored from my database into the image control. I've had read some articles and watch video tutorial which there were perfectly working and I followed it but I wasn't able to make it work. The image control just displayed blank. I used Generic Handler to retrieve the image file from my database based on the articles and tutorials I've got. here are my codes below:
Generic Handler:
Code:
<%@ WebHandler Language="C#" Class="ShowImage" %>
using System;
using System.Configuration;
using System.Drawing;
using System.Drawing.Imaging;
[Code] ....
Asp.Net Code for the Image control:
HTML Code:
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "ShowImage.ashx?ID=" + Eval("ID") %>' Height="128px" />
View 3 Replies
Apr 17, 2010
I would like to lock down a web server that is only serving MVC content. What is the best way minimize my server's attack surface?
View 2 Replies
Feb 4, 2010
got a Asset Management tool which stores (in a folder("node")) an index.htm and a bunch of other asset files such as .js, .css, flv, etcHere's the problem...if I access the index.htm I get ti via it's nodeID http://site/NODEGUID/index.htm , and all compound files try and download via that GUID as well so essientially I just get index.htm content served into each request file, thus giving me an epic fail :)Is there some way in asp.net to intercept that request so I can do a lookup on the DAM and get the proper file reference and send that down instead?
View 3 Replies
May 7, 2010
I'm getting this message when going to a web app that accesses my service.
"The content type text/html of the response message does not match the content type of the binding (text/xml; charset=utf-8)..."
The thing is, it happens once in a while even when no changes have been made to the service or the web app. And I can make it go away most of the time by going directly to the .svc?wsdl page in my browser and then coming back to the web app.
View 2 Replies
Feb 24, 2011
I have a domain which is receiving quite a few hits per day and have been asked if I can serve the static content from a subdomain. As the site is quite extensive and already written, I was wondering if there is any way I can use URL rewriting to change:
www.example.com/image.gif
to
static.example.com/image.gif
I have a solution which works using 301 redirects but from what I understand, this is counter productive as 2 requests will have to be made per image. I don't really want to go through all the aspx pages and css to hard code the new url as it will cause problems further down the line - some parts of the site are still being developed and static content could change at any time. I tried using rewrite (as opposed to redirect) to change the url but it came out something like:
http://www.example.com/http://static.example.com/image.gif
How would you achieve this? I have full access to dns and the server (win 2008r2 / IIS 7.5) so can make any changes if url rewriting is not the answer.
View 1 Replies
May 20, 2010
I would like to use HTML input file type in my aspx page to allow user to browse for a excel file and then read the content of the excel sheet programmatically.If I want to read the excel sheet I need the full path of the file to connect to the excel sheet using asp.net.I do not understand how can I get the full path of the file.I know I can get the filename using postedFile.FileName property.But I need the full path of the file.
View 2 Replies
Mar 5, 2011
I'm trying to create a validation layer that will contain methods to validate all my objects (in my Business Objects layer) .. but when I try to reference both the validation and business objects to each other I get a circular dependency error .. so I've decided to create a new layer (BLL) to validate the objects for me and I'll be able to reference both the validation and the object layers.
so I want to build some kind of class/interface -I don't know what fits more- to be like a generic type or a parent type that my method could accept it as a parameter and check for it's Name/ID property. Instead of defining a new method overload for each object type I have
Simplification
View 1 Replies
Jan 6, 2011
I have a simple upload page using the html file element. I choose a .pdf file to upload and when I inspect the Content type of the file when it goes to server the value is "application/msword" instead of "application/pdf"
View 1 Replies
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
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
Jul 22, 2013
When inserting a binary file do you know what will be the correct content type for extensions like .txt or .gif or others not in your sample? Is there a list of correct content types?
View 1 Replies
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
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
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
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
May 7, 2015
i want to access session value after login ..temrory procedure i knw but i heard about ashx file to manage session so what is the method to use it?
View 1 Replies
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
Jun 16, 2015
I need to provide the json string as response to the request made using webrequst as : [URL] ....
Above request will come from other application using webrequest ...
How to implement the page(aspnet.aspx) which handles the request and gives the json string as response. I know how to made webrequest. I am struggling at server end. How to receive request and give response as json string.
View 1 Replies