Monday, March 26, 2012
Server storing dynamically generated media files
hear what people think.
Here is the scenario:
I have this ASP.NET 2.0 page which allows user to enter some parameters
and then it dynamically generates a WAV or WMV file, depending on
preference. I want to send this back to the user via an <OBJECT> tag.
The way I am doing this right now is to assign the byte[] array to the
Session. Then, I generate an <OBJECT> tag (via an ASP literal control
added to a PlaceHolder control on the page) with the name being another
ASP Page (let's say MediaPlay.aspx).
In the Page load method of MediaPlay.aspx, I do something like this
(skip the error checking for clarity):
byte[] buffer = Session["MediaFile"];
Response.ContentType = Session["MediaContentType"];
Response.BinaryWrite(buffer);
Response.Flush();
Response.Close();
It seems to work, but I am wondering whether there is a better way to
do this. What do you think?
ACprobably not the best.
1) if you use inproc sessions, a large number of users may cause a recycle.
2) even if you use out of proc sessions, the wave file must be loaded on
every page hit after one is loaded.
3) if you clear the wave file from memory after download, a page referesh
will fail
you should store then in a temp storage (sql or disk), and run a cleanup job
that purges after session close.
-- bruce (sqlwork.com)
<andchoi@.gmail.com> wrote in message
news:1132674657.322499.113460@.g43g2000cwa.googlegroups.com...
>I am wondering whether this is the best way to do this. Would love to
> hear what people think.
> Here is the scenario:
> I have this ASP.NET 2.0 page which allows user to enter some parameters
> and then it dynamically generates a WAV or WMV file, depending on
> preference. I want to send this back to the user via an <OBJECT> tag.
> The way I am doing this right now is to assign the byte[] array to the
> Session. Then, I generate an <OBJECT> tag (via an ASP literal control
> added to a PlaceHolder control on the page) with the name being another
> ASP Page (let's say MediaPlay.aspx).
> In the Page load method of MediaPlay.aspx, I do something like this
> (skip the error checking for clarity):
> byte[] buffer = Session["MediaFile"];
> Response.ContentType = Session["MediaContentType"];
> Response.BinaryWrite(buffer);
> Response.Flush();
> Response.Close();
> It seems to work, but I am wondering whether there is a better way to
> do this. What do you think?
> --
> AC
>
Thursday, March 22, 2012
Server.HTMLEncode and performance
I'm dynamically loading an assembly into an ASP.NET application. In the
control that I load from that dynamic assembly I've tried to use
Server.HTMLEncode but this results in a serious performance loss. Is there
anyone who knows why or is there an alternative for server.htmlencode
method? Without the server.htmlencode the thingy works very fine.
greetz
MichaelThe HtmlEncode mathod will work as fast as the length of the string you are
encoding. If the string is short, it will be fast. If the string is long, it
will be slow.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Michael Gaillez" <michael.gaillez@.howest.be> wrote in message
news:uS0Z52fWEHA.3120@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I'm dynamically loading an assembly into an ASP.NET application. In the
> control that I load from that dynamic assembly I've tried to use
> Server.HTMLEncode but this results in a serious performance loss. Is there
> anyone who knows why or is there an alternative for server.htmlencode
> method? Without the server.htmlencode the thingy works very fine.
> greetz
> Michael
>
Ok that I can understand. But that is not the reason why I'm losing
performance in this application. If I'm doing exactly the same thing without
an dynamic assembly load it works pretty fast. If I use it with assembly
load it works very slow. So in my opinion the length doesn't really matter
in this case. But what I've found meanwhile is the httputility class were
the functionallity resides from. I will try that because then I don't have
to do this: "Page.Server...." . My guess is that this should do the trick
because reflection might not handle page.server very well.
greets
Michael
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:uIi7lwgWEHA.716@.TK2MSFTNGP11.phx.gbl...
> The HtmlEncode mathod will work as fast as the length of the string you
are
> encoding. If the string is short, it will be fast. If the string is long,
it
> will be slow.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "Michael Gaillez" <michael.gaillez@.howest.be> wrote in message
> news:uS0Z52fWEHA.3120@.TK2MSFTNGP12.phx.gbl...
there
>
The HttpUtility.HtmlEncode method will definitely work faster, as it is
static.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Michael Gaillez" <michael.gaillez@.howest.be> wrote in message
news:ez5bJ9gWEHA.1888@.TK2MSFTNGP11.phx.gbl...
> Ok that I can understand. But that is not the reason why I'm losing
> performance in this application. If I'm doing exactly the same thing
without
> an dynamic assembly load it works pretty fast. If I use it with assembly
> load it works very slow. So in my opinion the length doesn't really matter
> in this case. But what I've found meanwhile is the httputility class were
> the functionallity resides from. I will try that because then I don't have
> to do this: "Page.Server...." . My guess is that this should do the trick
> because reflection might not handle page.server very well.
> greets
> Michael
> "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> news:uIi7lwgWEHA.716@.TK2MSFTNGP11.phx.gbl...
> are
long,
> it
the
> there
>
Server.HTMLEncode and performance
I'm dynamically loading an assembly into an ASP.NET application. In the
control that I load from that dynamic assembly I've tried to use
Server.HTMLEncode but this results in a serious performance loss. Is there
anyone who knows why or is there an alternative for server.htmlencode
method? Without the server.htmlencode the thingy works very fine.
greetz
MichaelThe HtmlEncode mathod will work as fast as the length of the string you are
encoding. If the string is short, it will be fast. If the string is long, it
will be slow.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Michael Gaillez" <michael.gaillez@.howest.be> wrote in message
news:uS0Z52fWEHA.3120@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I'm dynamically loading an assembly into an ASP.NET application. In the
> control that I load from that dynamic assembly I've tried to use
> Server.HTMLEncode but this results in a serious performance loss. Is there
> anyone who knows why or is there an alternative for server.htmlencode
> method? Without the server.htmlencode the thingy works very fine.
> greetz
> Michael
Ok that I can understand. But that is not the reason why I'm losing
performance in this application. If I'm doing exactly the same thing without
an dynamic assembly load it works pretty fast. If I use it with assembly
load it works very slow. So in my opinion the length doesn't really matter
in this case. But what I've found meanwhile is the httputility class were
the functionallity resides from. I will try that because then I don't have
to do this: "Page.Server...." . My guess is that this should do the trick
because reflection might not handle page.server very well.
greets
Michael
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:uIi7lwgWEHA.716@.TK2MSFTNGP11.phx.gbl...
> The HtmlEncode mathod will work as fast as the length of the string you
are
> encoding. If the string is short, it will be fast. If the string is long,
it
> will be slow.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
> "Michael Gaillez" <michael.gaillez@.howest.be> wrote in message
> news:uS0Z52fWEHA.3120@.TK2MSFTNGP12.phx.gbl...
> > Hi,
> > I'm dynamically loading an assembly into an ASP.NET application. In the
> > control that I load from that dynamic assembly I've tried to use
> > Server.HTMLEncode but this results in a serious performance loss. Is
there
> > anyone who knows why or is there an alternative for server.htmlencode
> > method? Without the server.htmlencode the thingy works very fine.
> > greetz
> > Michael
The HttpUtility.HtmlEncode method will definitely work faster, as it is
static.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Michael Gaillez" <michael.gaillez@.howest.be> wrote in message
news:ez5bJ9gWEHA.1888@.TK2MSFTNGP11.phx.gbl...
> Ok that I can understand. But that is not the reason why I'm losing
> performance in this application. If I'm doing exactly the same thing
without
> an dynamic assembly load it works pretty fast. If I use it with assembly
> load it works very slow. So in my opinion the length doesn't really matter
> in this case. But what I've found meanwhile is the httputility class were
> the functionallity resides from. I will try that because then I don't have
> to do this: "Page.Server...." . My guess is that this should do the trick
> because reflection might not handle page.server very well.
> greets
> Michael
> "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> news:uIi7lwgWEHA.716@.TK2MSFTNGP11.phx.gbl...
> > The HtmlEncode mathod will work as fast as the length of the string you
> are
> > encoding. If the string is short, it will be fast. If the string is
long,
> it
> > will be slow.
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > Big things are made up
> > of lots of little things.
> > "Michael Gaillez" <michael.gaillez@.howest.be> wrote in message
> > news:uS0Z52fWEHA.3120@.TK2MSFTNGP12.phx.gbl...
> > > Hi,
> > > > I'm dynamically loading an assembly into an ASP.NET application. In
the
> > > control that I load from that dynamic assembly I've tried to use
> > > Server.HTMLEncode but this results in a serious performance loss. Is
> there
> > > anyone who knows why or is there an alternative for server.htmlencode
> > > method? Without the server.htmlencode the thingy works very fine.
> > > > greetz
> > > > Michael
> >