I've just installed subtext and am intending on hosting on discountasp.net. I want to add my own pages to the application (just 3) but if I add a standard aspx I get a 404. I'd ideally like to have a masterpage that uses some of the list controls in subtext so I can keep a list of Recent Posts and Archive on the side bar. It's an ideal, otherwise I could create a couple of my own controls to drop into the page to replicate IF that's not possible.
Any ideas?
Note: This applies to Subtext 2.1.2 and below
You'll need to add a handler mapping in web.config. Subtext tries to handle all requests.
The easiest thing to do is to create a directory where you want all your custom pages to live and map a PageHandlerFactory for that directory.
For example, search for the following in web.config
<add verb="*" path="HostAdmin/*.aspx" type="System.Web.UI.PageHandlerFactory"/>
And add the following line after
<add verb="*" path="custompages/*.aspx" type="System.Web.UI.PageHandlerFactory"/>
In the upcoming Subtext 2.5, you won't need to do this. You can simply drop your page anywhere in a directory and it'll just work.
Related
I have a client who has a huge site that would better serve their visitors if split up into two separate sites. So now I'm trying to split it up, while still sharing certain files between the two (essentially, the only thing that changes is the navigation and pages; the header, footer, and styling should all be the same between the two sites).
So now I am trying to create an If Else statement in ASP.net and VBScript that will switch out certain elements based on what the site's root file path/url is going to be. So far, it looks something like the following:
<% If objPage.FilePath = "/" Then %>
Show Content A
<% Else %>
Show Content B
<% End If %>
Which doesn't really help me as it only seems to effect the home page and not the other site pages. How might I change it to trigger based off the site address or, failing that, is there a variable I can stick in the quotes that will affect not just the root files, but all the subpage files as well?
Also, is there a better way to be going about this?
How about have a web.config setting which defines the flavour ?
For example:
<appSettings>
<add key="SiteFlavour" value="site1" />
<!--<add key="SiteFlavour" value="site2" />-->
</appSettings>
Then simply replace your conditional
objPage.FilePath = "/"
with a test based upon the config setting ?
This has the additional benefit of making testing easier, as you're not reliant upon a specific URL.
It also makes adding a third flavour quite straight forward.
You can always pull out the setting from config in your app start up (global.asax ?) if that helps.
Whats the right way to change the url for all the images on my site to use a cdn url or not based on a web.config value.
I have this web.config value
<add key="UseCDN" value="1"/>
now my page has a whole bunch of <\asp:image imageurl="RELATIVEPATH" tags.
I want them to point to my machine when "useCDN" = 0 and to cdn.com\RELATIVEPATH when "useCDN" = 1
whats the best way to do this?
For you to implement a cross cutting solution, you have to extend the image control class and override the Render method to use the use the CDN value (if in production).
Or just create a normal ASCX user control and use it. Can't search now but a simple search will get you plenty of tutorials.
UPDATE:
A tutorial to help you do it
So I currently use BundleTransformer, LESS and I'm trying to add the Autoprefixer post processor. This plugin automatically takes css like transform: scale(1.5) and converts it to -webkit-transform and -moz-transform.
If I am in release mode or have BundleTable.EnableOptimizations=true then everything works just fine and the prefixes are added as expected.
In debug mode however, all the individual CSS / LESS files in my bundle are present in the HTML as separate requests. I'm using this command in my CSHTML file:
#Styles.Render("~/Content/css/lessbundle")
i.e. In debug mode this gets expanded out to LINK tags for :
/cs/something.css
/css/lessfile1.less
/css/lessfile1.less
instead of a single file
/Content/css/lessbundle?v=RFAUSIwb-jEuuo4vHNTnTkE2LrN2jfHglX-Hk8HIF481
For the LESS files IIS automatically converts them, however it does not apply the Autoprefixer.
Is there a way to get Autoprefixer to work when requesting raw .css and .less files?
If not it seems kind of pointless to me because the only alternative I see is to request directly the 'Content/css/lessbundle virtual URL - which will get run through the Autoprefixer. It will only get minified for a release build.
In the documentation (sections: “Examples of usage”, “Debugging HTTP-handlers” and “Postprocessors”) describes how to solve this problem. I will list the basic steps:
For debugging HTTP-handlers to use a configuration settings from bundles need to add in the RegisterBundles method of App_Start/BundleConfig.cs file the following code:
BundleResolver.Current = new CustomBundleResolver();
In order to these settings can be applied to CSS- and JS-assets need to register the debugging HTTP-handlers CssAssetHandler and JsAssetHandler in Web.config file. To do this in the IIS Integrated mode, you need add to the /configuration/system.webServer/handlers element the following code:
<add name="CssAssetHandler"
path="*.css" verb="GET"
type="BundleTransformer.Core.HttpHandlers.CssAssetHandler, BundleTransformer.Core"
resourceType="File" preCondition="" />
<add name="JsAssetHandler"
path="*.js" verb="GET"
type="BundleTransformer.Core.HttpHandlers.JsAssetHandler, BundleTransformer.Core"
resourceType="File" preCondition="" />
To make AutoprefixCssPostProcessor is one of the default CSS-postprocessors, you need to make changes to the Web.config file. In the defaultPostProcessors attribute of \configuration\bundleTransformer\core\css element must be add AutoprefixCssPostProcessor to end of comma-separated list (for example, defaultPostProcessors="UrlRewritingCssPostProcessor,AutoprefixCssPostProcessor").
In addition to what #Taritsyn said you need to make sure your bundles are
CustomScriptBundle() and not ScriptBundle()
If not you will get the slightly confusing error message:
Could not find the transformer in the '~/Content/css/myCssBundle' bundle.
I found it interesting to look deeper into how this actually works
The HTML is written (just view source) with an additional parameter ?bundleVirtualPath
/Content/css/defenderrazor_DEBUG.less?
bundleVirtualPath=~%2fContent%2fcss%2fmyCssBundle
This is intercepted by the handler in the web.config when a .less file is requested and the handler is then able to use that bundle name to look up any transformations that you've set - including in this case the default post processor for AutoprefixCss.
For SEO reasons we are about to face a major refactoring for a ASP.NET website. To please SEO engines most of .aspx pages will be renamed. The problem is that these pages are referenced all over the web and we absolutely need to avoid to break these links, nor the SEO ranking boost that comes from these links.
Three questions:
A) Is there a common way to handle this?
B) I'd like to centralize in a C# file or an ASP.NET or IIS config file, a redirection table, something defined like:
{ "Page1OldName.aspx", "Page1NewName.aspx" }
{ "Page2OldName.aspx", "Page2NewName.aspx" }
{ "Page3OldName.aspx", "Page3NewName.aspx" }
...
I am aware of the Response.Redirect() method. I can imagine an ugly way to intercept page-not-found error and then use Response.Redirect() coupled with the redirection table, but it doesn't look clean. Is there a cleaner way?
C) Do such redirection could/will provoke SEO ranking penalty?
you can try to use UrlMapping in webconfig.
Test001 is the old url.
Test002 is the new.
<system.web>
<urlMappings>
<add url="~/test001.aspx" mappedUrl="~/test002.aspx" />
</urlMappings>
</system.web>
I'm trying to create theme for Orchard CMS. The template I have wasn't made for it so I have some troubles displaying images from Layout.cshtml.
This is the current folder structure on my web server (theme folder structure only):
Theme/Content/Images/Image.jpg
Theme/Views/Layout.cshtml
Theme/Styles/Site.css
The following line doesn't display image (located in Layout.cshtml):
<img src="../Content/Images/bgBig.jpg" alt="Big background image" />
However, this line does display the image (located in Site.css):
background-image:url('../Content/Images/bgLines.png');
I believe the problem is that Layout.cshtml doesn't display the image from Theme/Views/Layout.cshtml, but from the other location. If someone knows what would be that location or how to override it I would be thankful.
I might be a little late, but this may be of help to others.
To get the current theme and then build an dynamic path (as opposed to an absolute path) use this:
WorkContext.CurrentTheme: Gets the current working theme ExtensionDescriptor.
Then give it to the Html.ThemePath URL builder:
Ex.
Html.ThemePath(WorkContext.CurrentTheme, "/Content/Images/SomeImage.png")
Have fun!
Best regards,
Tiago.
When adding images in Layout.cshtml you should use the full path to your theme (eg. /Themes/My.Theme/Content/Images/MyImage.jpg). Remember that the paths you provide in [img] tag are relative to the URL in browser, not the path on the server. In MVC those are almost never equal.
Layout.cshtml view file gets loaded as a part of every single request, so relative paths placed inside will almost always break.
Imagine you have two Orchard pages: site.com/mypage and site.com/something/mypage. Layout.cshtml gets rendered in both of them. Relative URLs working for the first will surely break when you access second one.
CSS stylesheets are loaded directly by specifying absolute path to the physical files in /Themes/YourTheme/Styles folder (default), so in this case relative URLs will work.
HTH
Thx Tiago for your solution. I think this is in fact the correct solution, as opposed to linking the full path which I think would require the Orchard site to be on the root of the domain.
The full image reference of the original question would look like this:
<img src="#Url.Content(Html.ThemePath(WorkContext.CurrentTheme, "/Content/Images/bgBig.jpg"))" alt="Big background image" />
I'm surprised that nobody's mentioned that you need the following web.config in the folder in which your images/scripts/styles reside (see the orchard docs)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<httpHandlers>
<!-- iis6 - for any request in this location,
return via managed static file handler -->
<add path="*" verb="*" type="System.Web.StaticFileHandler" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers accessPolicy="Script,Read">
<!-- iis7 - for any request to a file exists on disk,
return it via native http module.
accessPolicy 'Script' is to allow for a managed 404 page. -->
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule"
preCondition="integratedMode" resourceType="File"
requireAccess="Read" />
</handlers>
</system.webServer>
</configuration>
Additionally, as others have pointed out, this is the most reliable way of locating an image:
<img src="#Url.Content(Html.ThemePath(WorkContext.CurrentTheme, "/Content/Header.png"))" />
if you examine the source, it should show you where it's trying to find that image and failing. It's most likely the relative path it's having issue with, try an absolute path in the css to see if that's the issue. without the actual site, I can't know for sure.