Intercept Output From Default Handler With Another HttpHandler?
Mar 18, 2011
I have set up an HttpHandler for *css to do some simple parsing:
<handlers>
<add name="CssHandler" verb="*" path="*.css"
type="MyApp.CssProcessor,MyApp.Assembly"/>
</handlers>
All was well until I added a resource that loads a css file dynamically, e.g.
<link rel="stylesheet" type="text/css" href="/loader.ashx/module.resource.css" >
To my surprise, things went horribly wrong. The custom http handler intercepts this, but since it's designed to just load files from the file system, it doesn't work. I realize that, technically, it matches a pattern *.css but that seems an odd behaviour, since the actual resource being requested from the web server is *.ashx and the css is only after the file path, as a parameter.
Is it possible to make the filter for a handler only apply to the actual server resource name?
Alternatively (and actually I'd like to know how to do this anyway) -- what I would really rather be doing is intercepting the output from the default css handler. That is, rather than having all my own code to actually load files from the file system in my CSS handler, it seems it would be far simpler to just take the response from the default handler and filter it. Which would have worked properly in this situation.
Finally, in either case, I'd much rather be filtering on resource MIME type text/css rather than intercepting requests by name, since what I really want to do is filter any CSS (rather than anything that happens to be named "*.css"). how to do this?
View 1 Replies
Similar Messages:
Jan 5, 2011
Is there some way to intercept the HTML output stream in asp.net and make modifications? Eg using httpmodules or something? I know this is possible using java servlets and assume there must be an elegant way to do this with asp.net.
My purpose is to combine the many javascript files into one composite script which has been minified/packed, to make the page load faster.Eg, if my page normally outputs the following in the page head:
<script type="text/javascript" src="/scripts/blah.js"></script>
<script type="text/javascript" src="/scripts/yada.js"></script>
I want to replace that with the following:
<script type="text/javascript" src="/scripts/all.js"></script>
(also i realise i'll have to create all.js somehow).
View 2 Replies
Aug 23, 2010
I am formatting html in my admin page and wants to send this html as part of Response object. I am redirecting to HttpHandler (Preview.ashx) using Response.Redirect, but how am I supposed to send that html within response and read it from httphandler using HttpContext object in my Handler?
View 4 Replies
Dec 28, 2010
I have IIS 7.5 with an ASP.NET application. The application must run with IIS Classic Mode.
I have one HttpHandler that serves all the Request:
<httpHandlers>
<add verb="*" path="*.aspx" type=".....HandlerFactory..." />
</httpHandlers>
The problem is that i can't establish a Default Document to an non phyisical file. I want that the Default Page be : Home.aspx (which is a non phyisical file).
So when I go: [URL] I get an error: HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.
I do not want to make a REDIRECT.
Is there any way to accomplish this without having to create a index.html to redirect to Home.aspx?
View 2 Replies
Jun 8, 2010
I'm using output caching in my custom HTTP handler in the following way:
public void ProcessRequest(HttpContext context)
{
TimeSpan freshness = new TimeSpan(0, 0, 0, 60);
context.Response.Cache.SetExpires(DateTime.Now.Add(freshness));
context.Response.Cache.SetMaxAge(freshness);
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetValidUntilExpires(true);
...
}
It works, but the problem is that refreshing the page with F5 leads to page regeneration (instead of cache usage) despite of the last codeline:
context.Response.Cache.SetValidUntilExpires(true);
UPD: Seems like the cause of problem is that HTTP handler response isn't caching on server. The following code works well for web-form, but not for handler:
Response.Cache.SetCacheability(HttpCacheability.Server);
Are there some specifics of the caching the http handler response on server?
View 2 Replies
Apr 22, 2010
I am trying to use output caching on my .net pages but it is not working when I use Route handlers to redirect request to actual page, but it works when I call the page directly.
also one more weird thing is that when I am debugging and using .net instance of IIS http://localhost:64293/test it is working, but when I deploy it and try to call the page it is not caching i.e. http://www.mydomain/test(but it works if I call the page directly)
I am using VS 2010, IIS 6.0, .net Framework 4
aspx page code is :
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" Title="Not Found" %>
<%@ OutputCache Duration="300" VaryByParam="*" Location ="Server" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
litPageTitle.Text = "<br/>Datetime: " + DateTime.UtcNow.ToString();
}
</script>
my global.asax.cs code is
public static void RegisterRoutes(RouteCollection routes)
View 2 Replies
Mar 18, 2011
I've created a simple sample site to demonstrate the issue. In it, I have a Default.aspx Page that has a button on it:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<p><asp:Button OnClick="ButtonClick" Text="Button" runat="server" />
</p>
<asp:Label ID="output" runat="server" />
</asp:Content>
The code behind just sets the label text on the button click:
protected void ButtonClick(object sender, EventArgs e)
{
output.Text = "Button Click!!";
}
I then have an IHttpModule that gets called for every request:
[code].....
And now it's broken again! So to make a long story short, just by accessing the Form collection on the request in the IHttpModule, I somehow screw up the PostBack, and the event never gets fired.
View 2 Replies
Apr 18, 2010
First off, suggest better ways if you want rather than patch up this code. I am just starting this project and it is first time I have tried to code a web site so anything you suggest is very much welcomed. I have spent the last 2 and 1/2 days trying to find workable answers to this but none I have found and tried seem to fit. If needed I can email screens shots or code. I am trying to construct a website that will have the same main theme throughout as far as the header, navbars sitemap, and footer go. Naturally the content will vary from page to page. I want to use a single master page and css stylesheet for this main theme and I will change the content format as needed per page because each page may vary somewhat.
However, about 15 of the pages will all use the same format for their content and this format will differ from the rest of the site but the format of the main theme will stay the same. So I am trying to create a nested master page to use to format the just the content area for all these pages while retaining the main theme for the header, etc.. I believe I should use a separate css file with the nested master page to handle the formatting of the content areas for these 15 pages. I have code that looks like it works when viewed in web developer but design view but does not work when viewd through a browser (IE, Chrome, Firefox). So far I have the following done in web developer.
If it helps the code and screen shots follow. Master Page called "Parent.master". For all theme throughout site Nested Master Page called "Lab.master". For the 15 like pages Primary stylesheet file for main theme called "StylesheetNew.css" For site theme Secondary stylesheet file to syle the 15 like formatted pages. It is called Labmaster.css Labs.apsx file to use as first of the 15 like pages.
Finally screens shots from web developer and browser. Sorry try as I might I could not capture screenshots and put them into this post. The problem is that web developer shows all the area (many lines high) with gray background and with the XXX text that I want to allocate for content in the 15 pages. Yet all the browser show is one line of text o a white background followed by the footer. It looks like the LabStyleSheet works in Web Developer but not in a browser.
Parent.master
<%@ Master Language="VB" CodeFile="Parent.master.vb" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]">
<html xmlns="[URL]">
<head id="ParentHeader" runat="server">
<title>HX5</title>
<asp:ContentPlaceHolder runat="server" id="headerPlaceHolder" />
<link href="~/StyleSheetNew.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="wrapper" >
<div id="Header" >
<table class="hdrtbl1" >
<tr>
<td id="hdrtd1" style="width:175px; height:100px;" >
<img id="logo" alt="Logo" src="../Images/logo.png" style="width: 136px; height: 87px" />
</td>
</tr>
</table >
<table class="hdrtbl2" >
<tr><td id="hdrtbl2td1"><b> Providing Professional Technical, Manangement and Business Solution</b></td></tr>
<tr><td id="hdrtbl2td2"> <b> Services since 2004 </b></td></tr>
<tr> <td id="hdrtbl2td3" align="center" ><img id="rdln" alt="RedLine" style=" height:3px;" src="../Images/RedLine.png" /></td></tr>
<tr><td id="hdrtbl2td4" > <b>Committed to Excellence In All We Do</b></td></tr>
</table>
</div>
<div id="navbardiv">
<ul id="topnav">
<li><a href="../pages/about.aspx" >About Us <img style=" border: none; " src="../Images/arrow-down.gif" /></a>
<!--Subnav Starts Here-->
<span>
<a style="font-weight:lighter; " href="#" >Who We Are </a> |
<a href="#">Locations</a> |
<a href="#">Business Classifications</a> |
<a href="#">Contact Us</a> |
</span>
</li>
<!--Subnav Ends Here-->
<li><a href="../pages/services.aspx">Services <img alt="arrow" style="border: none; " src="../Images/arrow-down.gif" /></a>
<!--Subnav Starts Here-->
<span>
<a style="font-weight:lighter; " href="#" >Capabilities</a> |
</span>
<!--Subnav Ends Here-->
</li>
<li><a href="#">Customers <img style=" border: none; " src="../Images/arrow-down.gif" /></a>
<span>
<a style="font-weight:lighter; " href="#" >Subnav Link</a> |
<a href="#">Customer Locations</a> |
<a href="../pages/labs.aspx">Labs</a> |
</span>
</li>
<li><a href="#">Careers <img style=" border: none; " src="../Images/arrow-down.gif" /></a>
<!--Subnav Starts Here-->
<span>
<a style="font-weight:lighter; " href="#" >Joining the HX5 Team</a> |
<a href="#">Current Opportunities</a> |
</span>
</li>
</ul>
</div>
<div id="subnavbar" >
<!-- <asp:SiteMapPath ID="SiteMapPath" runat="server">
</asp:SiteMapPath> -->
</div>
<div id="topContent" style="border-bottom:solid 1px #191970;">
<table>
<tr><td style="height:30px; width:900px;" >
<asp:ContentPlaceHolder id="TopPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
<!-- <div id="mainContent"> -->
<asp:ContentPlaceHolder id="MainPlaceHolder" runat="server" />
<!-- </div> -->
<!-- <div id="lowerContent"> -->
<asp:ContentPlaceHolder id="LowerPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
<!-- </div> -->
<div id="footerContent" style=" height:50px; width:900px; text-align: right; background-color: #ccc; ">
<span style=" font-family: Arial, Helvetica, sans-serif; font-size: xx-small; font-weight: bold; color: #000080; margin: 30px 20px 0px 0px;"> Copyright 2010 HX5, LLC All rights reserved</span></div>
</div>
</form>
</body>
</html>
View 4 Replies
Jan 24, 2011
I create custom HTTP handler for auto generating file and I want to tell IIS7 to serve current request like normal static file because I need to use IIS and web.config file to control compression setting and any other HTTP header of current requested file.I know. there is an internal class called StaticFileHandler in ASP.net. But I cannot access it. Or you have any other way to work like this.
View 1 Replies
Feb 10, 2010
I want to intercept any postbacks in the current page BEFORE it occurs . I want to do some custom manipulation before a postback is served. how to do that?
View 5 Replies
Jan 13, 2011
I have a control used in our CMS and we don't have the source code for it, what I would like to do is change the rendered output of this control.
Now, I could have a check in my base Page class that checks if the control is being used on the page and then change the html that needs to be altered, but that seems a bit excessive for just 1 usage.
So is there any other way of changing the behaviour of the control without the source code? I'm thinking not other than the way described above.
View 1 Replies
Feb 14, 2011
I am implementing HttpModule for compressing request.Below is the codee for HttpModule:
public class Global : IHttpModule
{
public void Init(HttpApplication app)
{[code]....
It's able to intercept and compress js and css in the development web server but when i run it from IIS 5.1 it is not able to compress js and css files.
View 2 Replies
May 28, 2010
I would like to generate a 401 page if the user does not have the right permission.
The user requests a url and is redirected to the login page (I have deny all anonymous in web.config). The user logs in successfully and is redirected to the original url. However, upon permission check, it is determined that the user does not have the required permission, so I would like to generate a 401. But Forms Authentication always handles 401 and redirects the user to the login page.
To me, this isn't correct. The user has already authenticated, the user just does not have the proper authorization.
In other scenarios, such as in ajax or REST service scenario, I definitely do not want the login page - I need the proper 401 page.
So far, I've tried custom Authorize filter to return ViewResult with 401 but didn't work. I then tried a normal Action Filter, overriding OnActionExecuting, which did not work either.
What I was able to do is handle an event in global.asax, PostRequestHandlerExecute, and check for the permission then write out directly to response:
if (permissionDenied)
{
Context.Response.StatusCode = 401;
Context.Response.Clear();
Context.Response.Write("Permission Denied");
Context.Response.Flush();
[code]....
First of all, I'm not even sure if that is the right event or the place in the pipeline to do that.
Second, I want the 401 page to have a little more content. Preferably, it should be an aspx page with possibly the same master page as the rest of the site. That way, anyone browsing the site can see that the permission is denied but with the same look and feel, etc. but the ajax or service user will get the proper status code to act on.
View 3 Replies
Feb 17, 2010
I am working on a tool which audits access to existing web application. Existing app does not have any hooks in place, but my plan is to inject an IHttpModule by modifying web.config and log whatever I need to log during EndRequest event.
What I'm struggling with right now is: I cannot intercept what is application writing to an output stream. I need to know what output does the application send to the client. Originally, I hoped I could run a code in BeginRequest to replace HttpContext.Response.OutputStream with a stream of my own, which would be flushed to original stream during EndRequest, but the stream only has a get accessor, so I cannot replace it.
I could of course use reflection to assign to private member of HttpContext.
View 2 Replies
Feb 28, 2011
n my A.aspx, I will call web method GetName in B.asmx
Is it possible, before my A.aspx call GetName in B.asmx, I inject or put some codes so when A.aspx try to call the method, it needs to go through my injected code without even changing the code in A.aspx and B.asmx?
Is custom HttpModule able to handle this scenario? If yes, how? Which HttpModule's event that occurred before the page actually called the web service?
View 2 Replies
Nov 30, 2010
I have user's who are losing their data because they sit on a page too long, then are asked to log back in. I want to do the following:
1) Instead of redirecting them to a login page, I want to cancel the current request and give the user a popup dialog box to login with.
2) When the login is successful, I want the user to be sent back to their form, with all data intact. (Even better if the request could go through without sending them back to that form, but this is optional).
How can I intercept these authentication requests, and present the user with a popup login?
I am using ASP.net forms authentication.
View 2 Replies
Jul 1, 2010
I wish to be able to place a System.Web.ActionFilterAttribute on an Action Method and override the OnActionExecuting method to insert business logic which determines if the Action should be fulfilled. Can the ActionExecutingContext be used to cancel the executing Action Method and do one of the following:
Send an HTTP Status Code (and the corresponding <customError> page).Execute a different Action Method within the same Controller.
View 2 Replies
Mar 24, 2010
i hava a gridview, with an sqldatasource control, if an update event goes to faili want intercept the error and manage ithow can i do? i cannot find the error event in gridview
View 2 Replies
Mar 25, 2010
I have installed an HttpModule into my web app that will handle all requests with a given file extension.
I want ASP.NET to handle all requests with the extension, regardless of whether there is an underlying file on disk. So, when I added the extension to the 'Application Extension Mappings', I unchecked the 'Verify that file exists' checkbox.
However, this just transfers the file check to ASP.NET rather IIS, so I just get a different error page when requesting URLs with the file extension.
Is there a way to preempt this ASP.NET file checking and intercept the requests?
View 2 Replies
Mar 15, 2010
I have a small 4-page application for my customers to work through. They fill out information. If they let it sit too long, and the Session timeout out, I want to pop up a javascript alert that their session has expired, and that they need to start over. At that point, then redirected to the beginning page of the application.
I'm getting some strange behavior. I'm stepping through code, forcing my Sessioni.IsNewSession to be true. At this point, I write out a call to Javascript to a Literal Control placed at the bottom of the . The javascript is called, and the redirection occurs.
However, what is happening is.. I am pressing a button which is more or less a "Next Page" button and triggering this code. The next page is being displayed, and then the Alert and redirection occurs. The result I was expecting was to stay on the same page I received the "Timeout", with the alert to pop-up over it, then redirection.
I'm checking for Session.IsNewSession in a BaseClass for these pages, overriding the OnInit event.
View 1 Replies
Mar 24, 2010
We send out registration urls to clients via email. Some of the email clients are turning the url intourl <url>I think it may be happening when users forward the email onto themselves at which point the email client re-formats the original email (maybe)[URL]Which rightly producesSystem.Web.HttpRequestValidationException: A potentially dangerous Request.QueryString value was detectedWhere in the code should I intercept these instances and santize the url so that the user is re-directed onto the original form of the url?
View 1 Replies
Sep 20, 2010
I need to get notified about asynchronous requests in ASP.NET. I used the jQuery .ajaxSend global event but it does not trigger when using UpdatePanels.
Is there a multi-browser way to detect when a request is being made on a page?
View 1 Replies
Sep 11, 2010
I'm looking for a way to intercept the ASP.NET processing pipeline in such a way to be able to register event handlers to all events on the Page class. The reason is, I need to maintain a session-bound instance of a component that needs to be notified of all important Page events, starting from OnPreInit.
There's an arbitrary number of Page descendants in the application, which are not under my control. Hence I cannot use an approach like using a single custom descendant, that would notify the session-bound component, as a base class for all pages in the web application.
I don't think creating a custom IHttpHandler or IHttpModule implementation would solve the problem. Also note I cannot create a custom HttpApplication descendant.
View 2 Replies
May 10, 2010
This question seems to be pretty close to what I am looking for - I was able to setup tracing and I am looking at the log entries for my calls to the service.However I need to see the raw soap request with the data I am sending to the service and I see no way of doing that from the SvcTraceViewer (only log entries are shown but no data sent to the service) - am I just missing configuration?
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Verbose"
propagateActivity="true">
[code]...
View 1 Replies
Oct 22, 2010
i have a e-commerce page which send data to last page for the payment...
In this last page, the user confirm his intention to acquire products .... In this moment, i've created a sub which insert a new order in the database...all works!...
The problem born when i try (and user could too) to manually refresh the page...the code will be processed again and a new (second) order will be inserted in the database.....it's not correct...
This page make a postback after confirm button....so control page.ispostback will not resolve problem...
How could i intercept manual refresh of this page in a secure way ?
View 7 Replies