Click here to Skip to main content
15,909,091 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: RSS Feed Pin
Suresh Pirsquare29-Aug-06 0:59
Suresh Pirsquare29-Aug-06 0:59 
QuestionDatagrid in ajax Pin
alokdotnet28-Aug-06 17:19
alokdotnet28-Aug-06 17:19 
QuestionUsing Asp page in Asp.net Pin
alokdotnet28-Aug-06 17:15
alokdotnet28-Aug-06 17:15 
AnswerRe: Using Asp page in Asp.net Pin
Guffa28-Aug-06 19:04
Guffa28-Aug-06 19:04 
QuestionEnter Text into Detailsview on Insert. Pin
japel28-Aug-06 16:15
japel28-Aug-06 16:15 
QuestionWhy is only my first dropdown list maintains its selection? Pin
littlecuttiepie28-Aug-06 12:37
littlecuttiepie28-Aug-06 12:37 
AnswerRe: Why is only my first dropdown list maintains its selection? Pin
Not Active28-Aug-06 16:50
mentorNot Active28-Aug-06 16:50 
QuestionDrop file extension HttpModule + Login Control Pin
eggsovereasy28-Aug-06 10:59
eggsovereasy28-Aug-06 10:59 
Someone here thinks making the url more readable and hiding the technology we use is a priority and I need to do it.

So, I wrote an HttpModule that does some url rewriting, first if you have an address without an extension it gets that page plus .aspx. I.e. if you typed "http://www.mysite.com/users" into your address bar, users.aspx would be loaded (though the url would stay the same). This works fine. Also, this module will take pages with an extension written in, remove it, and refresh the page. For example, if you typed in "http://www.mysite.com/users.aspx" (or .cfm, php, etc) the module would parse the url, and do a Respone.Redirect to "http://www.mysite.com/users" where it is then processed as described above.

However, the problem comes in when I try to use the login control built into asp.net 2.0. After you click the log in button I get a 404 error on default.aspx in ~/. If I disable my HttpModule everything works fine. Anything wrong with what I have or is there something the login control does automatically that interferes with it? Like Server.Transfer?

Here is the code for the module:
using System;
using System.Collections.Generic;
using System.Web;

namespace BEAR.UrlRewriter
{
    public class ExtensionWriter : IHttpModule
    {
        //the application to call this module
        private HttpApplication application;
        //extensions to discard
        private List<string> ext;

        public void Init(HttpApplication application)
        {
            //populate extensions to discard
            string[] exten = { "asp", "aspx", "pl", "cfm", "php" };
            this.ext = new List<string>();
            foreach (string s in exten)
                ext.Add(s);
            
            this.application = application;
            this.application.BeginRequest += new EventHandler(this.BeginRequestHandler);
        }

        protected virtual void BeginRequestHandler(object sender, EventArgs e)
        {
            string url = this.application.Request.Path;

            string[] path = url.Split(new char[] { '/' });//split directories
            //Split the last between file portion and the query string.
            string[] location = path[path.Length - 1].Split(new char[] { '?' });

            string file = location[0]; //Save file portion
            string[] splitFile = file.Split(new char[] { '.' });

            if (splitFile.Length == 1) //Only if the file has no extension
            {
                string newPath = string.Empty;

                foreach (string s in path)
                    newPath += s + "/";//reconstruct the path

                newPath += file + ".aspx"; //add an aspx extention

                if (this.application.Request.QueryString.HasKeys()) //reattach query string if it exists
                    newPath += "?" + this.application.Request.QueryString.ToString();

                //rewrite the url
                this.application.Context.RewritePath(newPath);
            }
            else if(splitFile.Length > 1 && ext.Contains(splitFile[1]))
            {
                string newPath = string.Empty;

                foreach (string s in path)
                    newPath += s + "/"; //reconstruct the path

                newPath += splitFile[0];//Drop the extension

                if (this.application.Request.QueryString.HasKeys()) //reattach query string if it exists
                    newPath += "?" + this.application.Request.QueryString.ToString(); 

                //redirect
                application.Response.Redirect(newPath.ToLower());
            }
        }

        public void Dispose() { /* Empty */ }
    }
}

QuestionForm Authentication Pin
Bassam Saoud28-Aug-06 10:32
Bassam Saoud28-Aug-06 10:32 
Questionimporting a swish file into ASP.NET Pin
Insia28-Aug-06 9:02
Insia28-Aug-06 9:02 
QuestionWeb Service vs. Web Form Security Pin
JimmyG1328-Aug-06 7:49
JimmyG1328-Aug-06 7:49 
QuestionWhat is "content file" and "code-behind file" ? Pin
Husam Burhan28-Aug-06 7:16
Husam Burhan28-Aug-06 7:16 
AnswerRe: What is "content file" and "code-behind file" ? Pin
japel28-Aug-06 16:43
japel28-Aug-06 16:43 
QuestionPassing Controls Pin
cisco210328-Aug-06 4:06
cisco210328-Aug-06 4:06 
AnswerRe: Passing Controls Pin
coolestCoder28-Aug-06 4:42
coolestCoder28-Aug-06 4:42 
GeneralRe: Passing Controls Pin
Not Active28-Aug-06 5:13
mentorNot Active28-Aug-06 5:13 
GeneralRe: Passing Controls Pin
cisco210328-Aug-06 5:22
cisco210328-Aug-06 5:22 
GeneralRe: Passing Controls Pin
Not Active28-Aug-06 5:57
mentorNot Active28-Aug-06 5:57 
AnswerRe: Passing Controls Pin
Not Active28-Aug-06 5:11
mentorNot Active28-Aug-06 5:11 
GeneralRe: Passing Controls Pin
cisco210328-Aug-06 5:26
cisco210328-Aug-06 5:26 
GeneralRe: Passing Controls Pin
Not Active28-Aug-06 5:55
mentorNot Active28-Aug-06 5:55 
Questionhi Pin
FREAK880228-Aug-06 4:01
FREAK880228-Aug-06 4:01 
QuestionNew to Asp.Net Pin
drc_no128-Aug-06 3:39
drc_no128-Aug-06 3:39 
AnswerRe: Read XML file from App_Data Pin
Guffa28-Aug-06 4:01
Guffa28-Aug-06 4:01 
GeneralRe: New to Asp.Net [modified] Pin
drc_no128-Aug-06 4:22
drc_no128-Aug-06 4:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.