简体   繁体   中英

404 Error While URL Routing with asp.net web Forms

I am implementing url routing in my asp.net web forms. This is my mapping class

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute(
            "User",
            "Users/{id}",
            "~/Modules/UserMgmt/Users.aspx");
        routes.MapPageRoute(
            "Leave",
            "LeaveApply/{id}",
            "~/Modules/LeaveMgmt/LeaveApply.aspx");
    }
}

I am calling this method in my Application Start

    void Application_Start(object sender, EventArgs e)
    {
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }

and this is my anchor tag

<a href="/Users/18">Users</a>

Its working fine when I configure the project with " Use Visual Studio Development Server " from the project properties.

在此处输入图片说明

and its working fine as shown below

在此处输入图片说明

When I configure run the project with " Use Local IIS Web Server " from the project properties. ie)

在此处输入图片说明

I am getting the error shown below 在此处输入图片说明

The route directory or project name(Created when configure with " Use Local IIS Web Server " ) is missing while Routing. When I put the directory name add directly to the url from browser its working. Shown below.

在此处输入图片说明

Could you please help me to solve this problem.

Your routing is working fine, other wise you havn't see results for localhost/URLRouting/Users/18 However, there is no website listening to 'localhost' address.

If you want to use localhost, open IIS Manager, Create WebSite under the root and map it to your project physical folder.

Remove 'UrlRouting' from the project web properties

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM