我想从C#direct创建doc,docx,pptx或excel文件到我的Onedrive帐户.我试过这个,但它不适合我.有谁知道我做错了什么?谢谢
public async Task<ActionResult> CreateWordFile()
{
LiveLoginResult loginStatus = await authClient.InitializeWebSessionAsync(HttpContext);
if (loginStatus.Status == LiveConnectSessionStatus.Connected)
{
var fileData = new Dictionary<string, object>();
fileData.Add("name", "Document.docx");
fileData.Add("Content-Type", "multipart/form-data; boundary=A300x");
fileData.Add("type", "file");
LiveOperationResult getResult = await connectedClient.PostAsync("me/skydrive/files", fileData);
}
return View();
}
Run Code Online (Sandbox Code Playgroud)
编辑:我得到的错误是这个:
"标题'Content-Type'缺少必需的参数:'boundary'.描述:在执行当前Web请求期间发生了未处理的异常.请查看堆栈跟踪以获取有关错误及其来源的更多信息.代码.异常细节:Microsoft.Live.LiveConnectException:标题'Content-Type'缺少必需的参数:'boundary'."
我需要从OnActionExecuting方法重定向到外部网址(例如“ www.google.com”)。现在我正在使用这样的东西:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
var redirectUrl = "www.google.com";
try
{
var isAjaxRequest = filterContext.HttpContext.Request.IsAjaxRequest();
if (isAjaxRequest)
{
filterContext.HttpContext.Response.StatusCode = SessionController.CustomHttpRedirect;
filterContext.HttpContext.Response.StatusDescription = redirectUrl;
filterContext.Result = new JsonResult
{
Data = new { Redirect = redirectUrl },
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
else
{
filterContext.Result = new RedirectResult(redirectUrl, true);
}
return;
}
else
{
throw new LoggedOutException();
}
}
catch
{
throw new LoggedOutException();
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于它没有将我重定向到“ www.google.com”,而是将其重定向到“ http:// localhost:1234 / www.google.com ”(我在本地尝试)。有什么办法解决这个问题?谢谢
我有一个操作结果方法,里面正在执行重定向(url)。我的问题是如何在执行重定向之前检查网址是否有效?
public ActionResult RedirectUser()
{
var url = "/Cars/Model/1"; //this is the url
// now i should check if the redirect return a 200 code (the url is valid) and if is valid I should redirect to that url, else i should redirect to "/Home/Index"
if(this.Redirect(url))
{
return this.Redirect(url);
}
else
{
return this.RedirectToAction("Index", "Home");
}
return this.RedirectToAction("Index", "Home");
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我举个例子吗?我在谷歌上搜索,但找不到任何可以帮助我的东西。谢谢