Creating A Wrapper For HttpContext?

Feb 8, 2011

I'm trying to create a SessionManager class which I can use to manage sessions in my MVC applications. For that I'm thinking the best way of doing so is by creating a wrapper class for HttpContext which would then allow me to access HttpContext.Current.Session.

To be honest, I'm not really sure about the whole thing, I just feel it's the logical way of doing so. I also want to create an ISessionManager and ISession interfaces, and then implement them according to my application's needs. For my current project, and for now, I need a InProc session management, but I might need to store session data in MSSQL Server when we decide to expand and use a web farm or a garden. That's why I'm trying to build a sort of an extensible framework right from the start.

Final note, I will be using Microsoft Unity to inject the concrete SessionManager of choice. I believe that's a good way to maintain a certain level of abstraction.

View 1 Replies


Similar Messages:

C# - Creating A Web Wrapper For COM And OCX?

Mar 17, 2010

Today we have a windows application that, using an OCX, creates a web page (visible by a WebBrowser control in a small .NET WinForm application) and communicates through COM to the main application/client. (not relevant but this is Pascal)

I'm currently responsible to re create this application in a web environment so we can have the same functionality shared through Web as the user can see the same in a Web Browser.

The Windows application has almost 4 years on it and I need to re create everything from scratch, and all the bugs/features find in the future in the Windows Application I have to re create them again in the Web...

is there any way I can create a Wrapper, even using 3rd party commercial objects, to:

Communicate with the COM Object Can expose the content of the OCX (this in my most confortable language, ASP.NET C#, but other are welcome) I was thinking out loud, can this be accomplish with a Java Applet? Silverlight 4?

View 1 Replies

ADO.NET :: Creating Dataset Wrapper In C#?

Oct 15, 2010

creating dataset wrapper in c# with sample code..

View 3 Replies

C# - Workaround For HttpContext.HideRequestResponse Being Internal? Detect If HttpContext.Request Is Really Available?

Apr 9, 2010

We're migrating an application to use IIS7 integrated mode. In library code that is designed to work either within the context of an HTTP request or not, we commonly have code like this:

if (HttpContext.Current != null &&
HttpContext.Current.Request != null) {
// do something with HttpContext.Current.Request
} else {
// do equivalent thing without HttpContext..
}

But in IIS7 integrated mode the check for HttpContext.Current.Request throws an exception whenever this code is called from Application_Start.

protected void Application_Start(object sender, EventArgs e)
{
SomeLibrary.DoSomethingWithHttpContextCurrentDetection();
}

Results in:

System.Web.HttpException: Request is not available in this context

How can I detect whether the request is really available without wrapping these calls in an exception handler and taking action based on whether an exception is generated or not.

Looking at HttpContext in Reflector I see it has an internal bool HideRequestResponse field but it's internal so I can only get to it with reflection and that's fragile. Is there a more official/approved way to determine if it's ok to call HttpContext.Request?

This blog post about the subject says not to use HttpContext, but how, in generic library code, can you determine if it's ok to use HttpContext?

http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx

I'm using the work-around mentioned there which is to use Application_BeginRequest and an initialized field to only initialize once as part of BeginRequest, but that has to be done in every calling application whereas I'd prefer to make the library code more robust and handle this situation regardless of where it's called from.

View 4 Replies

Relationship Between HttpContext.Request.Cookies And HttpContext.Response.Cookies

Nov 23, 2010

I have been experimenting with code that will clear all of the cookies in an HttpContext.Response.Initially, I used this:

DateTime cookieExpires = DateTime.Now.AddDays(-1);
for (int i = 0; i < HttpContext.Request.Cookies.Count; i++)
{
HttpContext.Response.Cookies.Add(
new HttpCookie(HttpContext.Request.Cookies[i].Name, null) { Expires = cookieExpires });
}

this will error with an OutOfMemoryException because the for loop never exits - each time you add a cookie to the Response, it also gets added to the `Request.

View 1 Replies

Difference Between ControllerContext.HttpContext.Session And HttpContext.Current.Session

Nov 23, 2010

i'm using an example in which i can fake the session.It's for use in a unittest of a mvc controller.In the test i create a controller and then i do this:

FakeHttpContext httpctx = new FakeHttpContext(null,null,null,null,mSessionItems );
ControllerContext ctx2 = new ControllerContext(httpctx,new RouteData(), target);

here mSessionItems is my session and target is my instance of a controller,and indeed, when i'm in a controller reading this.ControllerContext.HttpContext.Session, i have a session, great!but.... i also read the session outside the controller, and there i use HttpContext.Current.Session, and that is null (or actualy, the HttpContext.Current is null).

View 1 Replies

WCF / ASMX :: Soap Wrapper Around XmlDocument

Nov 8, 2010

I wrote a webmethod (Called SearchData()) in which the method makes a httpwebrequest to another url and gets the data in xmldocument. After getting the xmlDocument ,it is returned to SearchData method invoker. When i invoke the from browser it works fine. But When another application in java tries to consume this webmethod SearchData(), it is getting the error

<wsdl:part name="Body"/>

and each part should be type defined. The WSDL file is not well formatted. it doesn't have Type defined at each element. How to fix this.or Is there any other Better way to provide the end user the xml(ie from httpwebrequest result in webmethod ) with a soap wrapper ie with a well defined wsdl. My code :

[Code]....

View 1 Replies

Architecture :: How To Create Wrapper Classes

Nov 24, 2010

I have a third party dll and i need to add some more functionalities (methods, constants etc..) so create a wrapper class. I have no idea about wrapper classes. what is the purpose of this and how to create in .NET for this 3rd party dll.

View 6 Replies

AJAX :: CollapsiblePanelExtender Extra Div Wrapper?

Jul 15, 2010

I have this CollapsiblePanelExtender (below) the problem is that in firefox it gives a horizontal scroll bar under the control which has to expand.

[Code]....

Below is the generated HTML

[Code]....

If I remove the "overflow-y:hidden" from the generated div then the scroll bar goes away, which is what I want....

View 3 Replies

WCF / ASMX :: Writing A .NET REST Wrapper?

Oct 5, 2010

I am a REST web service newbie, does visual studio, .NET, or some other nifty microsoft tool provide any easy way to auto generate classes to consume a REST web service? With REST services is there even a service definition like there is with SOAP (WSDL) beyond the printed documentation? There is a new service that I'd like to consume but they only wrote wrappers for PHP, Pearl, Ruby, and Java and have more or less said you are on your own with .NET. I could write it myself but I'd like to cut corners and save time wherever possible.

View 1 Replies

MVC :: Injecting The Session Into A Wrapper Class

Aug 13, 2010

I've seen how to Fake the SessionState object in MVC using Scott Hanselmans MvcMockHelpers, but I'm dealing with a separate problem.What I like to do is create a wrapper around the Session object to make objects a little more accessible and strongly typed rather than using keys all over. Here is basically what it does:

public class SessionVars{ public SessionVars() {} public string CheckoutEmail { get { return Session[checkoutEmailKey] as string; } set { Session[checkoutEmailKey] = value; } }}

So that I can just do this in my controllers and views:

SessionVars s = new SessionVars();s.CheckoutEmail = "test@tester.com";

Now the problem comes in when I want to write unit tests, this class is tightly coupled with the HttpSessionState. What I can't figure out is what is the right class to accept/pass so that I can pass in a FakeHttpSession into the SessionVars class. I've tried so many things with this, and this (below) will compile, but it can't cast the HttpSessionState into the IDictionary. I've tried ICollection, HttpSessionStateBase.

public class SessionVars{ public SessionVars() : this(HttpContext.Current.Session) { } public SessionVars(ICollection session) { Session = (IDictionary<string, object>)session; } public IDictionary<string, object> Session { get; [code]...

I'm missing something big here. I feel like this is possible and that I should even be that far off.Furthermore, I'm confused as to whether I should use the IHttpSessionState, HttpSessionStateBase or the HttpSessionStateWrapper. What is the abstract type that I'd use for the session object inside my SessionVars class? What is the type that I pass into the constructor?

View 3 Replies

ADO.NET :: Light Weight Data Access Wrapper

Mar 8, 2011

I am just trying to figure something out. At work we have alot of data access code Ex:

[Code]....

Pretty standard stuff really, but I was at a training course recently where the Developers insisted on wrapping code, that seemed nothing more than expose exactly the same functionality.

I was interested in your thoughts as to whether this was a good idea. So the above would inherit from a DbHelper class with some thing like:

[Code]....

These would just expose the same but maybe a bit more generic i.e. using DbCommand as opposed to SqlCommand.

View 1 Replies

C# Wrapper Or Samples For Google Site Search?

Sep 25, 2010

Anybody seen any c# code examples for using Google site search to send a request to the Google search api and return the results in xml?

View 1 Replies

DataSource Controls :: DB Wrapper Class For SQL Server And SQL?

Mar 4, 2010

Not sure if I'm posting in the right place so please forgive meI have an ASP.NET C# application that connects to either a SQL Server or MySQL database depending on some value that is set in my project config. The issue I'm trying to avoid is handling the connections and queries separately. Ideally I would want to use a DB Wrapper class that can handle both SQL Server and MySQL.

View 8 Replies

JQuery In UpdatePanel Wrapper For PageRequestManager.getInstance().add_endRequest

Mar 18, 2011

When jQuery is applied to elements in an UpdatePanel, when the UpdatePanel refreshes, the jQuery is not applied to the newly injected HTML. This issue is resolved by using

Sys.WebForms.PageRequestManager.getInstance().add_endRequest() to register a function to be called when the AJAX request is complete: I've written a function that registers the function with add_endRequest, and also calls it at the same time:

Async.RegisterAndRun = function(callback) {
//register function to be run when an update panel request is complete
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(callback);
//also run the function right now.
callback();
};

Now all we need to call is Async.RegisterAndRun(AddFancyjQueryToMyHTML); or
Async.RegisterAndRun(function(){
AddFancyjQueryToMyHTML();
AddMoreFancyjQueryToMyHTML('with', 'args');
});

Currently it does what I need it to, and I never need to explicitly call add_endRequest which is nice.

View 2 Replies

AJAX :: Write A Wrapper Method Around The WebMethod When Using PageMethods?

Jan 19, 2011

I am using ASP.net with WebMethods to show data to the customer and save data entered by the customer.

My current framework uses javascript to create an xml with all of the values of all the html elements in de "div" (or other element). This xml is converted to a string and send to the webserver using PageMethods.

When I receive this xml (as a string), I parse it with my own XmlDataParser which does some security checks.

I need to parse the xml to an XmlDataParser in every PageMethod I use, and I also need to catch different exceptions (like exceptions that are thrown when data is validated) to show them to the user (=> The reason why is explained in one of my previous posts: [URL]

I wonder if it is possible to write a wrapper around the WebMethod, so I can parse the xml to the XmlDataParser in this wrapper, and pass it on to the code behind, and process exceptions that occur in the code behind?

View 4 Replies

C# - Create A Business Model Wrapper For A Generic Database Approach?

Mar 10, 2011

I'm currently facing a performance problem with creating POCO objects from my database. I'm using Entity Framework 4 as OR-Mapper. The whole application is a prototype for now. Let's assume I want to have some business objects like classes 'Printer' or 'Scanner'. Both classes inherit from a BaseClass called Product.
The business classes exist.

I try to use a more generic database approach. I don't want to create tables for "Printer" nor "Scanner". I want to have 3 tables: One called Product, and the other Property and PropertyValue (which stores all assigned values to a specific Product). In my business layer I do create a specific object like this:

public Printer GetPrinter(int IDProduct)
{
Printer item = new Printer();
// get the product object with EF
// get all PropertyValues
// (with Reflection) foreach property in item.GetType().GetProperties
// {
// property.SetValue("specific value")
// }
return item;
}

This is how the EF model looks like: Works fine so far. For now I'm doing performance tests for retrieving multiple sets. I've created a prototype and improved it several times to increase the performance. It is still far away from being usable. I takes 919ms to create 300 objects who only contain 3 properties. The reason for choosing such DB design is to have a generic database design. Adding new properties should only be done in the business model.

Am I just being too stupid to create a performant way of retrieving xx objects or is my approach totally wrong? As far as I understand OR-Mapper, they are basically doing the same?

View 2 Replies

How To Set A Property In Custom Controller Wrapper In OnActionExecuting How To Pass To Site.Master

Jun 3, 2010

Say I have a class that wraps the Controller class:

public class MyController : Controller
{
public string SomeProperty {get;set;}
public override void OnActionExecuting(...)
{
SomeProperty = "hello";
}
}

Now in my site.master, I want to have access to the SomeProperty that I just set. How can I do this?

View 2 Replies

Redirect Page Using HttpContext?

Apr 30, 2010

I am new in ASP.Net and C#.

I have used HttpContext.Current.Response.Redirect in a class file.

Is it right? or if any problem occur by using this?

View 2 Replies

How To HttpContext.Current Work?

Aug 5, 2010

I'm wondering how HttpContext.Current gets assigned a unique instance for every request considering it's a static object?

View 2 Replies

Getting HttpContext From BackgroundWorker Process?

Aug 19, 2010

I have an ASP.NET site and I've been doing some work refactoring code to try to remove some long running processes (in the order of an hour) from the actual http Request by creating a BackgroundWorker and sending the work off to that to process. This was running fine on cutdown tests but when I applied the logic to the real code I found problems accessing Session variables from the code running in the Background Worker. It seems that the HttpContext object that was passed has a null session and if I ask for HttpContext.Current I get null back.

I'm assuming that this is because they are in a different thread and that the session and HttpContext.Current are both reliant on being in the same thread. Is there any way I can get access to the Session from the background worker or am I stuck with finding all the variables I need from session and putting them in an usable data structure and then putting them back in session (if appropriate) afterwards? It obviously complicates the refactor massively if I need to do this so I'd rather not.how I might do this other than BackgroundWorker processes

View 1 Replies

C# - .Net Control.OnInt And HttpContext?

Feb 2, 2011

I'm digging around with HttpContext and the OnInit event for a custom control, after realizing that a few checks are not responding in the desired manner.

Within the current context's items collection, I store an object (serialized) that I would like to interrogate once on every post back. The first time the control is rendered, will the items[] be null, it then gets populated somewhere down the line and the user clicks a button to post back data.

Now, within the button submit event, I set the items[key] to null to ensure that on the post back I don't have anything stored, but it always contains a value.

I'm assuming that the OnInit handler has a reference to the previous state, thus 'falsely' assuming that the items[] should contain a value. Is this something to do with the way OnInit works, or am I missing the bigger picture?

View 1 Replies

What Is HttpContext.Response.SubStatusCode For

May 20, 2010

What is httpContext.Response.SubStatusCode for? this value is part of the IIS integration mode pipeline.

View 2 Replies

C# - Elmah: Exceptions Without HttpContext?

Jan 21, 2010

I spawn a thread on Application_Start and would like to log exceptions. There is not Context/HttpContext/HttpContext.Current, so how might i get it to log?ATM it does not catch any exception in my threads and if i write ErrorSignal.FromCurrentContext().Raise(ex); i get an error about context cannot be null.Maybe i can create a dummy HttpContext but somehow i dont think that will work well.-edit- i tried ErrorSignal.Get(new HttpApplication()).Raise(ex); and it doesnt seem to pick up that exception.

View 2 Replies

MVC :: Getting Controller And Action From HttpContext?

Mar 8, 2010

What's the correct way to get the controller name and action from an httpContext object? I can see the values in the debug, but I don't seem to be able to get to them in the object code?

View 13 Replies







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