久久久久久久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í))
主站蜘蛛池模板: 国产精品久久久爽爽爽麻豆色哟哟 | 精品国产乱码久久久久久久久 | 欧洲一区二区在线 | 日本久久网 | 精品久久久久久久久久久久久久 | 国产精品久久亚洲 | 久热免费在线 | 久久伦理电影 | 久久久久久综合 | 黑人巨大精品欧美一区二区免费 | 亚洲成人av在线播放 | 99精品电影| 神马久久香蕉 | 日本不卡一区二区三区在线观看 | 国产蜜臀97一区二区三区 | 中文字幕不卡视频在线观看 | 日日想夜夜操 | av大片在线观看 | 黄色高清视频 | 午夜丰满少妇一级毛片 | 国产一区二区av | 中文字幕视频在线观看 | 久久精品久久久久久 | 欧美高清性xxxxhd | 亚洲国产一区在线 | 国产乱码精品一区二区三区中文 | 作爱视频免费观看 | 欧美一级做性受免费大片免费 | 欧美日韩亚洲国产 | 91久久精品国产免费一区 | 免费成人高清在线视频 | 欧美日韩在线精品 | 国产精品福利视频 | 黄频视频| 国产精品日韩欧美一区二区 | 一区二区成人 | 四虎网站在线观看 | 欧美午夜剧场 | 91精品国产综合久久久动漫日韩 | 自拍中文字幕 | 国产成人精品一区二区 |