【发布时间】:2018-04-25 13:45:18
【问题描述】:
我是 Asp.Net Web 应用程序的新手。我在 Visual Studio 2017 中使用 MVC 创建了一个空的 ASP.Net Web 应用程序。我试图在 Web 应用程序中配置路由。到目前为止,我所做的是将“App_Start”文件夹添加到项目中,然后使用以下代码创建一个名为 RouteConfig.cs 的类文件:
RouteConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
namespace WebApplicationBS_Web.
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.Ignore("{resource}.axd/{*pathInfo}");
routes.MapPageRoute(
routeName: "Login",
routeUrl: "Login",
physicalFile: "~/Default.aspx"
);
}
}
}
然后我编辑了 Global.asax 文件如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.Routing;
namespace WebApplicationBS_Web.App_Start
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
}
我现在想在 web.config 中配置路由,使浏览器 shud 上的 Url 显示为 http://localhost:58170/Login
我已经构建了网站并在 Visual Studio IIS Express 中查看了它,但它似乎加载了没有 URL 路由的 Default.aspx。
目前的Web.Config文件如下:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.7"/>
<httpRuntime targetFramework="4.7"/>
</system.web>
<location>
<system.webServer>
<defaultDocument>
<files>
<clear/>
<add value="Default.aspx"/>
</files>
</defaultDocument>
</system.webServer>
</location>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
我该怎么办??
【问题讨论】:
-
我想知道您是否有向后路由的想法。听起来您希望在转到默认站点时 URL 显示为 localhost:58170/Login?但是您的路由只是意味着当您转到该 URL 时,将显示默认站点。最重要的是,了解您要访问的 URL 以及您希望看到的内容会很有帮助。