久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 MVC3 中使用 https 生成絕對 URL?

How to Generate absolute urls with https in MVC3?(如何在 MVC3 中使用 https 生成絕對 URL?)
本文介紹了如何在 MVC3 中使用 https 生成絕對 URL?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號..

我正在使用 MVC3 并嘗試從 https 提供內(nèi)容,問題是當(dāng)我調(diào)用 Url.Content 時(shí),仍然使用相對 url 從 http 提供文件.我認(rèn)為這個(gè)問題在 MVC3 中得到了解決,但我似乎找不到任何解決方案.有誰知道這個(gè)問題是否在 MVC3 中固有地解決了,以及如何完成它,還是我需要?jiǎng)?chuàng)建自己的輔助方法來生成基于協(xié)議的絕對 URL?

I am using MVC3 and am trying to serve content from https, the problem is that when I call Url.Content the files are still served from http using a relative url. I thought this problem was addressed in MVC3 but i can't seem to find any solution. Does anybody know if this issue is inherently solved in MVC3 and how to accomplish it or do I need to create my own helper methods to generate absolute Urls based on protocol?

推薦答案

您可能可以使用 VirtualPathUtility.ToAbsolute.大概是這樣的:

You can probably implement your own solution using VirtualPathUtility.ToAbsolute. Probably something like this:

public static class UrlHelperExtension {
  public static string Absolute(this UrlHelper url, string relativeOrAbsolute) {
    var uri = new Uri(relativeOrAbsolute, UriKind.RelativeOrAbsolute);
    if (uri.IsAbsoluteUri) {
      return relativeOrAbsolute;
    }
    // At this point, we know the url is relative.
    return VirtualPathUtility.ToAbsolute(relativeOrAbsolute);
  }
}

你會(huì)像這樣使用:

@Url.Absolute(Url.Content("~/Content/Image.png"))

(我自己沒有對此進(jìn)行測試,請隨意嘗試使其正常工作.)

(Didn't test this myself, feel free to play around to make it work right.)

這有助于您為內(nèi)容文件生成絕對 URL.為了更改生成的 URL 的方案,您可以創(chuàng)建一個(gè)額外的擴(kuò)展方法來操作給定 URL 的方案,以便它們是 HTTPS 或其他.

This helps to you to generate absolute URLs for your content files. In order to change the scheme of the resulting URLs, you can create an additional extension method that manipulates the scheme of the given URLs so that they are HTTPS, or something else.

正如 Khalid 在評論中指出的那樣,您可以使用的各種開源項(xiàng)目中已經(jīng)提供了類似的擴(kuò)展方法(如果許可證允許).可以找到一個(gè)示例 這里.

As Khalid points out in the comments, similar extension methods are already available in various open-source projects which you can make use of (given that the license permits). An example one can be found here.

這篇關(guān)于如何在 MVC3 中使用 https 生成絕對 URL?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗(yàn)證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
主站蜘蛛池模板: 国产美女精品视频 | 一级片视频免费 | 91高清免费观看 | 天堂综合网久久 | 久久亚洲视频 | 可以看黄的视频 | a在线观看 | 伊人伊人伊人 | 在线观看av网站永久 | 91福利网| 天天干视频 | 黄色a视频 | 操视频网站 | 精品久久一区二区 | 中文字幕一区在线观看视频 | 日韩欧美在线不卡 | 久久r精品| 国产成人免费网站 | 成人网址在线观看 | 蜜桃在线视频 | 欧美综合一区 | 91视频网址| 国产精品久久久久久久久久久久 | 精品国产女人 | 一区二区成人 | 久久亚洲一区二区三 | 五月综合激情网 | 日韩久久精品电影 | 亚洲综合国产 | 久久人爽| 国产亚洲精品久久19p | 精品综合久久久 | 欧美寡妇偷汉性猛交 | 日本久久综合 | 精品一区二区在线观看 | 成人h视频在线观看 | 天堂色网 | 日本欧美视频 | 蜜桃av人人夜夜澡人人爽 | 国产91久久久久蜜臀青青天草二 | 欧州一区二区三区 |