.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Rewrite non existant directories

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :ASP.Net



I am using a *.html script mapping in IIS 7.5 to force .html files to be processed by asp.net

This allows me to do something like domain.com/file-name-here.html and have IIS catch it in the Application_BeginRequest and rewrite the context to domain.com/file.aspx?a=file-name-here

This works well even though the .html file in the URL does not actually exist becuase I am rewriting the context before it requests the file.  I am having trouble doing that with non existant directories though - IIS keeps throwing a 404 error on teh static handler.  if I tell the static handler not to throw errors

for example

domain.com/folder-here/ - this doesnt work

domain.com/file-here.html - this does work


How can I make the folder portion work as well ?


View Complete Post

More Related Resource Links

Url rewrite with timer



I'm trying to rewrite my urls, which kinda work now.

The problem is that in my page i'm using a timer to refresh the data every couple of seconds.
But in Mozilla firebug I can see that the url keeps changing: it's getting bigger after each timer update, like this:


etc etc, until it returns a 404 not found.

What can I do to prevent this?


URL Rewrite causes AppSettings to Fail?


Hi there,

I just implemented basic URL rewriting to change a page from, for example, /member.aspx?id=123 to /member.aspx/erik.  That works and I'm happy with it.  However, I am now getting an error message that states "the connectionstring property has not been initialized".  Normally, I've been storing the connectionstring in web.config, and I access it with:

Dim Connect As SqlConnection = New SqlConnection
Dim ConnectString As String
ConnectString = ConfigurationManager.AppSettings("linktomysite")
Connect.ConnectionString = ConnectString

This is what I do on every other page of the site and it works fine.  The only way it will work on the page where I'm URL re-writing, however, is if I replace "ConfigurationManager.AppSettings("linktomysite")" with the actual connection string itself.  For security reasons, obviously I would prefer to keep that info out of the page.  What can I do?



Arabic QueryString with Url Rewrite Solution


Alsalamo 3alaykom ,

as we know that if you use Intelligencia.UrlRewriter.RewriterHttpModule or IIS URL Rewriting , we will face problems with arabic urls

as this

http://localhost:1234/Pages/???? ?????? ?????? ??????????

and the Rule is :

<rewrite url="~/Pages/(.+)" to="~/ShowPages.aspx?Page=$1" />

you will recive the QueryString["Page"] Like this

نائب العميد للشؤون الأكاديمية

so it's a big problem , and there is a solution that is :

remove the Rule of that rewriting ,,

<rewrite url="~/Pages/(.+)" to="~/ShowPages.aspx?Page=$1" />

then open your Global.asax file and Application_BeginRequest method exactly

use the following code to handle you request

void Application_BeginRequest(object sender, EventArgs e)
if (HttpContext.Current.Request.Url.ToString().Contains("/Pages/"))
	String[] txt= Regex.Split(HttpContext.Current.Request.Url.ToString(), @"/");
	String page = txt[txt.Length-1];

.NET Internals: Rewrite MSIL Code on the Fly with the .NET Framework Profiling API


In this article, the author shows how to dynamically rewrite Microsoft Intermediate Language code on the fly using the Profiling API of the CLR. Unlike approaches based on Reflection.Emit, this scheme works with the existing assemblies and doesn't require the creation of proxy or dynamic assemblies. The need for IL code rewriting emerges when you want to make your changes transparent to the client and preserve the identity of classes. This technique can be used for creation of interceptors, pre- and post-processing method calls, and code instrumentation and verification.

Aleksandr Mikunov

MSDN Magazine September 2003

Want to create Page URL rewrite based on Users GUID and Display name?



I am using the asp.net membership. 

On my site I have a Profile.aspx page.

In the code behind of this page,  i get the logged in UserId (Guid) and pass

this to a method in my DAL. GetUserByUserId()


In my database I have a Table called Member which the method gets the data from

and displays details on the page about  the user.


What I want to happen is when they have logged in and are diverted to Profile.aspx,

the page URL shows www.MyWebSite/Profile/UsersName 

for example



is this possible. In my Member table I have FirstName and LastName columns or do I get the

name from the membership table.


even better would be they go straight to www.MyWebsite/JohnSmith.aspx


thank you for any help






Url Rewrite for web service ...


Hello ,

how i can rewrite url for an web service ?!

i use it :

<add name="WebService" virtualUrl="^~/include/(.*).do" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/Def/WebService/$1.asmx" ignoreCase="true"/>

but when run sie , get some error(405 (Method Not Allowed) OR 500 ..) ...

Now I need to how to rewrite the web service address.

please help me ...

thanks .

Generating and storing html pages in User Directories on the server



I come from corporate asp.net development, and I am now working on a public website which will get a lot of traffic, perhaps a million users a day.  So I am faced with a ton of performance and scalability questions.

I would like to share some thoughts and see if my approaches resonate with any good practices, or perhaps I am heading down the wrong path...  Either way, I want to hear opinions.

(My number one concern is the fact that I am using asp.net for a public website.  I don't know of a lot of websites using asp.net)

I am using asp.net 2.0 (I know, its not the latest technology but I don't need any advanced features of asp.net 3.5 or 4, unless there are significant improvements geared towards what I am doing) 

On launch date, this will be running on a dedicated Windows Server 2008 running on Intel ATOM 330 1MB L2 Cache 1.6Ghz Dual-Core with 2GB DDR RAM.  Its fully managed by a full service hosting company which gives me an option to upgrade to a bigger server within a few hours.  I can even move the site to a webfarm if the traffic demands it.

So I have a User Dashboard, where users can create albums and upload pictures.  So what I am doing

Url Rewrite


Hi Everyone,

I have used url rewrite before, but have not yet attempted to do the following.
I have one site (www.somesite.co.za) which is being 301'ed to (www.sub.someothersite.co.za).
This work fine of course.

Is it possible to actually change the domain name in the url re-write? I would like to
hide the fact that the user is actually on a sub site on another domain. For example
if you browse to www.somesite.co.za, the url now reads www.subsite.someothersite.co.za.
I would like to re-write it to still be www.somesite.co.za

Any help will be greatly appreciated.

Thank you


Louis Lewis 

Url Rewrite for web service ...

Hello , how i can rewrite url for an web service ?! i use it :   <add name="WebService" virtualUrl="^~/include/(.*).do" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/Def/WebService/$1.asmx" ignoreCase="true"/>  but when run site and call a method(webservice.asmx/ChangeImage) , get error :The resource cannot be found. and if call web service mathod with jquery get error(405:Method Not Allowed). this is replay : <html> <head> <title>The HTTP verb POST used to access path '/Game-Root/Def/WebService/webservice.asmx/ChangeImage' is not allowed.</title> <style> body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Lucida Console";font-size: .9em} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:

URL-rewrite problem or sth else?

WelcomeI have a little problem with the *. js and *. css (probably also with others). When they move up to the header (or anywhere) I get something like that. Any ideas?Tuinel

asp:LoginStatus with url rewrite - postback url

hi ! I have done a url rewrite in my website and I did the following for handling the postbacks;    protected void Page_Load(object sender, EventArgs e)     {         this.form1.Action = Request.RawUrl;    protected void Page_Load(object sender, EventArgs e)    {        this.form1.Action = Request.RawUrl;it worked. but no with loginstatus button?? anyone knows why??

Delete bin and obj folder from projects directories

You always have problem to debug when you do latest from source control.You might end up deleting bin/obj folder sometime.Here is nice bat file which delete bin/obj folder(s). 1. copy this on notepad and save it as clean.bat file 2. Keep this file on root directory 3. Double check the directory on "DIR /B /AD /S obj" and "DIR /B /AD /S bin" ---------------------------------------------------------------------------------------------- FOR /F "tokens=*" %%G IN ('DIR /B /AD /S bin') DO RMDIR /S /Q ...(read more)

URL ReWrite with UrlRewrite.net

I'm trying to set up Url-rewrite-function on our site. For this I will use the Approach 2 on http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx    In that exampel they are using this <rewriter>    <rewrite url="~/products/books.aspx" to="~/products.aspx?category=books" />    <rewrite url="~/products/CDs.aspx" to="~/products.aspx?category=CDs" />    <rewrite url="~/products/DVDs.aspx" to="~/products.aspx?category=DVDs" />  </rewriter>   But I want just a keyword direct aftrer the site name like this www.site.com/books  

Compare 2 directories

Hai Friends,   How can I compare 2 directories in c#. If you have send me the code.   GSVS

Url rewrite + ScriptManager = Client side error...

Hi All,   I am trying to build a asp.net website with url rewriting. I have retrieved a rewrite rule from my web host (see below) that I have added to my web.config file. The rule redirects all urls to my default.aspx as intended and every thing seems to work as it should.<rewrite> <rules> <rule name="Rewrite All" stopProcessing="true"> <match url="^(.*)$" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="Default.aspx" /> </rule> </rules> </rewrite>.until I add a ScriptManager to my page for partial updating of UpdatePanels. When I do this i get a client side (javascript) error as follows (see below). The error occures both on the initial page load and on postbacks. Viewstate is still working, but partial updates and ajax or any other javascript is not working because of the error below.Chrome javascript console: WebResource.axd:3Uncaught SyntaxError: Unexpected token <WebResource.axdResource interpreted as script but

VS2008, Virtual Directories and IIS7

I did have this working but now something has stopped it (after trying to integrate combres)My dev machine is win 7x64, running VS2008. I have a solution with number projects (mostly libraries), one was a webapplication. This webapplication used to debug through. That site was configured to point to the home directory of that web application.It was set up this way because i was URL Rewriting and that was the only way i could get it workingHowever now whenever i start up visual studio it complains that the local IIS has not been configured, would you like to create the virtual directory. If i say no then the project is not loaded, if i say yes then the process fails with could not find the server on the local machine. Creating a virtual directory is only supporting on the local IIS server.I can edit the XML of the project file to turn off Use IIS in which case i can load the project but the site doesn't work through the integrated visual studio server.I've tried removing the website in IIS7 and removing the AppPool and rebuilding but no go.Can anyone offer me advice or pointers on how to get this solved?many thankspaul
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend