Using a httpmodule I want to add a meta tag to all pages in my web application at run time. So I need to access the header section of my page. How can I do this in a httpmodule?
You would be better served by inserting this META tag into the header of your site's Master Page (and creating and using a Master Page if you don't already have one.) That give's you a central location for it, while not having the overhead of a module in the pipeline.
If you need to use an HttpModule, see this link about installing a response filter.
You probably want the HttpApplication and the current context of that so you can modify the request and response streams.
Related
I am trying to redirect to a page from the server without referrer. Right now I am doing redirect like this:
I haven't found any overloads for Redirect method or any other ways to redirect without referrer so it's present on the page:
So is there any solution to redirect without referrer in ASP.NET?
You can't handle the referrer from the Redirect method, but you can do one of the following:
Launch the new page on a new window.
Using a meta tag on the content page as follows:
<meta name="referrer" content="no-referrer" />
Or you can add the tag following this answer: How to add meta tag to ASP.Net content page
Move the redirect logic to the front and use rel(attribute specifies the relationship between the current document and the linked document) use:
link
I think you're asking "after my C# server code sends a redirect to the client browser, telling it to go somewhere else, I want the browser to NOT put my site URL into the Referer header when it goes to that somewhere else"
You can't, if it's direct, unless you're redirecting from a secure page (yours) to an insecure page (theirs)
You'll probably have to create an interim page that you redirect to, that has some client side scripting that performs the actual transition (like those "thanks for searching your flight with expedia, please wait while we transfer you to the airline to complete your booking" type pages) because then you can take control of what their browser sends; if you straight refer them, you can't
How do i block of page requests to the website , and make it unavailable (redirect to an error page) for a specific time slot?
You can place a file named app_offline.htm in the root directory of your ASP.NET website and ASP.NET will automatically route all traffic to this html page. In this file you can have any HTML code to show end user that maintenance is currently in process.
Other way of doing the same can be found Here
Insufficient info.But still you can use any of the methods. HTTHandlers in ASP.net Web forms Action Filters in ASP.net MVC. You can just check a flag set in Config file to determine whether to redirect or not if it needs to be configurable. Else you can check specific condition.
I understand that Server.Transfer doesn't make a round trip back to the requesting client.
What I haven't been able to learn is if control is simply passed directly to the new request handler you're transferring to or if or if the entire request life-cycle is executed again.
I assume the entire life-cycle is executed again using the transfer URL but wanted to verify this was the case.
Here is what I found through experimentation.
When using Server.Transfer the entire request life cycle is not ran again.
If you write your own Module, hook it into the request life cycle, and call Server.Transfer from that module the rest of the request life cycle will be skipped and the page life cycle will begin immediately.
After completing the transfer page life cycle the request life cycle picks back up with its tear-down events. Note, the HtppContext in for the tear-down events will be the original one you transferred from. That is, the URL and QueryString values will be the same as the original request and not be the URL and QueryString values for the page you transferred to.
Server.Transfer does modify the HttpContext.Request object to contain the new URL and QueryString information during the page life cycle for the page you transferred to.
If you transfer to a resource that is not a page but is text based (e.g. something.xml) the content of that page will be returned exactly as is with its encoding set to text/html.
If you transfer to a resource that is not a page and is not text based (e.g. something.pdf) then an HttpException error will be thrown. This happens even if you have defined a custom Handler for this resource.
It's just passed along, with its state intact. The request lifecycle does not get run again, although the page lifecycle will run for the page you're transferring to.
http://msdn.microsoft.com/en-us/library/ms525800(v=vs.90).aspx
Server.Transfer acts as an efficient replacement for the Response.Redirect method. Response.Redirect specifies to the browser to request a different page. Because a redirect forces a new page request, the browser makes two requests to the Web server, so the Web server handles an extra request. IIS 5.0 introduced a new function, Server.Transfer, which transfers execution to a different ASP page on the server. This avoids the extra request, resulting in better overall system performance, as well as a better user experience.
This link is also helpful -
http://www.developer.com/net/asp/article.php/3299641/ServerTransfer-Vs-ResponseRedirect.htm
I'm trying to get the list of requests that occur within the confines of a single httpwebrequest from my aspx page.
When using fiddler, you request a page from IE. While doing that request the page requests x number of other files as part of the request. Fiddler shows you that you are getting a .css file, a .js file and maybe its's also requesting a couple other pages from that page before it renders.
I want to be able to make the httpwebrequest from my aspx page then monitor (or list out) the URLs that are being called within that request.
That said I am open to alternate ways to do the request. e.g. IFRAME, etc.
Maybe this just can't be done from an aspx page. Ideas?
If you are using an HttpWebRequest on the server, it is not going to download all of the other embedded resources. If you want to get the list of resources used on the page, you'll have to parse the HTML yourself.
Here's a related questions that might be useful: How can I use HTML Agility Pack to retrieve all the images from a website?
This cannot be done from ASPX page. I think you should hook on one of the Global ASAX events (via writing custom HttpModule) and intercept the requests there.
My app is a very simple "one page" type app-
It has Default.aspx
I'm basically trying to get, for example:
www.myappurl.com/this is my text
I want to get hold of "this is my text" from the above example.
This will be displayed on the page (for now)
I didn't really want to have to use any complext url rewriting things for this...
(My hosting provider uses IIS6)
I tried using a 404 handler, but this is a bit long winded, and i'm using shared hosting, that can't set the "execute url" on custom 404 pages.
Any other ideas?
You can add a mapping for all requests with the * extension to the ASP.NET isapi dll (GET/POST) verbs. You will need to uncheck the "verify file is on disk" checkbox when mapping the extension in IIS. (In IIS7 integrated mode, you map the extension in the web.config as well). Note that this will caause everything to be served by asp.net, even images and script files, which can slow things down.
Then create a handler mapping in your web.config to a http handler you create.
From there, in the ProcessRequest() method of the handler, you have access to the HttpContext that spawned the request and can manipulate the URL from there.
That is the easiest option, you could also create a HttpModule, or have the default page at root redirect to http://www.domain.com/default.aspx/this is my text, in the code-behind of default.aspx, you will be able to get the text following the page and slash.