Asked  7 Months ago    Answers:  5   Viewed   41 times

What are the differences between

Response.AddHeader("Content-Disposition", "attachment;filename=somefile.ext")


Response.AddHeader("Content-Disposition", "inline;filename=somefile.ext")

I don't know the differences , because when I use one or another I always get a window prompt asking me to download the file for both of them. I read the specs, but it is clueless.



Because when I use one or another I get a window prompt asking me to download the file for both of them.

This behavior depends on the browser and the file you are trying to serve. With inline, the browser will try to open the file within the browser.

For example, if you have a PDF file and Firefox/Adobe Reader, an inline disposition will open the PDF within Firefox, whereas attachment will force it to download.

If you're serving a .ZIP file, browsers won't be able to display it inline, so for inline and attachment dispositions, the file will be downloaded.

Tuesday, June 1, 2021
answered 7 Months ago

Those are two completely different things:

An Activity is an application component that provides a screen, with which users can interact in order to do something. More details:

Whereas a Fragment represents a behavior or a portion of user interface in an Activity.

Thursday, June 3, 2021
answered 7 Months ago

Let me bump a little internals on you:

public static HttpContext Current
    get { return ContextBase.Current as HttpContext; }
    set { ContextBase.Current = value; }

internal class ContextBase
    internal static object Current
        get { return CallContext.HostContext; }
        set { CallContext.HostContext = value; }

public static object HostContext
        var executionContextReader = Thread.CurrentThread.GetExecutionContextReader();
        object hostContext = executionContextReader.IllogicalCallContext.HostContext;
        if (hostContext == null)
            hostContext = executionContextReader.LogicalCallContext.HostContext;
        return hostContext;
        var mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();
        if (value is ILogicalThreadAffinative)
            mutableExecutionContext.IllogicalCallContext.HostContext = null;
            mutableExecutionContext.LogicalCallContext.HostContext = value;
        mutableExecutionContext.IllogicalCallContext.HostContext = value;
        mutableExecutionContext.LogicalCallContext.HostContext = null;


var context = HttpContext.Current;

is equal to (pseudocode)

var context = CurrentThread.HttpContext;

and inside your Task.Run something like this happens

CurrentThread.HttpContext= context;

Task.Run will start new task with thread from thread pool. So you're telling that your new thread "HttpContext property" is reference to starter thread "HttpContext property" - so far so good (well with all the NullReference/Dispose exceptions you'll be facing after your starter thread finishes). Problem is if inside your

//Other long running code here.

You have statement like

var foo = await Bar();

Once you hit await, your current thread is returned to thread pool, and after IO finishes you grab new thread from thread pool - wonder what its "HttpContext property" is, right ? I don't know :) Most probably you'll end with NullReferenceException.

Wednesday, August 11, 2021
answered 4 Months ago

From Nikita Salnikov-Tarnovski's blog:

The shallow heap is easy – it consists of only the heap occupied by the object itself. There are some nuances to how to calculate it, but for the scope of this article we leave it as is. Stay tuned for future posts on the same topic.

The retained heap is in many ways more interesting. Only rarely are you interested in the shallow heap, in most cases your actual question can be translated to “If I remove this object from the memory, how much memory can now be freed by the garbage collector”.

Now, as we all remember, all Java garbage collection (GC) algorithms follow this logic:

1)There are some objects which are considered “important” by the GC. These are called GC roots and are (almost) never discarded. They are, for example, currently executing method’s local variables and input parameters, application threads, references from native code and similar “global” objects.

2)Any objects referenced from those GC roots are assumed to be in use and hence not discarded by the GC. One object can reference another in different ways in Java, in the most common case an object A is stored in a field of an object B. In such case we say “B references A”.

3)The process is repeated until all objects that can be transitively reached from GC roots are visited and marked as “in use”.

4)Everything else is unused and can be thrown away.

Saturday, September 18, 2021
answered 3 Months ago

If the server you are logging in to uses cookie based authentication then you must create a System.Net.CookieContainer where you store the authentication cookie. This is quite simple:

CookieContainer container = new CookieContainer();

// Create web request
request.CookieContainer = container;

// Create next web request
nextRequest.CookieContainer = container;

// And so on

Just reuse the CookieContainer object for all your HttpWebRequest objects, and keep it in memory for later use.

The CookieContainer is Serializable, so you can persist it on disk if you need to. That will allow you to keep your cookie(s) even when your user restarts your application.

Alternatively, if the page doesn't use cookies but stores the session id in the url instead, you need to keep pass along the session id in the url of the pages you wisit. Just append it to the url's and it should work. :-)

Sunday, October 3, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :