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

如何在 MVC3 中使用 https 生成絕對(duì) URL?

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

問題描述

限時(shí)送ChatGPT賬號(hào)..

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

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

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

這有助于您為內(nèi)容文件生成絕對(duì) 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 在評(píng)論中指出的那樣,您可以使用的各種開源項(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 生成絕對(duì) URL?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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)證并跨請(qǐng)求保留自定義聲明)
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视在线国内在线播放酒店 | 97精品国产97久久久久久免费 | 欧美jizzhd精品欧美巨大免费 | 久久久久亚洲精品 | 成人免费在线观看视频 | 国产综合精品一区二区三区 | 亚洲欧美日韩精品久久亚洲区 | 男人视频网站 | 国产乱码一二三区精品 | 精品久久国产视频 | 亚洲精品久久 | 美国一级片在线观看 | 一级大片免费 | 欧美一区二区三区视频在线 | 一区二区视频在线 | 亚洲狠狠 | 国产福利91精品一区二区三区 | 午夜伦理影院 | 日韩一及片 | 久久国产精品视频 | 一级黄色av电影 | 国产成人99久久亚洲综合精品 | av手机免费在线观看 | 第四色影音先锋 | 91久久久久久久久久久久久 | 久久久国产精品视频 | 91操操操 | 国产日屁 | 国内自拍视频在线观看 |