我是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中配置路由,以便浏览器中的Url显示为http://localhost:58170/Login
我已经建立了网站&在Visual Studio IIS Express中查看它,但它似乎加载Default.aspx而没有Url Routing。
到目前为止,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>
我该怎么做?
答案 0 :(得分:0)
答案 1 :(得分:0)
您可以使用Rewrite模块。然后你可以这样设置:
<configuration>
<system.webServer>
<rewrite>
<rule name="login" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{PATH_INFO}" pattern="/Login*" />
</conditions>
<action type="Redirect" url="/default.aspx" />
</rule>
</rewrite>
</system.webServer>
<configuration>