I want to route these 3 paths to default base url path.
www.mysite.com/page1.aspx
www.mysite.com/page2.aspx
www.mysite.com/page3.aspx
I want to appear these 3 pages in address bar like this: www.mysite.com
There are only these 3 pages in my asp.net project.
How can I do this in asp.net 3.5 sp1 with IIS 6.0.
void Application_BeginRequest(object sender, EventArgs e)
{
switch (HttpContext.Current.Request.Url.AbsolutePath.ToLower())
{
case "/page1.aspx":
HttpContext.Current.RewritePath("~/default.aspx");
break;
case "/page2.aspx":
HttpContext.Current.RewritePath("~/default.aspx");
break;
case "/page3.aspx":
HttpContext.Current.RewritePath("~/default.aspx");
break;
}
}
With this code, error occured:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /default.aspx
Problem is rewriting the url. It is searching default.aspx file. There is no default.aspx file. There is page1.aspx file.
Why it is searching default.aspx ? I jus开发者_开发百科t want to rewrite path..
Your call to HttpContext.Current.RewritePath
is saying "if anyone asks for /page1.aspx
(or /page2.aspx
or /page3.aspx
), serve them ~/default.aspx
instead".
Naturally if ~/default.aspx
doesn't exist, this will throw a 404.
What are you trying to do? You say you "want to route these 3 paths to default base url path" but what is that path if ~/default.aspx
doesn't exist?
精彩评论