Hi,
How to stop a website from opening a particular file in the view mode. The problem is that I have few files with extension (.default) like navigator.cfg.default and web.config.default and when I run the web application then it is possible to view those files. How can I stop it?
I tried the following code:
namespace HttpUrlRewrite
{
/// <summary>
/// Summary description for HttpUrlRewrite
/// </summary>
public class Rewriter : System.Web.IHttpModule
{
public void Init(System.Web.HttpApplication Appl)
{
Appl.BeginRequest += new System.EventHandler(Rewrite_BeginRequest);
}
public void Dispose()
{
}
public void Rewrite_BeginRequest(object sender, System.EventArgs args)
{
System.Web.HttpApplication App = (System.Web.HttpApplication)sender;
string path = App.Request.Path;
string strExt = System.IO.Path.GetExtension(path);
if (strExt == ".default")
{
//Do Something
HttpContext.Current.Response.Redirect("default.aspx");
}
else
{
//Do Something
}
}
}
}
<httpModules>
<add type="HttpUrlRewrite.Rewriter" name="HttpUrlRewrite" />
</httpModules>
But the code didn't work under the IIS. However when I run the project from Visual Studio and try to open a file with extension (.default), I am redirected to default.aspx but when I try to open the .defualt file from the IIS, I am still able to open the file.
I have one more question here - Is there any performance issue if I am redirecting the user to a different page with HttpModule every time he enters a particular extension?
Thanks..