C# - IIS URL Rewriting - Keep Relative Paths When Serving Multiple Files?

May 25, 2010

My WebApp is part CMS, and when I serve up an HTML page to the user it typically contains relative paths in a.href and img.src attributes. I currently have them accessed by urls like: ~/get-data.aspx/instance/user/page.html -- where instance indicates the particular instance for the report and "user/page.html" is a path created by an external application that generates the content. This works pretty reliably with code in the application's BeginRequest method that translates the text after ".aspx" into a query string, then uses Context.RewritePath(). So far so good, but I've just tripped over something that took me by surprise: it appears that if any of the query string ("instance/user/page.html") happens to contain a plus sign ("+") the BeginRequest method is never called, and a 404 is immediately returned to the user.

So my question is two-fold:

Am I correct in my belief that a "+" would cause the 404, and if so are there other things that could cause similar problems? Is there a way around that problem (perhaps a different method than BeginRequest)? Is there a better way to preserve relative URL paths for generated content than what I'm using? I'd rather not require site admins to install a 3rd party rewrite tool if I can help it.

View 1 Replies


Similar Messages:

HTML Img - ASP Image And Relative Paths

Mar 4, 2011

What is the correct way to reference an image in ASP.NET for live deployment on IIS? The following works in dev and production:

<asp:ImageButton ID="ibnEdit" runat="server" OnClick="ibnEdit_Click" ImageUrl="~/App_Themes/Default/images/one.png" Visible="false" ToolTip="Edit" />

The following doesn't work in either: (why not?)

<img src="~/App_Themes/Default/images/two.gif" />

The following works in dev but not in production:

<img src="../App_Themes/Default/images/two.gif" />

View 2 Replies

URL Rewrite Breaks Root Relative Paths?

Jan 27, 2011

I have a website, lets call it mywebsite.com. I also have a blog at mywebsite.com/blog. I have made a URL rewrite rule so it can be accessed from blog.mywebsite.com. The issue is that all my root relative paths (~/) do not work when viewing the blog from blog.mywebsite.com. Ok, say if there is a link on my blog that goes to a blog post that is at ~/blog/post.aspx?id=1. It will then go to blog.mywebsite.com/blog/post.aspx?id=1 which is actually, mywebsite.com/blog/blog/post.aspx?id=1 and that does not exist.

View 3 Replies

Web Forms :: Relative Paths With Master Pages?

Sep 28, 2010

How do I deal with master pages and relative paths especially when dealing with sub-folders?

View 1 Replies

DataSource Controls :: Uploading Multiple Files To File System And Saving Paths To Database With One Button Click

Jan 20, 2010

I creating a page where our clients can view advertising images and then able to download the images in different file formats. So I need the images and the different download types all saved into the same row in the database so that when I go to display them on the page when they select a picture the right download links will be there. So here where my problem comes in, I don't know how to code it so that I can insert mulitiple file paths into the database at once. The images are saved in a table called images. The downloads are saved in a table called Image Downloads.

Here is the code for the page I have it coded to submit the images to the database but not sure how to add the rest. I have got three different sql datasources for each table not sure if that's the way to go.

[Code]....

View 1 Replies

HTML - Why Does Rewrite Relative Paths For Runat=server Anchor Controls

Mar 24, 2010

I have my UserControls in a ~/Controls folder in my solution:

/Controls/TheControl.ascx

If specify the following:

<a id="theId" runat="server" href="./?pg=1">link text</a>

ASP.Net seems to want to rewrite the path to point to the absolute location. For example, If the control is on [URL] the link href will be rewritten to read

<a id="munged_theId" href="../../Controls/?pg=1>link text</a>

Why does Asp.Net rewrite these control paths, and is there an elegant way to fix it?

I just want the anchor control to spit out exactly what I tell it to!!! Is that so hard?

EDIT:

I've basically done what Kelsey suggested. I knew I could do it this way, but I don't like adding markup in my code when I want something relatively simple. At least it solves the problem:

Aspx page:

<asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>

Code-behind:

var anchor = new HtmlGenericControl("a") { InnerText = "Previous" + " " + PageSize) };
anchor.Attributes["href"] = "?pg=" + (CurrentPage - 1);
anchor.Attributes["class"] = "prev button";
ph.Controls.Clear();
ph.Controls.Add(anchor);

As you can see by the amount of code needed for what is essentially supposed to be be a simple and light-weight anchor, it's not the most optimal solution. I know I could use a Literal but I figured this was cleaner as I'm adding more than one anchor.

View 4 Replies

Serving ISO-8859-1 And UTF-8 Files From C#?

Mar 7, 2011

We have a large site with thousands of static html files. Some of them are ISO-8859-1, others are UTF-8 (with and without byte order marks).

The web.config file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8" />
</system.web>
</configuration>

If I change the fileEncoding to "ISO-8859-1" it works for both ISO-8859-1 and UTF-8 if there is a byte order mark. We are trying to avoid manually checking and adding byte order marks to files that do not have them. Is there any way to accomplish this?

The files have the charset meta tag. Can we make the server read that to determine the file encoding?

EDIT

If I remove the wildcard application mapping to aspnet_isapi.dll the files are served correctly. Is there any way to have the wildcard match everything except for .html?

View 1 Replies

C# - Serving Htm Or Xml Files From ApplicationHost?

Feb 25, 2011

I am hosting the ASP.Net runtime in my exe but I find that if I try to access htm or xml files from the browser, it gives a 404.

I can access aspx, asmx and other asp.net related files just fine.

Is there any configuration that I need to do to server other file extensions and if so, what?

View 1 Replies

Serving Up Multiple Content Items?

Feb 4, 2010

got a Asset Management tool which stores (in a folder("node")) an index.htm and a bunch of other asset files such as .js, .css, flv, etcHere's the problem...if I access the index.htm I get ti via it's nodeID http://site/NODEGUID/index.htm , and all compound files try and download via that GUID as well so essientially I just get index.htm content served into each request file, thus giving me an epic fail :)Is there some way in asp.net to intercept that request so I can do a lookup on the DAM and get the proper file reference and send that down instead?

View 3 Replies

Don't Rewrite Images - Css Files - Js Files At While Url Rewriting With Using UrlRewritingNet

Mar 16, 2010

UrlRewritingNet to my project now i can rewrite urls but i dont wanna rewrite images css files js files etc i only want to rewrite url as you can also guess for example how do i need to edit this code to achive this

<add name="Rewrite" virtualUrl="^~/PokePokedex/(.*)/(.*).aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/Pokedex-Pokemon.aspx?PokemonId=$1&PokemonName=$2"
ignoreCase="true" />

View 4 Replies

JQuery Dialog Serving Multiple Button's Click Event Handler?

Oct 7, 2010

I have a scenario where...

1.) Have created a div with a dropdown list and ok, cancel button

2.) On document ready - registering div created on step 1 into a jQuery dialog

3.) on a javascript button click - I am opening this dialog box.

4.) Now, the problem is - the jQuery dialogbox which I have created, needs to be used by other button clicks as well on same page. Now, my div's (which is a dialog at runtime using jQuery) ok button click is already engaged with a javascript function (button1 click) and I can not associate other button's click events with it - thus stuck up here and have no clues or hit to resolve this.

View 2 Replies

Web Forms :: SiteMap With Multiple Paths To Same Page?

Jul 20, 2010

I have a sitemap, and i'm using nested repeaters to display the parent and child nodes for my breadcrumbs.I have 3 pages: Home, Hub, and Search.Each of these pages can navigate to each other. In other words:

Home> Hub
Home> Search
Home> Hub > Search
Home> Search > Hub
Home > Default

The most common path would be "Home > Hub" and Home > Search > HubHowever, I can't seem to figure out how to show this on my breadcrumbs, since you can't have multiple ULR's in the Sitemap. Right now, you can only go "Home > Hub". If you go from "Search" to "Hub...it should show "Home > Search > Hub" in the breadcrumbs.

View 5 Replies

Multiple Paths In Location Element Of Web.config?

Dec 20, 2010

How to specify multiple paths in one location element in web.config:, a

<location path="Images">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>

We would like to add styles and images to location, e.g. location path="images, styles". Is it possible to put multiple paths in location element (and how)?

View 2 Replies

SQL Server :: Table Cause Cycles Or Multiple Cascade Paths?

Oct 4, 2010

i have a table that contains 3 forign keys, 2 of them from the same table when i make Delete Rule Cascade,this error message appears

'Customers' table saved successfully
'Order' table
- Unable to create relationship 'FK_Order_Customers1'.

Introducing FOREIGN KEY constraint 'FK_Order_Customers1' on table 'Order' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint. See previous errors. what is solution,as i want when i delete data from master table ,all dependent (child) data automatically deleted, so i use Cascade.

View 2 Replies

Configuration :: URL Rewriting Static Files Like CSS?

Nov 2, 2010

How do I rewrite the url for static files? When adding something like

RouteTable.Routes.MapPageRoute("test", "style/style.css", "~/Static/Styles/Public.css");

I just want the url /style/style.css to point to another static file on the webserver..

I'm getting this error:

There is no build provider registered for the extension '.css'. You can register one in the <compilation><buildProviders> section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'.

View 5 Replies

Relative Urls For Images And Js Files In MVC Application - Diff Behaviour On Local And Production Server?

Mar 13, 2011

I have an MVC web application, the urls like following in my views folder:

<img src="../../Images/Delete.png"/>

are working on my localhost, but when I deployed the application on production server, they stopped working and when I use single ".." instead of double "../.." , they start working on production server.

View 2 Replies

Web Forms :: URL Rewriting Without Multiple Slash

Sep 24, 2012

How to rewrite my url from

http://www.mysite.com/8
to
http://www.mysite.com/home.aspx?id=8

I want only one slash after my domain name as

http://www.mysite.com/8 
not as
http://www.mysite.com/home/8

View 1 Replies

Postback - Multiple Page_Load Events With URL Rewriting?

Feb 18, 2010

Im using intelligencia urlrewriter as my url rewrite module. I have one very strange problem which only occurs when an url is rewritten but to make it more fun, not on all rewritten pages. Edit: Forgot to tell you what's the problem boing boing. the problem is that my Page_Load event gets fired 2 times.his is how my form rewrite adapter looks like:using System;

using System.Web.UI;
using System.Web;
using System.Web.UI.WebControls;

[code]...

View 3 Replies

Architecture :: Allowing Access To Multiple Customers For One User With Url Rewriting

Jan 27, 2010

I am currently developing a solution in which the user logs in once and can work on multiple customers at the same time on my site.I've looked at all possible solutions involving sessionid having stored the customerid, to launching a new browser session so i could have multiple sessions for one users etc. I also looked at using cookieless sessions.But the all fail because it's not a simple solution and in my opinion a simple solution is most of the time a good and predictable solution.

Therefore i came up with the idea to use url rewriting(i've seen this used in other applications). When the user opens a customer, i would like to start his url as follows "~/Customers/xxxxxxx/*.aspx" where xxxxxx represents the customerid. and *.aspx represents a complete subset of pages of my site. This would allow me to use a simple technique to use multiple user sessions within a single asp.net session.

Now coming to my problem, I have never done some url rewriting, therefore my questions:

- Is this possible.

- Can i protect all the pages that need a customerid as input(come to think of it, if no customerid in the querystring, redirect to a selection screen would be sufficient).

- How do i adopt all urls used in a sitemap etc in a structured way.

View 3 Replies

Configuration :: ResourceManager And Resx Files - Files To Display Items In Multiple Languages

Oct 13, 2010

I have an application that uses resource files to display items in multiple languages. My app uses quote a lot of javascript and the alerts need to display in the local language. To do this, I have created an http handler which will read the keys and values of the culture-specific resource file and write them to a JSON array which is then embedded in the page in a script tag, the messages can then be accesses using, for exmaple:

Message.Error (en-GB = "Error", fr-FR = "Erreur")

The messages http handler works great in development, however when I run the application on a test server, I get the error: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Resources.Alerts.resources" was correctly embedded or linked into assembly "App_GlobalResources.b0n9j90e" at compile time, or that all the satellite assemblies required are loadable and fully signed. The code that I use to acccess the resource file is:

ResourceManager manager = Resources.Alerts.ResourceManager;
ResourceSet resourceSet= Resources.Alerts.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true);

Where Resources.Alerts is the type that contains my multi-lingual definitions. The build action for the Alerts.resx file is set to "Embedded Resource". Any ideas why this works locally but not on my test server, am I missing something?

View 1 Replies

Web Forms :: URL Rewriting - Looking For Easiest Way To URL Rewriting

Apr 10, 2010

I am trying to implement URL rewriting technique in my Web application.I have found some articles on net 2 rewrite URL. But i m not able to understand. tell me any API or DLL which will take care of all url rewriting techniques in my Web applications.

I have heard something abt UrlRewriter.ddl . But i have not used it yet. provide me the easiest way to do that. If any sample application is there then it will be better ti understand

View 4 Replies

How To Get Multiple Overlapping Config Files For Multiple Solutions

Mar 30, 2011

I'm very new to ASP.net, so I'm just figuring this out.First off, I have multiple separate projects that will be hosted on the same server.Second, they must be able to share certain settings (like connection string, configuration options, etc).Third, those shared settings must be configurable for different deployments (test, prod, etc).

View 1 Replies

C# - XML Parseing Error When Serving A PDF

Apr 13, 2010

I'm trying to serve a pdf file from a database in ASP.NET using an Http Handler, but every time I go to the page I get an error

XML Parsing Error: no element found
Location: https://ucc489/rc/NoteFileHandler.ashx?noteId=1,msdsId=3
Line Number 1, Column 1:
public class NoteFileHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
[code]...

View 1 Replies

Scaling And Serving Images With .NET 3.5?

Oct 27, 2010

I am working on a web application where images has to be scaled dynamically and served to the client as fast as possible (with low overhead). I need to create something that scales and compresses high-quality PNGs to medium quality JPEGs.Now, there are multiple ways of doing this and I am slightly confused which method provides the best solution for the application to be as fast as possible - and I was hoping you guys could guide me in the right direction.This application will run on the .NET 3.5-platform and I am looking for fresh ways of doing this. Googling has given me some clues but most of the articles I found were VERY old (2000-2005 or so).The client app is written in ASP.NET MVC, while the backend app is written in Web Forms. The images are located in a directory in the Web Forms application, but I guess that dosen't say the image handler must be written in Web forms.

View 3 Replies

Serving Videos From Amazon S3?

Dec 17, 2010

If I host video or any other media content on Amazon S3, how can I use ASP.net Membership to enforce access rights?

View 1 Replies







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