Asynchronous HTTP Handler And Using HttpContext In A Background Thread?

Feb 10, 2010

I was reading Walkthrough: Creating an Asynchronous HTTP Handler and noticed they pass the HttpContext from the handler thread and use it in a WaitCallback which runs on a background thread. It makes calls like _context.Response.Write(). Am I correct in assuming that this doesn't violate the fact that HttpContext is not thread safe because the handler thread will not be using it after the async work has started?

Also, Using an HTTPContext across threads has some good information about HttpContext and threads. Is all of HttpContext not thread safe, or just items like Response? Can multiple background threads access the Items property, if only in read mode?

View 1 Replies


Similar Messages:

Getting Website's URL Without HttpContext.Current (running In Background Thread)?

Aug 3, 2010

Bit of a long shot, but is there a way in ASP.NET to dynamically get the website's URL [URL] when there is no HttpContext.Current available.

There is no HttpContext because the code is running in a background thread* (but under the ASP.NET AppDomain). I have a background process that sends emails out every evening, and needs to include the Web address, but I don't want to hard code it because of deployments and testing (it changes from [URL] to[URL] and then to [URL] for the live site).

View 2 Replies

C# - Set HttpContext.Current.User From Thread.CurrentPrincipal?

May 17, 2010

I have a security manager in my application that works for both windows and web, the process is simple, just takes the user and pwd and authenticates them against a database then sets the Thread.CurrentPrincipal with a custom principal. For windows applications this works fine, but I have problems with web applications.

After the process of authentication, when I'm trying to set the Current.User to the custom principal from Thread.CurrentPrincipal this last one contains a GenericPrincipal. Am I doing something wrong? This is my code:

Login.aspx

[code]....

View 5 Replies

How To Call Static File Handler From HTTP Handler In IIS7 And 4.0

Jan 24, 2011

I create custom HTTP handler for auto generating file and I want to tell IIS7 to serve current request like normal static file because I need to use IIS and web.config file to control compression setting and any other HTTP header of current requested file.I know. there is an internal class called StaticFileHandler in ASP.net. But I cannot access it. Or you have any other way to work like this.

View 1 Replies

C# - Accessing HttpSessionState (HttpContext.Current.Session) From Another Thread?

Nov 25, 2010

We have a web site which implements a central HttpSessionState management in App_Code like this:

[code]...

All of this worked fine ultil we needed to implement a time consuming process in a new thread...
In the second thread HttpContext.Current.Session is null (we know its because the current context its different between threads) so everything fails :

Investigating we found that you could pass the session from one thread to another like this:

[code]...

View 2 Replies

HttpHandlers / Modules :: Redirect A Page From Http To Https Using Http Module Begin Request Handler?

Jul 15, 2010

i redirect a page from http to https using http module begin request handler .i am calling webservice using ajax but it is saying webserice not defined .which otherwise works fineits work fine when rediect page in page_load instead .but i need to add function for https to http in every page. i still not know why ajax is not working when i use http module for redirect

View 3 Replies

Web Forms :: Start Two Asynchronous Database Access Calls That Are Executed Onto The Separate Thread?

Sep 2, 2010

i have the code for asynchronous call to the database. i execute the sql command into the begin method that will executed onto the separate thread. now i want to execute the another database call asynchronously so that this also execute onto the separate thread. code for one database cal is here....

private SqlConnection con, con1;
private SqlCommand cmd, cmd1;
private SqlDataReader dr, dr1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AddOnPreRenderCompleteAsync(new BeginEventHandler(Begin),
new EndEventHandler(End)
);
}
}
/////////////BEGIN METHOD
IAsyncResult Begin(object sender, EventArgs e,AsyncCallback cb, object state)
{
string connect = "Data Source=.\SQLEXPRESS;Asynchronous Processing=true;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";
con = new SqlConnection(connect);
con.Open();
cmd = new SqlCommand("SELECT FirstName,LastName,Age,Company,Profile FROM Person",con);
return cmd.BeginExecuteReader(cb, state);
}
//////END METHOD
void End(IAsyncResult ar)
{
dr = cmd.EndExecuteReader(ar);
Label2.Text = System.Threading.Thread.CurrentThread.GetHashCode().ToString();
GridView1.DataSource = dr;
GridView1.DataBind();
}

View 1 Replies

C# - Set Thread As Background Or Not

Jan 2, 2011

I need an explanation regarding some advice I got on this site. I'm doing a newsletter sending app, and I have my mail sent in a seperate thread so the process doesn't slow down the whole web site. A couple of people advised me to set the threads IsBackground property to true. I did this, but was also courious about what this does, so I googled a bit.

As it turns out, setting the IsBackground property to true indicates that "it's okay if the process shuts down while this thread is still running.". Or as microsoft puts it "Any remaining background threads are stopped and do not complete." I don't know if I got this the wrong way but, wouldn't it be better to leave the IsBackground property to false, so that the spawned thread can complete its work regarding the main thread?

View 2 Replies

How To Pass Through Http Call With HTTP Handler

Jan 4, 2011

Background:

We are using the Facebook API and receive back URLs for profile image thumbnails. Unfortunately the protocol is restricted to just HTTP and it doesn't support HTTPS. The page on our site that hosts the thumbnails is always delivered via HTTPS, and if we use HTTP for the thumbnails the user will receive security warnings from their browser.

Solution:

Build an HTTP Handler that "passes through" the image from the Facebook URL, but allow the handler to be called via HTTPS. Before I started coding I thought I could something like this:

Response.OutputStream = WebRequest.Create(FacebookUrlForThumbnail)

but I ended up having to save the image to an object in memory than write the image to the Response.OutputStream using the image save function.

Current Code:

[Code]....

This seems inefficient but I can't find a way of using the HTTP Handler as I orginally intended. Is there way of accomplishing the goal without creating the image memory and just "passing through" the call?

View 3 Replies

HttpHandlers / Modules :: Asynchronous Read From Handler?

Jan 16, 2010

I have found very strange problem with using asynchronous request. I wrote ASP.NET handler like follows.

[Code]....

Next, i write C# client application as follows.

[Code]....

This works very fine, s == "Test1".Now i want to make nonblocking call as follows.

[Code]....

View 4 Replies

Programmatically Set HttpContext.Handler In Classic Application?

Feb 24, 2010

In my CMS application, I'm trying to intercept all ASP.NET requests, inspect them and then assign custom HttpHandler if necessary or leave default handling when appropriate.I tried setting HttpContext.Current.Handler in Application_BeginRequest but it doesn't seem to work.There is MapRequestHandler event in HttpApplication but it is not available in the Global application class.

View 1 Replies

C# - Creating A Background Thread In A WCF Service During A Call?

May 21, 2010

The following code is part of a WCF service. Will eventWatcher take up a thread in the ASP .NET thread pool, even if it is set IsBackground = true?

[code].....

View 1 Replies

How To Optimize The Performance Of A Thread Running In Background

Feb 4, 2011

In my website, I am using thread to perform a repetitive process in background. Now the process takes around 30 to 45 seconds to update the database.

Basically the function performs the following:

1) Download the CSV from a website.

2) Parse the CSV and update the database tables.

I want to optimize the performance and decrease the time it takes to 15 seconds.

How can I do this?

EDIT:

Here is the Code:

[code]....

View 1 Replies

AJAX :: Fire Callback Event Handler From Asynchronous Upload

Nov 22, 2010

I have a page that is using the Ajax asynch file uploader. What I would like to have happen is after the file is uploaded I would like to have it displayed in a list on the page. I am looking for a way to fire a callback event when the file upload is complete. Is it possible using the asynch fileupload control?

View 1 Replies

What Is HTTP Module And HTTP Handler

Jan 20, 2010

clear my concept What is HTTP module and HTTP Handler and how does they work while page requesting???

How authentication and Authorization process work in asp.net?

View 2 Replies

C# - Finding Information About Sending Emails In A Background Thread?

Jan 21, 2010

I have a thread running in the background that will sleep and pull data from the database when something wakes it up. I am sending the emails using google apps using SmtpClient (code below).

I wanted to know if there is anything i be aware of? I plan to send only one email at a time (a registration or forgot password email). I am a little worried something can happen like an invalid email locking up the thread because i didnt set a timeout or maybe google apps happen to be done and causing the app to blow up. What should i be aware off? I should ask how i should test as well?

[code]....

View 4 Replies

Http - Get Application Path Without Using Httpcontext?

Mar 9, 2010

How to do it?I don't want to use this:

HttpContext.Current.Server.MapPath

Is there a similar function that I can call without requiring a httpcontext?For example if a start a thread doing some stuff i cant use the httpcontext, but i still need to get the path of the app. And no i can't pass the context as an argument or read it from a shared var.

View 1 Replies

C# - Catching Exceptions Thrown In An Asynchronous Web Service Completed Event Handler?

Feb 12, 2010

Imagine a web service with a method that returns a Customer object, that takes a customer ID as a parameter, i.e.

[WebMethod]
Customer GetCustomer(string customerId)

Now imagine that you're writing an ASP.NET app and you've generated a proxy for the service with the async operations. You create an instance of the service, wire service.GetCustomerCompleted to your handler, OnGetCustomerCompleted, and call service.GetCustomerAsync("12345"). In OnGetCustomerCompleted you apply logic to detect that no customer was found and throw a custom exception, or you want to throw the exception found in e.Error, e.g.:

void OnGetCustomerCompleted(object sender, GetCustomerCompletedEventArgs e)
{
if (e.Error != null)
throw new ApplicationException("GetCustomer failed", e.Error);
if (String.IsNullOrEmpty(e.Result.FirstName) && String.IsNullOrEmpty(e.Result.LastName))
throw new CustomerNotFoundException();
}

(I've omitted the bits of code that sets up a Customer object and persists it through the calls.) You launch the call to GetCustomerAsync in Page_Load and expect to retrieve the result in a handler wired to Page.OnPreRenderComplete. My question is, how do you catch the exception in your page? I know you can catch it with Global.asax's ApplicationError, but what if you don't want to navigate away from your page?

View 1 Replies

Does The Continuously Running Thread In Background Impact The Website's Performance

Feb 3, 2011

In my website I am using thread to perform the function which downloads the CSV from a website and parses the data into the database.

Now if I am not able to stop the thread then what could be the impact on the performance?

Also If I unknowingly start another thread then would it impact my website's performance?

View 3 Replies

C# - Can Execute A Stored Procedure Using Linq In A Background/alternate Thread

Feb 4, 2011

In my app I am using the open xml sdk to generate a word document and write the file to the response.output stream for the user to download.

At the time that the letter is generated I also need to call a SP via linq data context to update a row in my db.

I think that I need to execute this SP in a seperate thread so that I can simultaneouly write the file to the output. my method looks like this...

protected void btnPrint_Click(object sender, EventArge e)
{
//call sp to update
//create letter and send to client
}

Is this feasible or should I avoid seperate threads?

View 1 Replies

Configuration :: Unable To Pass Session With Modal Popup Extender And Background Thread

Oct 2, 2010

I have a problem with a Model Popup Extender that monitoring a background thread.

I need to give feedback to the user about tasks that happend in the server side.

So searching on internet this give me a solution [URL]

Launch a thread, passing the Session variable, update a flag and a mesage and show the info in the web with a timer.

almost all, is fine, in one server (sadly, close to production) after the task (and thread) is completed, the Session variable is set to null and the user is redirected to a "Session Expired" Page.

[code].....

I noticed that this is a very slow server and some websites are very slow.

Session is managed with cookies and the timeout is set to 30 min.

View 1 Replies

C# - Difference Between Http.context.user And Thread.currentprincipal And When To Use Them

Jun 16, 2010

I have just recently run into an issue running an asp.net web app under visual studio 2008. I get the error 'type is not resolved for member...customUserPrincipal'. Tracking down various discussion groups it seems that there is an issue with Visual Studio's web server when you assign a custom principal against the Thread.CurrentPrincipal.

In my code, I now use...

HttpContext.Current.User = myCustomPrincipal
//Thread.CurrentPrincipal = myCustomPrincipal

I'm glad that I got the error out of the way, but it begs the question "What is the difference between these two methods of setting a principal?". There are other stackoverflow questions related to the differences but they don't get into the details of the two approaches.

I did find one tantalizing post that had the following grandiose comment but no explanation to back up his assertions...

[code]....

View 3 Replies

Access System.Web.Http.Current.Response From A Within A Thread?

Jul 16, 2010

I have a ASP.NET page with a WebMethod that creates an object and runs one of the object's methods in a new thread.I need to access the System.Web.HttpContext.Current.Response.ContentType property from within this thread. Each time I (try to) access it, I receive a NullReferenceException.

View 1 Replies

HttpContext.Current.Items Reused Across Multiple Http Requests?

Jan 27, 2011

I'm using HttpContext.Current.Items to make a Per-Request Cache Store. I'm hitting to many Cache entries over different http requests.

It seems that HttpContext.Current.Items is reused across multiple http requests. Is it normal?

View 2 Replies

Localization :: Assign Culture To Current Thread When Http Is Stateless?

Feb 5, 2010

When I was localizing my web application I got one strange doubt.

In the first request i set current thread's current culture to user chosen culture. It worked fine for that particular request. But when i browsed for other page, server rendered content in default english culture. I think the reason meight be "http is stateless" means current request is served by a thread whose culture was set properly. Send request will be serverd another thread which does not about previous thread. So we should once again assign culture to this thread. Localization can be done by setting culture to a session variable.

So my question is what is the benifit that we get by setting culture to current thread. With setting to thread we can show the page in user desired language.

View 2 Replies







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