I am using IIS7 and urlMappings to map some urls to actual pages.
Example:
<urlMappings>
<!-- Remap friendly urls to actual pages: -->
<add url="~/help/" mappedUrl="~/content/help/help.aspx" />
<add url="~/news/" mappedUrl="~/content/news/default.aspx" />
</urlMappings>
This works great if the url has a trailing '/' , example:
http://www.mysite.com/news/
But I get page not found error if I do this:
http://www.mysite.com/news
I could add an extra entry without the trailing '/' so that both map to the same page, but I don't want to do this for SEO (would think it is duplicate content).
Is it possible to get the urlMappings to redirect?
For example, something like this:
<add url="~/help" redirect="~/help/" />
If not, what would be the best way of doing this?
Do you think google would really penalize
http://www.mysite.com/news/
http://www.mysite.com/news
as duplicate?
Here is my work around:
I add both entries, with and without trailing '/', to the urlMappings in web.config
<urlMappings>
<!-- Remap friendly urls to actual pages: -->
<add url="~/help/" mappedUrl="~/content/help/help.aspx" />
<add url="~/help" mappedUrl="~/content/help/help.aspx" />
</urlMappings>
Then in the page itself add the following code on page_load:
Dim mappedUrl as string = "/help"
If Request.RawUrl.EndsWith(mappedUrl) Then
Response.RedirectPermanent(String.Format("~{0}/", mappedUrl))
End If
This will permanently redirect and calls to the mapped page without a trailing '/' to the same page with a trailing '/'
Related
I have an MVC application which I am deploying out to a staging server using Team City. I have created a Web.Staging.config transform to handle the different database connection, certificates and service calls.
On this staging server I have had a request to have the title of the Index view to read "TEST SYSTEM" and to have a different colour scheme to signify, at a glance that the user is on the test system.
So far I have handled this by changing the view on the file system in notepad, and swapping the bootstrap.css file to one with a different theme however every time I do a new commit/deploy these changes are wiped and its becoming tiresome.
Is there anyway to handle CSS/view changes per server by using a similar transform system as employed to handle the web.config
There's not really an easy way to transform CSS files like that, but what you could do is have your master CSS file link in your config file, so your view would be something like:
<link href='#ConfigurationManager.AppSettings["MainCSS"]'>
Then your web.Debug (and other transformations) could point to the correct path:
<add key="MainCSS" value="/Content/Site.css" />
And your web.Staging config could point to another:
<add key="MainCSS" value="/Content/Staging/Site.css" />
You can also apply the above logic for your Index view:
public ActionResult Index()
{
string viewName = ConfigurationManager.AppSettings["MainView"];
return View(viewName);
}
Then have in your web.Debug (and others):
<add key="MainView" value="Index" />
And in your web.Staging:
<add key="MainView" value="IndexStaging" />
One solution could be to add a key to the web.config and read it using the WebConfigurationManager.AppSettings. Those settings can be transformed. In your view you can check this setting if you need to change the title and if you need to load an additional css file.
In your web.config:
<appSettings>
<add key="IsTestSystem" value="False" />
</appSettings>
and in as transform:
<appSettings>
<add key="IsTestSystem" value="True" xdt:Locator="Match(key)" xdt:Transform="SetAttributes"/>
</appSettings>
In your view / layout:
if (Boolean.TryParse(WebConfigurationManager.AppSettings["IsTestSystem"] ?? "False", out run)) {
// include css file for test system or modify the title
}
And, if you want, you can just switch between the two bootstrap.css files.
I'am using intelligencia.UrlRewriter on my web site.
I'am sending two querystring parameter to profil page.
<asp:HyperLink ID="lnkProfil" runat="server" Text='profil' NavigateUrl='/u/9f51e845-1089-4495-bd66-964db5b9c47b/tiju' ForeColor="Silver"></asp:HyperLink>
web config :
<rewrite url="~/u/(.+)/(.+)" to="~/Profil.aspx?user_id=$1&user_name=$2" />
and url seems like
http://yxyx.com/u/9f51e845-1089-4495-bd66-964db5b9c47b/tiju
But I want to make like
http://yxyx.com/u/tiju
or directly
http://yxyx.com/tiju (like facebook & twitter)
How can I hide user id parameter on url ?
If you want to have http://yxyx.com/u/tiju you should set it in the HyperLink
<asp:HyperLink ... NavigateUrl='/u/tiju' ...
In this case rewrite rule could be as
<rewrite url="~/u/(.+)" to="~/Profil.aspx?user_name=$1" />
As you see, in this case you will send only one parameter (tiju)
I have two user types: Readers and Authors. And I'm using Reader.Master and Author.Master for authorization purposes.
Then, there are StoriesR.aspx inherited from Reader.Master and StoriesA.aspx inherited from Author.Master. (In StoriesR.aspx page, you able to read the stories and in StoriesA.aspx you able to write the story.) So,
Reader.Master --> StoriesR.aspx
Author.Master --> StoriesA.aspx
Now, the thing is I don't want my users to see StoriesR.aspx?s=3 or StoriesA.aspx?s=3 in their browsers. I only want them to see stories?s=3. (even without the .aspx part)
How can I achieve this?
you can do this using urlMappings from web.config file
add in web.confing
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<urlMappings enabled="true">
<add url="~/reader/stories" mappedUrl="~/reader/StoriesR.aspx"/>
<add url="~/author/stories" mappedUrl="~/author/StoriesA.aspx"/>
This will do url mapping.
You could have one aspx page and change the master page programmatically depending on what type of user they are, Author or Reader.
You can do this in the Page_PreInit event of your aspx page.
Check this c# example or this VB example
Ok we have the following re-written URL using UrlRewriter.net
/category/games/21
using the following expression.
<rewrite url="~/Category/(.+)/(.+)" to="~/category.aspx?CatId=$2" />
however google can attach the following,
/category/games/21?gclid=clickIdHere
this would need to be re-written to,
/category.aspc?CatId=21&gclid=clickIdHere
Can anyone help suggest an expression that will work with the above?
I suppose somthing like...
<rewrite url="~/Category/(.+)/(.+)?gclid=(.+)" to="~/category.aspx?
CatId=$2&gclid=$3" />
should be like
<add name="category" virtualUrl="^~/Category.aspx/(.*)/(.*)" destinationUrl="~/Category.aspx?CatID=$1&gclid=$2" ignoreCase="true" rewriteUrlParameter="ExcludeFromClientQueryString" />
I'm using urlRewritingNet. My web.config is here>>
<add name="HOME" virtualUrl="^~/(.*)/Default.aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/Default.aspx?PageTitle=$1" ignoreCase="true"/>
My query string is here:
www.domain.com/home/default.aspx
This works. But I'm insert LoginStatus control. When click on the login control to logout, Page url was like this www.domain.com/home/default.aspx?PageTitle=home
Request.Querystring["PageTitle"] result is home,home
How to stop this duplicated query string?
I came across the same problem, I did something like following;
change your destinationUrl to "~/Default.aspx/$1"
and catch it with Request.PathInfo.Substring(1);