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
Similar Messages:
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
Mar 2, 2010
I need to run a SELECT box [on]change handler after changing the selectedIndex.
I see the selectBox._events['change'][0].handler() method added by $addHandler, but what is the ASP.NET Ajax way to raise it as an event?
The backup plan is to set sel.onchange directly and skip ASP.NET Ajax events completely.
View 6 Replies
Jun 10, 2010
I'm trying to use one ImageButton as both a login button and a logout button. Initially its a login button. I click the button once and it runs the login click handler and pops up a text box to type in a password. Then I enter the password to login. Inside the password box's submit handler I check to see if the password is valid. If it is, I enable all the password protected functionality on the page, change the button's image from the login image to the logout image, and change the button's click handler from the login Click handler to the logout Click handler.
So far my code just swaps the button's image but the click handler never changes to the logout handler. I have tried two ways of changing the ImageButton's click handler programmatically and both have failed:
1.
loginBtn.Attributes.Remove("OnClick");
loginBtn.Attributes.Add("OnClick", "logoutBtn_Click");
2.
loginBtn -= new ImageClickEventHandler(loginBtn_Click);
loginBtn += new ImageClickEventHandler(logoutBtn_Click);
Neither the login text box or the login/logout button are inside an UpdatePanel. EnableViewState is set to the default of true. Does anyone see what is preventing the Click handler from being changed?
View 4 Replies
Jan 25, 2012
I need to generate a button way after the page loads but I can't work out how to deal with the Event handler. If I do this when the page loads as shown bellow it works as intended but if I use the exact same method in a button it fails. (it creates the button but when I click the button it just disappears instead of showing a msgbox."I know I shouldn't use Msgbox in a web form but I only do it as a test then remove it"
Code:
Partial Class Default3
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mybutton As Button
mybutton = New Button
mybutton.Text = "Submit"
[code]...
View 1 Replies
Jun 1, 2010
We are in design phase of a project whose goal is replatforming an ASP classic application to ASP.Net 4.0. The system needs to be entirely web based. There are several new requirements for the new system that make this a challenging project:
The system needs to be database independent. It must, at version 1.0, support MS SQL Server, Oracle, MySQL, Postgres and DB2. The system must be able to allow easy reporting from the database by third party reporting packages. The system must allow an administrative end user to create their own tables in the database through the web based interface. The system must allow an administrative end user to design/configure a user interface (web based) where they can select tables and fields in the system (either our system's core tables or their own custom tables created in #3) The system must allow an administrative end user to create and maintain relationships between these custom created tables, and also between these tables and our system's core tables. The system must allow an administrative end user to create business rules that will enforce validation, show/hide UI elements, block certain actions based on the identity of specific users, specific user groups or privileges.
Essentially it's a system that has some core ticket tracking functionality, but allows the end user to extend the interface, business rules and the database. Is this possible to build in a .Net, Web based environment? If so, what do you think the level of effort would be to get this done? We are currently a 6 person shop, with 2.5 full time developers.
View 5 Replies
Jan 25, 2011
We have a big classic ASP website, and we want to start writing new code in .net, (the website is way to big to rewrite 100% at this stage).
The old website uses session variables, will these still be accessible in the .net pages, and if not (which I suspect) is there anything we can do to make them accessible?
The new section is detachable, that is it is pretty much independent from the rest of the site so should be fine to write in .NET, it's just sessions which are important to us. Do we need another login page?
How bad practise would it be to ajax a local .net page which sets session info when they login to the old site? Can we copy session data this way?
View 1 Replies
Mar 30, 2011
anybody know about different between this.Page and (Page)HttpContext.Current.Handler?i had a problem that this.page returned null, and someone wrote me that using the construct "(Page)HttpContext.Current.Handler" will be better. what the different?why and when this.page return null?
View 2 Replies
Sep 3, 2010
I will be adding new pages and adding functionality to current pages.
I would basically like to use new technology and but I don't know how should I add it to classic ASP pages
In other words, can I <#--include--> an aspx page in Classic asp page? Or anything of that sort, may be creating a user control in ASP.NET and using it in classic ASP?
View 2 Replies
Mar 21, 2010
I'm trying to manually create a button and add a Click event handler for it in code. However when the button is clicked the event handler doesn't seem to react on event (or event isn't called).
we tested the code in Visual Studio 2008 and everything worked just as it should. And I'm using Visual Web Developer 2005 XE. So I assume that I'm missing something to be done manually being in VWD 2005 XE, or the problem is in VWD 2005 XE it self.
here is what I'm doing:
[Code]....
View 9 Replies
Jun 7, 2010
i have problem accessing HttpContext.Current.Application From global.asax its seems to be null every time i try to access it. How can i to this?
HttpContext.Current.Application.Lock();
HttpContext.Current.Application["Actions"] = "hello";
HttpContext.Current.Application.UnLock();
View 2 Replies
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
Oct 13, 2010
I wanted to understand the behavior of HttpContext.Current.Application during the load balancing. I have read that session can be stored in disk hence can be retrieved from different servers. Is this true for HttpContext.Current.Application also. Does the keydata stored in one machine is accessible in other different machine too?
View 1 Replies
Jun 11, 2010
I've found myself having a requirement to configure log4net based on a file relative to the physical location of the running ASP.NET web application. We like to start the logger as early as possible, so Application_Start seems a proper place. In IIS6, this works fine and has been running for ages, but now we moved to IIS7 and this won't work anymore:
string absolutePath = HttpContext.Current.Request.PhysicalApplicationPath;
because the HttpContext.Current is not available in many global.asax (Application, Session) events. This is old news, we all know it raises the now infamous Request is not available in this context error. We don't want to move back to Classic Mode.
Now, the question is simple: without using HttpContext, is it possible to find the physical location of the currently running web application instance?
View 2 Replies
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
Dec 30, 2010
How can i identify just from the HttpContext Object that the HttpRequest coming to my application is from a cookieless application or cookieless browser?
View 2 Replies
Mar 14, 2011
I have an application with an HttpHandler that processes any requests for a .js file. I only want this handler to process *.js files that are requested in the root of the application.
The handler mapping looks like this:
<add name="HandleJS" path="*.js" verb="*" type="MyApp.JsHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
Currently, this handler processes ALL requested *.js files. Here is an example of the behavior I want.
This request would be processed by the handler: http://localhost/myapps/approot/script.js
and this one would not be processed by the handler: http://localhost/myapps/approot/dontProcessMe/script.js
I'd really like to avoid including the full absolute path in the handler path so I tried some other things first.
It doesn't look like the path property of the add element allows the use of the ~/ application root mechanism, so setting path="~/*.js" doesn't work.
I've also tried replicating the StaticFile handler that's built into IIS and doing something like this:
<add name="MyStaticFiles" path="*/*.js" verb="*" modules="StaticFileModule" />
or
<add name="MyStaticFiles" path="dontProcessMe/*.js" verb="*" modules="StaticFileModule" />
Both of which just return a blank response with an HTTP status of 200.
View 2 Replies
Jan 22, 2010
Can anyone tell me the differnce between
System.web.httpcontext.current.application["tag"]
or
System.Configuration.Appsettings["tag"]
View 2 Replies
Feb 6, 2011
I wanna execute same functionality for all DataGrid controls in my application for example.. inserted event handler. but without calling it manually. I mean to be called automatically.Is there anyway to do that ?
View 2 Replies
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
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
Feb 16, 2010
add php Extension to IIS6 and IIS 7 via Code in C# using WMi (System.Management). I cant use DirectoryEntry.
I am stuck with adding a new ScriptMap Object to IIS 6/IIS7.
I have read some posts at here and there and heard that adding new WMi object from Scratch is difficult.
I want to enable IIS 6/IIS7 to handle php as well as aspx files and be able to process them. I have extracted php zip archive to a directory on my system (not installed it). The propblem is i am able to modify existing ScriptMap objects but i dont get to understand the add a new ScriptMap Objects.
Also i am not sure whether adding the a new extensiuon handler to ScriptMap will solve the problem or not.
View 2 Replies
Aug 18, 2010
We usually catch unhandled exceptions in Global.asax, and then we redirect to a nice friendly error page. This is fine for the Live environment, but in our development environment we would like to check if CustomErrors are Off, and if so, just throw the ugly error.
Is there an easy way to check if CustomErrors are Off through code?
View 3 Replies
Nov 4, 2010
I need to dynamically instantiate a web application from a console application. By this definition, I mean that my console application contains a web application that is not bound to IIS/XSP.Currently, I create the web application into a temporary directory and copy some forged files into it. These are a special Global.asax that maps to my own implementation of HttpApplication to use in the web application (I need to do some initialization at app start), then I forge special .asmx files that map to my own skeleton classes and dynamic plugins
foreach (IPlugin plugin in _target.Plugins)
{
WsdlSkeletonDefinition[] defs = plugin.GetWsdlSkeletons();
My approach works, but I'm not so satisfied by it because I have to write lots of garbage into file system, even if I eventually delete it all.I know I can control HTTP handlers via Web.config, but I don't want to forge a Web.config for that. I would like to create a mapping such as I can remove the .asmx extension from web services' URLs and still get them.For example, one of the default scripts is "LogbusManagement.asmx", which must be hard-coded into client APIs and the .asmx prevents portability to other platforms such as PHP. I want to make "LogbusManagement.asmx" equivalent to "LogbusManagement" and any extension. For this, I might use an HttpHandlerFactory.
My straight question is,like asked here by somebody else: is there a way to programmatically, possibly from Global.asax, to set IHttpHandlers or IHttpHandlerFactories for web applications?
View 1 Replies
Dec 2, 2010
I have a folder in my application (UploadsFolder) in which I've been adding images I use for y application. Is it possible to add more images to this folder programmatically online?
View 3 Replies