日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

asp.net?web?api2設置默認啟動登錄頁面的方法_實用技巧

作者:小小魚34309335 ? 更新時間: 2022-11-12 編程語言

1.在Global.asax文件中添加Application_BeginRequest方法,如下如所示:

public class WebApiApplication : HttpApplication
{
    protected void Application_Start()
    {
        log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
    
    
    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Context.Request.FilePath == "/") 
            Context.RewritePath("home/page/login.html");
    }
}

靜態頁面的目錄結構如下所示:

2.等啟動項目后,到了登錄頁,有可能會發現靜態資源,如圖片,css,js文件全部加載失敗,這個時候需要修改一下路徑,如下所示:

登錄成功跳轉的頁面也要注意下。

備注:項目使用rider2022.2.3開發?

原文鏈接:https://blog.csdn.net/qq_34309663/article/details/126968948

欄目分類
最近更新