httpcontext

Unit Testing Web Services - HttpContext

别等时光非礼了梦想. 提交于 2019-12-02 16:24:20
I want to write unit tests for a web service. I create my test project, reference my web project (not service reference, assembly reference), then write some code to test the web services - they work fine. However, there are some services which make sure the user is logged in to the web application by using HttpContext.Current.User.Identity.IsAuthenticated . In the context of the tests, there is no such thing as HttpContext, so the tests always fail. How should these kinds of web services be unit tested? Skuli Here is a related discussion. I stopped referencing HttpContext.Current directly.

How to obtain the HttpContext in Event Handler

拟墨画扇 提交于 2019-12-02 07:13:07
问题 I’m trying to obtain the HTTPContext within an Event Handler in a Document Library in MOSS, but all I have is a null value of the HTTPContext.Current, I do the same thing on a List and the HTTPContext is returned. There is a way to obtain the HTTPContext in Document Libraries to access the HTTPContext.Request method? Thanks for your help Here is the code: public class TestContextListItemEventReceiver : SPItemEventReceiver { HttpContext current; static object obj; /// <summary> /// Initializes

Navigate to a new page and display an alert box

五迷三道 提交于 2019-12-02 06:57:43
I am developing an application by using ASP.Net WebForm. Once user click a button, application will navigate to a new page and prompt out a dialog box "Welcome to JackiesGame" However, I able to navigate to new page but the alert dialog box does not display. The following is my sample code void cmdCancel_Click(object sender, EventArgs e) { HttpContext.Current.Response.Redirect(Globals.NavigateURL(TabId), true); Page page2 = HttpContext.Current.CurrentHandler as Page; ScriptManager.RegisterStartupScript(page2, page2.GetType(), "alertMessage", "alert('Insert Successfully')", true); } Add the

How is HttpContext being maintained over request-response

风流意气都作罢 提交于 2019-12-02 05:07:18
I am wondering how the HttpContext is maintained given that the request-response nature of the web is essentially stateless. Is an identifier being for the HttpContext object being sent as part of the __EVENTTarget / __EVENTARGUMENTS hidden fields so that the HttpRuntime class can create the HttpContext class by reading this section from the request (HttpWorkerRequest)? I don't think Please let me know as I am trying to fill some holes in my understanding of the http pipeline and I was unable to find any information about this. I understand something like HttpContext.Current.Session["myKey"] =

Artificially populate HttpContext object in a Console application

独自空忆成欢 提交于 2019-12-02 02:46:33
I am writing a wrapper library for log4net. This library should be able to capture Context information such as querystring, cookie, form fields etc. etc. I am invoking this wrapper class from Console application as opposed to TDD class. Is there a way to populate HttpContext object inside a Console application as follows? HttpContext c = new HttpContext(null); c.Request.QueryString.Keys[1] = "city"; c.Request.QueryString[1] = "Los Angeles"; c.Request.QueryString.Keys[2] = "state"; c.Request.QueryString[2] = "CA"; And then retrieve it as follows? Console.WriteLine(context.Request.QueryString

How to obtain the HttpContext in Event Handler

懵懂的女人 提交于 2019-12-02 00:58:32
I’m trying to obtain the HTTPContext within an Event Handler in a Document Library in MOSS, but all I have is a null value of the HTTPContext.Current, I do the same thing on a List and the HTTPContext is returned. There is a way to obtain the HTTPContext in Document Libraries to access the HTTPContext.Request method? Thanks for your help Here is the code: public class TestContextListItemEventReceiver : SPItemEventReceiver { HttpContext current; static object obj; /// <summary> /// Initializes a new instance of the Microsoft.SharePoint.SPItemEventReceiver class. /// </summary> public

Access Membership User On Session End

梦想的初衷 提交于 2019-12-01 22:26:44
问题 I'm currently trying to write a little bit of code to do some tidying up once a user abandons their session (either via time out or logging out) however would like to access the User object so I know who the session belongs to. Unfortunately HttpContext is null so I can't access HttpContext.User or HttpContext.User.IsInRole or even the auth cookie directly. I understand the reasons behind this but wonder if there is there any other way to get access to this information when a session times

Entity Framework ObjectContext with Dependency Injection

房东的猫 提交于 2019-12-01 14:37:33
Well, it seems like I'm stuck in my application structure. Here's what I want to do: UI layer: An ASP.NET webforms website. BLL: Business logic layer which calls the repositories on DAL. DAL: .EDMX file (Entity Model) and ObjectContext with Repository classes which abstract the CRUD operations for each entity. Entities: The POCO Entities. Persistence Ignorant. Generated by Microsoft's ADO.Net POCO Entity Generator. I'd like to create an obejctcontext per HttpContext in my repositories to prevent performance/thread [un]safety issues. Ideally it would be something like: public MyDBEntities ctx {

Castle.Windsor and HttpContextWrapper

天大地大妈咪最大 提交于 2019-12-01 13:31:44
HttpContextWrapper and HttpContextBase, as explained here , were introduced to make HttpContext more mockable/testable. I'm trying to use it with S#arp Architecture , and hitting some problems. My MVC Controllers are set up to accept an HttpContextBase argument in the constructor, and during Application_Start, HttpContextBase is registered with Castle.Windor as follows: container.Register(Component.For<HttpContextBase>().UsingFactoryMethod( () => new HttpContextWrapper(HttpContext.Current))); This seemed to work OK for a bit, but then I realised Castle is only running that Factory method once,

How can I make HttpContext available to be used by my Unit Tests?

风格不统一 提交于 2019-12-01 04:48:31
I want to write a unit test which tests the function of a class called UploadedFile. The problem I face is this class' static constructor uses HttpContext.Current property and because I am running my unit test from a class library I do not have an HttpContext at the testing time. Look at my static constructor: static UploadedFile() { if (HttpContext.Current == null) throw new Exception("web server not available"); HttpServerUtility server = HttpContext.Current.Server; // SET UploadedFileMappingFile Names: _resourceFileNames = new StringDictionary(); _resourceFileNames[_suppoertedFileStructures