Yussi Ariefiyono
Archive for April, 2009
Fixing the problems in url rewriting asp.net
Apr 27th
postbacks while using URLRewriter.net
solution:
put this code:
<%@ Register TagPrefix="url" Namespace="Intelligencia.UrlRewriter"
Assembly="Intelligencia.UrlRewriter" %>
and
change <form id="form1" runat="server"> to <url:form runat="server">
problem with Google BOT
solution:
add this code in your App_Browsers/genericmozilla5.browser
<browsers>
<browser id="GenericMozilla5" parentID="Mozilla">
<identification>
<userAgent match="Mozilla/5\.(?'minor'\d+).*[C|c]ompatible; ?(?'browser'.+); ?\+?(http://.+)\)" /></identification>
<capabilities>
<capability name="majorversion" value="5" />
<capability name="minorversion" value="${minor}"/>
<capability name="browser" value="${browser}" />
<capability name="Version" value="5.${minor}" />
<capability name="activexcontrols" value="true" />
<capability name="backgroundsounds" value="true" />
<capability name="cookies" value="true" />
<capability name="css1" value="true" />
<capability name="css2" value="true" />
<capability name="ecmascriptversion" value="1.2" />
<capability name="frames" value="true" />
<capability name="javaapplets" value="true" />
<capability name="javascript" value="true" />
<capability name="jscriptversion" value="5.0" />
<capability name="supportsCallback" value="true" />
<capability name="supportsFileUpload" value="true" />
<capability name="supportsMultilineTextBoxDisplay" value="true" />
<capability name="supportsMaintainScrollPositionOnPostback" value="true" />
<capability name="supportsVCard" value="true" />
<capability name="supportsXmlHttp" value="true" />
<capability name="tables" value="true" />
<capability name="vbscript" value="true" />
<capability name="w3cdomversion" value="1.0" />
<capability name="xml" value="true" />
<capability name="tagwriter" value="System.Web.UI.HtmlTextWriter" />
</capabilities>
</browser>
</browsers>
Simple url rewriting ASP net with URLRewriter.Net
Apr 24th
URL Rewriting with URLRewriter.Net
URL Rewriting has lots of benefits, listing its main benefits
- SEO Friendly URL
- Secured URL
- No need to change bookmark with change in site structure.
Before URL Rewriting my URL looks like
http://localhost:2661/URLRewrite2/DynamicPage.aspx?MyTitleId=1
After URL Rewriting URL is changed to
http://localhost:2661/URLRewrite2/Article/Asp-Net-website-paths-1.aspx
Step-by-Step Explanation
Step 1: Download Binary Files for URLRewriter.Net
Step 2: Add Reference to Binary Files, Right click project "Add Reference" and add binary files.
Step 3: Update Web.Config File to make URLRewriter.Net works.
<configuration> <configSections> <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" /> </configSections> <system.web> <httpModules> <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" /> </httpModules> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" /> </modules> <validation validateIntegratedModeConfiguration="false" /> </system.webServer> <rewriter> <rewrite url="~/Article/(.+)-(.+).aspx" to="~/DynamicPage.aspx?MyTitleId=$2"/> </rewriter> </configuration>
Step 4: Adding Function to Generate SEO Friendly URL from given Title
public static string GenerateURL(object Title, object strId) { string strTitle = Title.ToString(); #region Generate SEO Friendly URL based on Title //Trim Start and End Spaces. strTitle = strTitle.Trim(); //Trim "-" Hyphen strTitle = strTitle.Trim('-'); strTitle = strTitle.ToLower(); char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray(); strTitle = strTitle.Replace("c#", "C-Sharp"); strTitle = strTitle.Replace("vb.net", "VB-Net"); strTitle = strTitle.Replace("asp.net", "Asp-Net"); //Replace . with - hyphen strTitle = strTitle.Replace(".", "-"); //Replace Special-Characters for (int i = 0; i < chars.Length; i++) { string strChar = chars.GetValue(i).ToString(); if (strTitle.Contains(strChar)) { strTitle = strTitle.Replace(strChar, string.Empty); } } //Replace all spaces with one "-" hyphen strTitle = strTitle.Replace(" ", "-"); //Replace multiple "-" hyphen with single "-" hyphen. strTitle = strTitle.Replace("--", "-"); strTitle = strTitle.Replace("---", "-"); strTitle = strTitle.Replace("----", "-"); strTitle = strTitle.Replace("-----", "-"); strTitle = strTitle.Replace("----", "-"); strTitle = strTitle.Replace("---", "-"); strTitle = strTitle.Replace("--", "-"); //Run the code again... //Trim Start and End Spaces. strTitle = strTitle.Trim(); //Trim "-" Hyphen strTitle = strTitle.Trim('-'); #endregion //Append ID at the end of SEO Friendly URL strTitle = "~/Article/" + strTitle + "-" + strId + ".aspx"; return strTitle; }
Step 5: Changing DataBinder.Eval Function in .Aspx Page to reflect changes in URL of Grid.
Note: Learn more about DataBinder.Eval Function
<%#GenerateURL(DataBinder.Eval(Container.DataItem,"Title"),DataBinder.Eval(Container.DataItem,"Id"))%>
Sources :
YAF forum multiple boards stand alone
Apr 20th
Problem:
you want 2 diffrent forum with 1 login
Solution:
YAF is just a control so call it using the boardid as a parameter. For
instance, if you look at the default.aspx it has code that looks like
this:
<form runat="server" enctype="multipart/form-data">
<yaf:forum runat="server"/>
</form>
Now
go into admin and create a new board (Boards) and make note of the ID.
Make another file called "secondboard.aspx" (or whatever) and change
call to YAF to include the boardid #:
<form runat="server" enctype="multipart/form-data">
<yaf:forum boardid="2" runat="server"/>
</form>
(Boardid
is whatever you want… you could have it reference a million different
boards if you create them — categoryid is also supported.)
Embedding YAF inside an existing asp.net website
Apr 16th
===The problem===
I have an existing asp.net website with master pages and lots of other stuff. How do I embed yaf into that, so I can use my existing menus and everything, with yaf appearing seamlessly as a page within the site?
If you take yaf "out of the box", then the obvious way to do this is to put the whole thing in an iframe. That kind of works, but there are a few things which don't work too well, and it's kind of complicated and unsatisfactory. In short, it's a hack.
Here's a better way to do this…
===Solution Summary===
Don't use yaf as an application, use it as a control and stick it in one of your site's pages which uses your existing master page(s).
===How to do it===
Here's how to get yaf working without the application thing. This has been tested on iis6 and iss7 with 1.9.1.2.
====prerequisites====
#Install yaf as per the instructions into a subdirectory of your main website. I use ~/yaf.
#Make sure that the standard installation works before you do the following, so you're only dealing with one thing at once.
====step by step====
# Use IIS manager and remove the application you created for YAF in the standard install.
# Move the yafnet.config file from ~/yaf to ~.{br} Ensure that the yafnet.config file "points" to the place where you have YAF installed, in the example case:{br}@@<root>/yaf</root>@@
# Modify ~/web.config.{br}You need to update your main site ~/web.config with most of the contents from the old ~/yaf/web.config. Leave out all the "rewriting stuff" as you're going to switched that off later anyway. Specifically, you seem to need the following. Check carefully where this stuff comes from in the old web.config and make sure you put it in the same sections in your site's web.config. It'll bitch at you if you don't. See additional notes below.:
#*@@<section name="yafnet" type="yaf.SectionHandler,yaf"/>@@
#*@@<yafnet configSource="yafnet.config"/>@@
#*@@<authentication mode="Forms"><forms name=".YAFNET_Authentication" timeout="525600" /></authentication>@@
#*@@<customErrors defaultRedirect="error.aspx" mode="RemoteOnly"/>@@
# Modify ~/yaf/yafnet.config.{br}Disable url rewriting. Set:
#*@@<enableurlrewriting>false</enableurlrewriting>@@
# Delete or rename the old ~/yaf/web.config{br}This will stuff things up if you leave it there on iis6 (you will get an error message at run time of the type "It is an error to [...] allowDefinition='MachineToApplication'").
#Copy or move ~/yaf/yaf.dll to ~/bin/yaf.dll{br}
#Copy or move ~/yaf/framehelper.aspx to ~/{br}
#Create and edit your new yaf forums "container" page.{br}This will reference your own master page and be in your site map etc. You need to add the following lines (you can copy these from the top of the ~/yaf/default.aspx file, which you will not be using):{br}Under the "<%@ Page directive" put
#*@@<%@ Register TagPrefix="yaf" Namespace="yaf" Assembly="yaf" %>@@
#*@@<%@ Register TagPrefix="yc" Namespace="yaf.controls" Assembly="yaf" %>@@
#* In the content place holder where you want to display the forums, put the control tag (you can also copy this from the ~/yaf/default.aspx file):
#*@@<yaf:Forum runat="server" ID="forum" />@@
That's it.
=====Additional Notes=====
#There's a line in the yaf default web.config:{br}@@<xhtmlConformance mode="Legacy"/>@@ If you're using MS Ajax at all on your site and you stick that in the site's web.config, it will break ms Ajax in strange and entertaining ways. [http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx|See here] for some background on this. Leave this like out and MS Ajax works again…