![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [SOLVED] HTTPModule : ASP.NET 2.0? Suppose I have site xyz.com. Site has a page called show_user.aspx where I need to access the Session variables. But this show_user.aspx page will not be called directly Instead , when user type xyz.com/somnath …it will interpret “somnath” as a user name and internally call page show_user.aspx?user=somnath. I have created a HTTP module URLCheckingModule for URL checking. This is settings in my web.config file … <httpModules> <add name="Session" type="System.Web.SessionState.SessionStateModule"/> <add name="URLChecking" type="UserProfileModule"/> </httpModules> <pages enableSessionState="true" /> </system.web> </configuration> my Class code ... public class UserProfileModule : IHttpModule { public void Init(HttpApplication app) { app.PreRequestHandlerExecute += new EventHandler(this.OnPreRequest); } private void OnPreRequest(object sender, EventArgs e) { HttpContext context = HttpContext.Current; HttpRequest request = context.Request; string FilePath = request.FilePath; string ext = Path.GetExtension(FilePath); if (string.IsNullOrEmpty(ext) && !FilePath.EndsWith("/")) { // suppose URL is http://xyz.com/somnath/ // and empty Extension string q = request.QueryString.ToString(); string path = request.FilePath + "/" + (string.IsNullOrEmpty(q) ? "" : q); context.Server.Transfer("show_user.aspx" ); } else { if (FilePath.EndsWith("/")) { string dPath; dPath = context.Server.MapPath(FilePath); if (Directory.Exists(dPath) == false) { FilePath = FilePath.Remove(FilePath.Length - 1, 1 FilePath = FilePath.Remove(FilePath.Length - 1, 1); context.Response.Redirect(FilePath); } } } } public void Dispose() { } } Now, If in the show_user.aspx, works well, if I don’t have any session related calls, but gives error if I want to work with Session. Response.Write(Session["somnath"]); // note I have set the Session in the default page. Server Error in '/WebTest' Application. ________________________________________ Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration. Note: 1.I have already set the Session module in Web.config. 2.To ensure that , Sessionstate should be available I have added Module at “PreRequestHandlerExecute” , AS per MSDN documentation Session state is available in this event. I am stuck on this problem. Logically there is no reason to code to not work, as all steps are followed. Please help me for this problem. I have added IReadOnlySessionState , but sill same problem. Session is null. |
| |
| |||
| In order for your module to work, make sure IIS is configured to pass all requests (not just .aspx requests) to the .NET framework. To access Session from an HTTPModule, you must add the IReadOnlySessionState or the IRequiresSessionState (readonly is better for performance if you don't need to write to the session). |
| |||
| Hey I am same person, who has asked this question. I able to resolve the issue. 1. I have added the HTTP module in BeginRequest that is app.BeginRequest += new EventHandler(this.OnPreRequest); 2. instead of Server.trasfer I have used ... context.RewritePath("... This help me. Session is working properly. |
![]() |
| Thread Tools | |
| Display Modes | |
| |