i am using URL rewriting in my asp.net application using regx
virtual URL is
/ProductDatabaseCMS/(?<category>w*)/Product/(?<product>w*).aspx
original URL is
/ProductDatabaseCMS/Product.aspx?PROD_ID=${product}
application path is ~/ProductDatabaseCMS
my application has master page that uses style sheet and the path is
~/App_Themes/Styles/Style_Sheet.css
i am requesting the URL
/ProductDatabaseCMS/(?<category>w*)/Product/(?<product>w*).aspx
from one of the webpage of application using Hyperlink control but in that case stylesheet is not working for this page Because it is taking path
~/ProductDatabaseCMS/(?<category>w*)/Product/App_Themes/Styles/Style_Sheet.css
what i have to do in this case.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If you use a relative URI to reference the external stylesheet, you have to consider this: Relative URIs are always resolved from a base URI which is the URI of the current resource if not declared otherwise.
So if you request /foo/bar and there is a relative URI reference css/baz.css in the HTML document, it would be resolved to /foo/css/baz.css as /foo/bar is the base URI.
To solve this problem you have two options:
- use absolute URIs or at least absolute paths to reference the resources (e.g.
/App_Themes/Styles/Style_Sheet.css), or - set a suitable base URI using the
BASEHTML element (e.g.<base href="/" rel="nofollow noreferrer noopener">) so that every relative URI is resolved from that new base URI.
Method 2
Use a “root-relative path” for the CSS href. You start the href with “/”, that’s all.
Try: /App_Themes/Styles/Style_Sheet.css
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0