I have created a page in Umbraco 7.
I need to pass an id to this page and I want to read that parameter inside the template.
If I use this url: http://www.example.com/product?id=10 I have access to the id inside template using Request["id"] which is fine. but the issue is I want to have my Url like http://www.example.com/product/10 but if I use it I receive: "404 - File or directory not found.".
I actually thought it might be resolved by Umbraco default routing but it is not.
I also tried IIS URL rewrite, but I believe it should be a better way in Umbraco to handle it same as ASP.NET MVC Routing.
You could use this rewrite rule to handle the routing before the request reaches Umbraco.
<rule name="Product Rewrite" stopProcessing="false">
<match url="product/([0-9]+)/"/>
<action type="Rewrite" url="/product/?id={R:2}"/>
</rule>
Another approach is to implement a custom ContentFinder which enable you "find" the content on your own. This allows you make even prettier urls for your products if you can determine the ids from the name in some way. This link https://24days.in/umbraco-cms/2014/urlprovider-and-contentfinder/ provide some information on how to implement a ContentFinder.
Related
I have an existing Angular website in that I want to deploy ASP.NET MVC application inside the virtual directory. the problem is when I try to route to ASP.NET MVC application inside a virtual directory it shows "403 - Forbidden: Access is denied." error on IIS.
I tried adding a new url rewrite rule in web.config of an angular application as given in
https://www.stefanoscerra.it/iis-rewrite-rules-configuration-angular-web-config/
but it tries to find the angular route and if not match any angular route it redirects to the angular default route
In I was having same scenario like this I solved by adding rewrite rule URL rewrite configuration in web.config .You will need to add rewrite rule like below.
<rule name="mvcinsideangularrule" stopProcessing="true">
<match url="mvcvirtualdir/(.*)/(.*)/(.*)" />
<action type="Rewrite" url="http://yourdomain.com/mvcvirtualdir/{R:1}/{R:2}/{R:3}"/>
</rule>
It will work in your scenario.
I'm publishing an MVC 3 site to a go daddy account. I'm using the FTP Publish utility in VS 2010. The site publishes "okay". But here is the issue:
On my local machine, when I run it the web address is:
localhost/Student/Create
On my go daddy account, I have created a subdirectory called mvctest.
I have created a subdomain called mvctest.mysite.com that points to the virtual directory at mvctest. This works fine.
But after I publish my site to www.mysite.com/mvctest, I am getting an additional /mvctest/ directory in all of my links. What I want is:
mvctest.mysite.com/Student/Create
what I get is:
mvctest.mysite.com/mvctest/Student/Create
What's interesting is that if I manually type in what I want, the page loads fine. If I've hard-coded a link to the root, it's fine, but all of my Url.Content and Html. Links add the additional mvctest directory..
I've searched all over and haven't found an answer to this dilemma. I tried in the web.config, but I don't think that does it. I feel like something in the FTP Publish utility in VS2010 is altering the routing structure in my global.asax file, but I'm not sure.
Any suggestions appreciated.
Is your virtual directory an application? If it's not set as an application, IIS will treat the root of your site as the application and add the subdirectory. See this post.
The following solved the same issue for me and is quoted from a blog post I found (source):
So now for the solution, and I probably should have mentioned this at the beginning but hopefully you’re using IIS7 with the URL rewriting module installed (it is installed by default when you use IIS7 on GoDaddy).
Simply add the following into your web.config’s system.webServer element:
<rewrite>
<rules>
<rule name="Remove Virtual Directory">
<match url=".*" />
<action type="Rewrite" url="{R:0}" />
</rule>
</rules>
</rewrite>
All this does is “rewrite” the URL with itself. This causes URL Rewrite to add the original URL (the one with no folder name) to a ServerVariable which is used by ASP.NET MVC to generate other URLs.
I've implemented a sitemap that is dynamically generated on the fly using the technique described here.
Since my site is a WebForms app, my sitemap URL ends up being www.mydomain.com/Sitemap.aspx.
This is working well, and I can use search engine webmaster tools to tell them the URL to my sitemap. However, smaller search engines may not know where to find this file. It would be better if my dynamically generated sitemap could be at www.mydomain.com/sitemap.xml. This is the standard URL for a sitemap.
What is the easiest way to generate the same sitemap data I do now but have it appear as the file sitemap.xml. Can I do it using routing, or do I need a custom HTTP handler?
I'm using webforms but also have sites using ASP.NET MVC so I'm very interested in finding the best technique to do this in both platforms.
For Webforms, you can use HttpModule, check out UrlRewriting.NET
For MVC, use routing:
routes.MapRoute("Sitemap",
"sitemap.xml",
new { controller = "Home", action = "Sitemap" })
For Webforms, you can also update your web.config as mentioned above, you just use plain aspx or ascx page and then do magic with rewrite :-) (I use .net 4.0)
e.g.
<system.webServer>
<rewrite>
<rules>
<rule name="Main Sitemap" stopProcessing="true">
<match url="^sitemap.xml"/>
<action type="Rewrite" url="sitemap/sitemap.aspx" appendQueryString="false"/>
</rule>
</rules>
</rewrite>
</system.webServer>
I've just recently started trying to use Umbraco, so I hope this doesn't sound stupid.
I'm trying to set the default web page to my site, but I am having no luck. I recently installed umbraco v 4.7.1.1, along with the blog starter kit that you can select when using the installation wizard.
In my "Content View", I have the following structure:
Content (folder)
Personal Site (folder)
Index
About
MyTestBlog
When I look at the Properties tab for MyTestBlog, the Template property is set to "Blog Post". When I go to www.mytestsite.com, the content on MyTestBlog shows up on the site's default web page.
I have the Template property for the Index page set to "Textpage". I right clicked on the Personal Site folder and selected Sort. From the Sort pop-up window, I dragged Index to the top of the list so that it has the sort order of zero (0).
From what I have read, whatever is set as the first item will be the default web page in Umbraco, but this does not seem to be the case for me. No matter what I try, I cannot get Index to be the default web page for the site.
I have checked to ensure that all of the web pages have been published. Is there something that I am missing or not doing?
Thanks!
Not a stupid question at all, it's a common stumbling block when first learning Umbraco. I know it tricked me when I started. Your assumptions are correct in that Umbraco will display the first node as the default page, but it's the node Personal Site which is actually the first node.
To fix this, add a property with the alias umbracoInternalRedirectId of data type Content Picker to your Personal Site document type. Then in the content section pick the node you want the Personal Site node to default to (it doesn't even have to be the first subnode).
Normally, you could use a property alias of umbracoRedirect but Umbraco doesn't allow this on the first node without it's problems. umbracoRedirect is safe to use (and generally preferred) for any other node in the site.
Or, if the website has already been published, add a rewrite rule to the Web.Config:
<rewrite>
<rules>
<rule name="Redirect to front" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/yourViewName" />
</rule>
</rules>
</rewrite>
Just include that inbetween the system.webServer tags within the configuration tags, and replace yourViewName by the appropriate view's name (like Contact or Work) and you're done!
Best of luck.
I have a virtual directory created and a sub domain that points to that virtual directory. My links always route to subdomain.domain.com/subdomain/controller/action when they can leave off the subdomain link. Is there an easy way to stop that?
Also, it's the same problem when I mapped anotherdomain.com to my virtual directory. It ends up linking to anotherdomain.com/virtualdir/controller/action.
It just looks unprofessional to me to have all my links be myapp.com/myapp/action/controller.
I have also wondered this, but I don't believe that you can achieve this in the ready-made routing that comes with ASP.NET MVC.
Thankfully, the user has a great deal of freedom in choosing how they want to handle these things, and a solution that you may want to consider can be found here.
The ASP.NET MVC team appear to have recognised that this should be pre-baked into MVC by default, but I don't see anything being done about until v2 as it will require changes to the routing engine.
Failing this, you may want to consider url rewrites (this is obviously much easier if you have IIS7). Here is an IIS forum post discussing this.
IIS 7 Rewrite Example (taken from here):
<rule name="RewriteSubdomain">
<match url="^(.+)">
<conditions>
<add input="{HTTP_HOST}" type="Pattern" pattern="^([^.]+)\.myapp\.com$">
</conditions>
<action type="Rewrite" url="{C:1}/{R:1}" />
</rule>