MVC Session Per Request Pattern And IHttpModule - Open An ISession

Jan 9, 2010

Im trying to make a solution like this [URL] Now the question is how do I filter the request, I only want to Open an ISession if the request is for an ASPNET MVC Action, not for *.gif, *.css etc. How should I handle this filtering?

View 3 Replies


Similar Messages:

C# - Session Vs Singleton Pattern?

May 12, 2010

I have a web application where I would like to pull user settings from a database and store them for Global access. Would it make more sense to store the data in a Singleton, or a Session object? What's the difference between the two?Is it better to store the data as an object reference or break it up into value type objects (ints and strings)?

View 3 Replies

Session Object Design Pattern?

Jan 28, 2011

I'm looking to build an ajax page; it's a reporting page. By default, load today's report. On the page there's a calendar control and when the user clicks on a date, reload the gridview with the corresponding data. Is it considered good practice to do the following:

1) on the first page load, query the data for the page

2) put the query result in the session object and display it in a gridview

3) if the user requests new data, get new data from the query with different parameters

4) put the result of the second query in the session object and display it

5) if the user then requests the data from the first query, get it from the session object

6) do the sorting and paging with the data held in the session.

Note: the data of each query will contain about 300-500 rows and about 15 columns. I'd like to do all this with ajax calls. What are some suggestions and pitfalls to avoid.

View 4 Replies

State Management :: What Is The Regex Pattern Of Session Id

Sep 7, 2010

asp.net 4.0

I wonder what the Regex pattern for session id is?

View 1 Replies

Pattern For Retrieving Complex Object Graphs With Repository Pattern With Entity Framework

Oct 13, 2010

We have an ASP.NET MVC site that uses Entity Framework abstractions with Repository and UnitOfWork patterns. What I'm wondering is how others have implemented navigation of complex object graphs with these patterns. Let me give an example from one of our controllers:

[code]....

It's a registration process and pretty much everything hangs off the POCO class Person. In this case we're caching the person through the registration process. I've now started implementing the latter part of the registration process which requires access to data deeper in the object graph. Specifically DPA data which hangs off Legal inside Country.

The code above is just mapping out the model information into a simpler format for the ViewModel. My question is do you consider this fairly deep navigation of the graph good practice or would you abstract out the retrieval of the objects further down the graph into repositories?

View 2 Replies

MVC :: AsyncController Gripes / Working Pattern For Converting A GET-POST-GET Pattern To Asny?

Feb 23, 2010

Does anyone have a working pattern for converting a GET-POST-GET pattern to asny?

I'm encountering the following issues:

1. You cannot mix Sync and Async action methods SubmitForm(), SubmitFormAsync(bool? confirm), SubmitFormCompleted() ... (because the resolver gets all confused ... it doesn't use the HTTP verb to decide who to target. BTW: I think that's poor design, or a bug)

2. Renaming the get method name to something else eg: SubmitFormConfirmation(), SubmitFormAsync(bool? confirm), SubmitFormCompleted() would be very awkward if it works ... because you have to doctor the <form markup to specify an action name.

3. You cannot give them all async names SubmitFormAsync(), SubmitFormAsync(bool? confirm), submitFormCompleted(), because the call just keeps malfunctioning. It sometime even behaves as if you are requesting a delete of something.

Can someone give an insight from an actually working sample.

View 5 Replies

Best Design Pattern For Associating Subdomain With Area And PRG Pattern?

Aug 21, 2010

Now that the next version of ASP.NET MVC is being prototyped and previewed (ASP.NET MVC 3 Preview 1 came out a couple of weeks ago), I wonder if we should call the attention of the Core Dev team (S Hanselman, Phil Haack and all) to this "feature."there a easy/non tacky way of associating subdomains &#8594; areas?Something like:
[URL]Also, whats the best accepted design pattern in implementing PRG pattern in ASP.NET MVC? I guess it should also get some official loving in MVC 3.

View 2 Replies

Web Forms :: 3.5 Error: Unable To Make The Session State Request To The Session State Server?

Dec 7, 2010

Have not run the ASP.NET Development Server for a while. Today I copied a production website to my workstation and ran it with VS 2008. The following error message popped up. What is the problem with the ASP.NET development Server on my workstation? The website on the Production server still ran okay.Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of KEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesaspnet_stateParametersAllowRemoteConnection.
If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '127.0.0.1' as the server name.

View 2 Replies

When Open A Page Get Message, Server Is Temporarily Unable To Service Request

Mar 15, 2010

I have installed/compiled mono, xsp and mod_mono. But how do I configure apache to use it? I tried including the mod_mono.conf file and apache does see the module and loads it but when I visit an asp page I getService Temporarily UnavailableThe server is temporarily unable to service your request due to maintenance downtime or capacity problems.

View 2 Replies

Web Forms :: Distinguish Between Window.open Request And Copy Paste It In Browser

Apr 19, 2010

We have a page that is opened in the child window using window.open. Now the user will copy the child's window Url and copy-paste it in the browser. We need to restrict this scenario. How should we do this. I mean I need to know in my page load method whether the request has come from window.open or whether the user copy-pasted the Url on the Browser's Address bar.

View 7 Replies

C# - Inject Js From IhttpModule?

Mar 8, 2011

i trying to inject js to page (to tags) by using ihttpmodule.but js isn't injected.

the page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyTempProject._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

[Code]....

View 1 Replies

Passing Session[] And Request[] To Methods In C#?

Apr 13, 2010

In C#, How do you pass the Session[] and Request[] objects to a method?I would like to use a method to parse out Session and Request paramaters for a .aspx page to reduce the size of my Page_Load method. I am passing quite a few variables, and need to support both POSTand GET methods. For most calls, not all variables are present, so I have to test every variable multiple ways, and the code gets long...This is what I am trying to do, but I can't seem to properly identify the Session and Request paramaters (this code will not compile, because the arrays are indexed by number)

static string getParam(
System.Web.SessionState.HttpSessionState[] Session,
System.Web.HttpRequest[] Request,
string id)

[code]...

View 2 Replies

HttpModule : Detect First Request In A Session?

Sep 2, 2010

I have written a HttpModule for our site which generally accepts requests and checks for specific file extensions as well as the value of a specific session variable. Is it possible to detect the first request in a session?

View 1 Replies

C# - How To Dispose IHttpModule Correctly

Aug 6, 2010

All implementation of IHttpModule I've seen looks following:

[code]....

I am wondering why is the Dispose method always empty? Shouldn't we unsubscribe the event which we subscribe in the Init method?

View 1 Replies

C# - Implement A .NET Event On An IHttpModule?

Nov 7, 2010

I've declared an event on an HTTP Module so it will poll subscribers for a true/false value to determine if it should go ahead with its task of tweaking the HTTP Response. If only one subscriber answers true then it runs its logic.

Are there potential pitfalls I'm not seeing?

public class ResponseTweaker : IHttpModule {
// to be a list of subscribers
List<Func<HttpApplication, bool>> listRespondants = new List<Func<HttpApplication, bool>>();
// event that stores its subscribers in a collection
public event Func<HttpApplication, bool> RequestConfirmation {

[Code]....

View 1 Replies

Difference Between HttpApplication Class And IHttpModule?

Jan 31, 2011

What is the difference between HttpApplication class and IHttpModule? Are they both same or different?

I see articles that mention the same events in both the classes.

View 4 Replies

C# - Reference An IHttpModule Instance In The Pipeline?

Nov 7, 2010

An IHttpModule implementation I created

public class ResponseTweaker : IHttpModule { // my module ...

is registered in Web.config

<system.web>
<httpModules>
<add name="redman" type="ResponseTweaker"/>
</httpModules>

and an instance of it is sitting in the pipeline.

From the perspective of a caller (e.g. from the Global.asax.cs file), how should I get a reference to that module instance?

View 1 Replies

Register Generic Class As IHttpModule?

Nov 9, 2010

public class NHibernateSessionPerRequest<T>:IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context)
{
context.BeginRequest += BeginRequest;
context.EndRequest += EndRequest;
}
}

How can it be registered in web.config?

View 2 Replies

Flash - Associate Session With Client / Request Based On Ip

Mar 18, 2010

In one web page we use a flash upload control but becouse a flash bug in the upload event the session is lost as its posted back with a new session.

We have tought of using a table with ip and old session id or a query string with the old session id in order to reassing it in the uploaded event...

Knowing the old session id how can i reassign it to the client? (In C#)

View 2 Replies

Custom Authentication Module Inheriting IHttpModule

Feb 3, 2011

LoginPage.aspx:-
protected void Button1_Click(object sender, EventArgs e)
{
Context.Items["Username"] = txtUserId.Text;
Context.Items["Password"] = txtPassword.Text;
//
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, Context.Items["Username"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(10), true, "users", FormsAuthentication.FormsCookiePath);
// Encrypt the cookie using the machine key for secure transport
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // Name of auth cookie
hash); // Hashed ticket
// Set the cookie's expiration time to the tickets expiration time
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
Response.Cookies.Add(cookie);
Response.Redirect("Default.aspx");
}
Global.asax file:-
void Application_AuthenticateRequest(object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id =
(FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
// Get the stored user-data, in this case, our roles
string userData = ticket.UserData;
string[] roles = userData.Split(',');
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id, roles);
Response.Write(HttpContext.Current.User.Identity.Name);
Response.Redirect("Default.aspx");
}
}
}
}

I get the following error after signing in This webpage has a redirect loop.

The webpage at [URL] has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.

View 2 Replies

State Management :: Session Or Request In Class Without Passing As Parameter

Sep 3, 2010

I'd like to be able to reference the asp.net objects Session, Request, from a procedure without passing them in as parameters all the time. Is there a way to do this. For example, now I have

[Code]....

I'd like to call it like this "ContextPT.GetSession()" and have GetSession know how to find the Session object. I know this does not seem like a big deal in this case, but I have reasons.

View 1 Replies

Persisting Session State Via Multiple Request Using JQuery $.ajax()?

Jan 25, 2011

just been trying to recieve the session value from multiple jquery ajax requests on the same domain name. i think i understand that each request is kind of a virtual browser request so the session is mutally exclusive to each request, but there must be a way some how, has anyone solved this. Basically this is what im trying to do:

I have tries using type: GET and POST but still no luck.

First request - Stores the product id in a session

[code]....

View 1 Replies

Security :: Potentially Dangerous Request When Packing Session State?

Mar 31, 2010

I'm writing a product management system for a website. As an administrator defines product details, those details are stored in the Session so that fields remain populated as the user navigates across multiple pages. One of these fields is a "RichTextBox" that allows the user to define a product description with rich text.

Attempting to pack the contents of this rich text box into a Session variable raises the following Server Error:

A potentially dangerous Request.Form value was detected from the client (ctl00_ContentPlaceHolder1_RichTextBox1_tbxRichContent="<b>asdf</b>").

The offending line of code is as follows:

Session["NewProductDescription"] = HttpUtility.HtmlEncode(RichTextBox1.Text);

I thought HtmlEncoding would solve the problem, but it did not.

View 1 Replies

How To Avoid ASP.NET SqlServer Session To Interfer With The Ambient Transaction-Per-Request?

May 20, 2010

I am trying to use a transaction scope in a transaction-per-request pattern. So I have a http module that do (simplified):

private void Application_BeginRequest(object sender, EventArgs e)
{
var scope = new TransactionScope(TransactionScopeOption.RequiresNew);
PutScopeInHttpContext(scope);
}

private void Application_EndRequest(object sender, EventArgs e)
{
var scope = GetScopeFromHttpContext();
try
{
if (HttpContext.Current.Error == null)
{
scope.Complete();
}
}
finally
{
scope.Dispose();
}
}


Then, in my web.config, I have:

<httpModules>
<clear/>
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
<add name="Profile" type="System.Web.Profile.ProfileModule"/>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="TransactionPerRequestWebModule" type="Acme.Web.TransactionPerRequestWebModule, Acme.Web"/>
</httpModules>
<sessionState mode="SQLServer" sqlConnectionString="Data Source=localhostSQLEXPRESS;Integrated Security=SSPI;" cookieless="false" timeout="360"/>


Now, at what seem like randomly rate, roughly 1 page out of ten gives me the following error:

[SqlException (0x80131904): Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1951450
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849003
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
System.Data.SqlClient.SqlDataReader.get_MetaData() +83
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
System.Data.SqlClient.SqlCommand.ExecuteReader() +89
System.Web.SessionState.SqlSessionStateStore.DoGet(HttpContext context, String id, Boolean getExclusive, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +516

[HttpException (0x80004005): Unable to connect to SQL Server session database.]
System.Web.SessionState.SqlSessionStateStore.ThrowSqlConnectionException(SqlConnection conn, Exception e) +229
System.Web.SessionState.SqlSessionStateStore.DoGet(HttpContext context, String id, Boolean getExclusive, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +649
System.Web.SessionState.SqlSessionStateStore.GetItemExclusive(HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +48
System.Web.SessionState.SessionStateModule.GetSessionStateItem() +117
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +487
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +66
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


What I (think I) understand is that the connection to the ASP.NET session database is sometimes enlisted in my business transaction, and I get this error when my business transaction is completing first.

There is a couple of problem with that:


I don't think the transaction for the session state should be the same as my business one. These are 2 separate concerns.
It makes the transaction automatically escalate to a distributed (MSDTC) one, which impacts my performance.

How do I decouple my business transaction from the ASP.NET session one?

View 1 Replies

State Management :: Session_OnStart Event Fires With Every Request After A Session Timeout

Jun 3, 2010

I have noticed that when I have a session that has expired, the Session_OnStart event fires with every new request.

I suppose that this behavior is not normal, because I was expecting that the session would re-start only with the first request and not with every subsequent request.

This behavior occurs only with sessions where the timeout period has been exceded.

The current conditions under which I have experienced this problem are:

I have experienced this problem with an application that is using the .NET 2.0 framework and with a session mode configured to InProc. This problem is happening both on Windows XP SP3 and Windows 2003 Server.

View 5 Replies







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