0

ファイルへのリンクを作成する必要がある小さな Asp MVC 3 プロジェクトがありますが、サイトの名前がわかりません。したがって、私の ActionResult には、次のものが必要です

public ActionResult LinkToFile()
         {

var fields = new[]{
                        new { type = "string",  name = "name" ,  title = "Name"} ,
                        new { type = "string" ,  name = "link" ,  title = "Link" }
                    };

                 var meta = new { fields };
                 var data = new[]
                           {
                               new
                                   {
                                       name = "PDF file",
                                        link =  http://example.com/files/file.pdf

                                   }
                           };


                 var res = new { contentType = "LinkToFile", id = 1, meta, data };
                 return Json(res, JsonRequestBehavior.AllowGet);

   }

前に言ったように、サイトの名前がどうなるかわからない。ファイルはサーバー上のフォルダ名「file」にあります</p>

4

4 に答える 4

2

infoexpert.it、

ここでは100%明確ではありませんが、おそらく次のものを使用できます。

Request.UrlReferrer

また:

Request.UrlReferrer.Host // or Request.Url.Host

等..

必要な情報を推定しますか?

于 2012-02-08T10:02:46.760 に答える
1

Use

var url = Request.Url;

To get the url of the site. If this is to much you can always trim off some access url

于 2012-02-08T09:58:07.073 に答える
0

http://www.cambiaresearch.com/articles/53/how-do-i-get-paths-and-url-fragments-from-the-httprequest-object

私が推測するリスト全体があります:)

于 2012-02-08T10:03:30.067 に答える
0
Uri baseUri = new Uri(Request.Url.Host);
Uri uri = new Uri(baseUri, "files/file.pdf");
于 2012-02-08T10:10:42.110 に答える