我发现了一篇博文,展示了如何将熟悉的东西(如HttpResponseMessage)"重新填充"回ASP.NET Core MVC,但我想知道在REST Post方法中使用以下代码执行相同操作的新本机方法是什么.控制器:
// POST audit/values
[HttpPost]
public System.Net.Http.HttpResponseMessage Post([FromBody]string value)
{
var NewEntity = _repository.InsertFromString(value);
var msg = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Created);
msg.Headers.Location = new Uri(Request.RequestUri + NewEntity.ID.ToString());
return msg;
}
Run Code Online (Sandbox Code Playgroud)
在ASP.NET Core MVC项目中,我似乎无法获得Request.RequestUri.
我尝试检查Request,我能够创建这样的函数:
private string UriStr(HttpRequest Request)
{
return Request.Scheme + "://" + Request.Host + Request.Path; // Request.Path has leading /
}
Run Code Online (Sandbox Code Playgroud)
所以我可以改写UriStr(Request).但我不确定这是对的.我觉得我正在乱砍,并没有正确使用它.
早期非核心ASP.NET MVC版本的相关问题询问如何获取站点的基本URL.
我需要使用Web API Get方法返回一个图像.下面的代码似乎工作正常,除了我在Fiddler的ImageView窗口中收到此消息,"此响应已编码,但并未声称是图像."
public HttpResponseMessage Get()
{
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new StreamContent(fs);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return response;
}
}
Run Code Online (Sandbox Code Playgroud)
我在Fiddler中也看到了与此代码相同的结果:
public HttpResponseMessage Get()
{
HttpResponseMessage response = new HttpResponseMessage();
Byte[] b = (GetImageByteArray());
response.Content = new ByteArrayContent(b);
response.Content.LoadIntoBufferAsync(b.Length).Wait();
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return response;
}
Run Code Online (Sandbox Code Playgroud)
如果我使用.png格式,我会得到相同的结果.
感谢您的帮助,
这条线
System.DateTime.Parse("09/12/2009");
Run Code Online (Sandbox Code Playgroud)
将日期(字符串)转换为9/12/2009 12:00:00 AM.我怎样才能在9/12/2009的表格中找到日期.
在解释之后我做了:
DateTime dt = System.DateTime.Parse(Request.Form["datepicker"]);
dt.ToString("dd/mm/yyyy");
/* and this code have time, why???*/
Run Code Online (Sandbox Code Playgroud) 我没有在网上看到任何关于如何获取位于BlobContainerClient.
以前,我使用过这些Microsoft.Azure.Storage软件包,但后来它们已被弃用。我扫描目录中所有 blob 的旧代码是:
public async Task<void> ListAllBlobs(string path)
{
var myContainer = await GetCloudBlobClientAsync();
var directory = myContainer.GetDirectoryReference(path);
var blobs = await directory.ListBlobsSegmentedAsync(true, BlobListingDetails.None,
blobSettings.MaxResult, null, null, null);
var results = blobs.Results;
foreach(CloudBlockBlob b in results)
{
// non-relevant code
}
}
private async Task<CloudBlobContainer> GetCloudBlobClientAsync()
{
var storageAccount = CloudStorageAccount.Parse(azureBlobStorageConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(blobStorageSettings.ContainerName);
if (!await container.ExistsAsync())
{
await container.CreateAsync();
}
return container;
}
Run Code Online (Sandbox Code Playgroud)
本质上,我将上面的代码从Microsoft.Azure.Storageover移至Azure.Storage.Blobs.
如果我要重新创建 …
到目前为止,我一直在尝试使用这段代码:
<style>
body {
background-image: url(http://example.com/wp-content/uploads/2016/04/myImage.jpg);
background-size: 100%;
background-repeat: no-repeat;
}
</style>
Run Code Online (Sandbox Code Playgroud)
但这不会在生成的 PDF 上呈现图像。
正文中以这种方式格式化的纯图像标签可以正常工作并显示良好:
<img src="/home/example/public_html/wp-content/uploads/2016/04/myImage.jpg">
Run Code Online (Sandbox Code Playgroud)
有人知道为什么吗?我该怎么做才能让背景图像实际显示在生成的 pdf 上?
更新:
我现在尝试对链接的所有可能性进行 base64_encode() ..意味着我已经通过了,
/home/example/public_html/wp-content/uploads/2016/04/myImage.jpg
http://example.com/wp-content/uploads/2016/04/myImage.jpg
/wp-content/uploads/2016/04/myImage.jpg
这些 ^ 组合通过 base64_encode() 函数进行,但它们都无法显示背景图像。
我刚刚启动了Azure托管的WordPress应用服务,并选择为数据库执行MySQL应用内(预览)选项.对于那些不知道的人,这允许我在同一环境中与我的Web应用程序并行运行MySQL服务器.
但是,我遇到了选择进行MySQL查询的问题.
我想重用来自不同PHP项目的代码,其中MySQL调用是PDO语句的形式,如下所示:
try {
$db = new PDO('mysql:host=localhost;dbname=localdb;charset=utf8',
'user',
'pass');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch(PDOException $ex) {
echo "did not connect...";
}
$sth = $db->prepare("SELECT *FROM MyTable;");
$sth->execute();
Run Code Online (Sandbox Code Playgroud)
除非我有用户名和密码,否则我无法拨打这些电话.
PHP应用程序(预览版)中的PHPMyAdmin侧面板如下所示:
如果我拉出用户帐户,这就是我所看到的:
当涉及到我应该使用的用户和传递时,我迷失了,如果我甚至应该使用localdb我的数据库(这是列出所有wordpress表的地方).
总而言之,我只是尝试使用PDO语句从数据库中提取信息,并且需要知道如何去做.
有没有办法将 PDF 设置为 HTML 文件的背景?它需要符合 CSS v2.1。我希望在 html 页面中执行类似的操作:
body {
background-image: url(FULLURL/myPDF.pdf);
}
Run Code Online (Sandbox Code Playgroud)
其背后的主要目的是基本上将 HTML 呈现为 PDF,覆盖现有的 PDF。(这是我使用 PHP 和 DOMPDF 等资源做的)
它之所以要兼容 CSS v2.1,是因为资源是这样设置的: https: //github.com/dompdf/dompdf
有人有主意吗?我有点卡住了。
编辑 -本教程(尽管几乎类似于google的教程)才使一切正常:http : //teev.io/blog/google-analytics-api-php
我正在尝试遵循此处提到的教程:https : //developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php
我已经完成了所有步骤:
composer require google/apiclient:^2.0腻了并更新了composer.json文件。service-account-credentials.json刚刚下载的文件放入文件夹/public_htmlHelloAnalytics.php并将其放入/public_html文件夹。HelloAnalytics.php:
<?php
// Load the Google API PHP Client Library.
require_once '/home/user/vendor/autoload.php';
$analytics = initializeAnalytics();
$profile = getFirstProfileId($analytics);
$results = getResults($analytics, $profile);
printResults($results);
function initializeAnalytics()
{
// Creates and returns the Analytics Reporting service object.
// Use the developers console and download your service account
// credentials in JSON format. Place them in this …Run Code Online (Sandbox Code Playgroud) 我在HostGator上有一个网站,让我们说它的域名是https://example.com.
我还在Azure上托管了一个应用程序,Active Directory在整个站点上启用了身份验证(包括API组件),假设它的域名是https://example.azurewebsites.net
目标 -让PHP文件被执行(作为CRON作业)https://example.com并首先让文件使用Azure的Active Directory进行身份验证,然后https://example.azurewebsites.net/api/getValues通过HTTP GET调用从中提取数据.
问题 -显然,只是在没有承载令牌的情况下调用API会导致a 401,但401即使我传递的是有效的承载令牌,我仍然会得到一个.
这是我做的:
我访问过的https://login.microsoftonline.com/{{tenant_id}}/oauth2/authorize?response_type=code&client_id={{client_id}}是通过Azure AD管理门户提供给我的.
这返回:
https://example.com/?code={{really_long_string_of_code}}
我拿了这个really_long_string_of_code并把它作为一个身体参数通过邮递员code,如下所示:
如您所见,它返回了上面看到的令牌^.
然后,我接受了这个令牌并通过另一个Postman电话:
但问题是,我仍然得到确切的错误消息:
您无权查看此目录或页面.
我觉得我已经尝试了一切.我甚至进入portal.azure并设置了"允许的令牌受众":
任何人都知道我可以改变哪些设置以允许这种调用发生?
如果有人可以比我更好地表达这个问题,请提出建议,我将进行更改(或自行编辑)。
这是我当前的jsfiddle:https ://jsfiddle.net/5v7mzadu/
我的HTML:
<div class="text-cycler">
WE <div class="c-text" id="ctext-1">CARE</div>
<div class="c-text" id="ctext-2">THINK</div>
<div class="c-text" id="ctext-3">SEE</div>
<div class="c-text" id="ctext-1">KNOW</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的CSS:
.text-cycler {
text-align:center;
font-size:25px;
}
.c-text {
display:inline-block
}
Run Code Online (Sandbox Code Playgroud)
我的Javascript:
var divs = $('div[id^="ctext-"]').hide(),
i = 0;
(function cycle() {
divs.eq(i).fadeIn(400)
.delay(1000)
.fadeOut(400, cycle);
i = ++i % divs.length;
})();
Run Code Online (Sandbox Code Playgroud)
如您所见,第二个单词淡入/淡出。我想为div添加一个平滑过渡,以便div容器的宽度不会突然改变宽度大小。(以使宽度“对齐”更平滑)
有人可以帮忙吗?
c# ×4
azure ×3
css ×3
php ×3
asp.net ×2
dompdf ×2
pdf ×2
api ×1
asp.net-core ×1
asp.net-mvc ×1
blobstorage ×1
google-api ×1
html ×1
javascript ×1
jquery ×1
mysql ×1
oauth ×1
oauth-2.0 ×1
pdo ×1
postman ×1
transition ×1
wordpress ×1